728x90
반응형
클래스 하나를 통째로 게임 모듈로 만들었다.
UpDownFunk 클래스 생성만 하면 곧바로 게임이 실행된다.
UI로도 만들어볼 예정이다. 근데 Tkinter랑 안친하다.
갠적으로 파이썬은... 데이터분석용에 너무 최적화되어있다고 생각하기 때문에...
import random
class UpDownFunk:
__figure = 0
def __init__(self):
print("Enter a number that will range of figure", end=": ")
range_ = self.input_filteringNaN()
self.__figure = random.randint(0, range_)
print("Enter a limit of turn", end=": ")
self.limit = self.input_filteringNaN()
print("[Game start!]")
self.starting()
def starting(self):
for i in range(self.limit):
print(f"Enter number({i+1}/{self.limit}):", end=" ")
number = self.input_filteringNaN()
if number > self.__figure: print("<Down>")
elif number < self.__figure: print("<Up>")
else:
self.ending()
return
self.overing()
def input_filteringNaN(self):
while(True):
try:
intnum = int(input())
return intnum
except: print(" [Not a number, re-enter]", end=": ")
def ending(self):
print("<Currect!>")
def overing(self):
print(f"<limit is full:Game over> figure is {self.__figure}")
def __del__(self):
print("[Close the game]")
def __str__(self):
return "[Game is underway]"
test = UpDownFunk() #Run
728x90
반응형
'농장 > Python' 카테고리의 다른 글
Jupyter notebook 내가 원하는 경로에 생성하기 (0) | 2020.11.20 |
---|---|
파이썬 Turtle 로 GUI에 도형 그리기 (0) | 2020.04.24 |
이클립스로 Python 구동하기 - PyDev 설치 (연동과 테스트) (0) | 2020.03.26 |