2
그래서 나는이 문제를 겪고 있습니다. 누군가 제가 올바른 방향으로 나를 가리킬 수 있다면, 너무 감사 할 것입니다. 내가 너를 위해 준비시켜 줘.파이썬에서 하나의 클래스에서 다른 클래스로 "옮겨 다니는 것"
나는 그래서 같은 클래스로 채워진 1 개 파이썬 파일/모듈의 이름 객실 :
모든 멋진 물건 권리가class Intro(object):
def __init__(self):
# Setting up some variables here
def description(self):
print "Here is the description of the room you are in"
? 그런 다음 다른 파일/모듈 (Engine)에 있습니다. 나는이있다 :
import rooms
class Engine(object):
def __init__(self, first_class):
self.lvl = first_class
def play_it(self):
next_lvl = self.lvl
while True:
# Get the class we're in & run its description
next_lvl.description() # it works.
# But how do I get the next class when this class is done?
내가 각 방/레벨 클래스 내에서 사용자의 결정을 기반으로 일하고자하는 일까지, 그것의 설명 기능/특성/w 새로운 클래스에 따라 엔진 호출. 말이 돼? 아니면 내가 이것에 대해 생각해야하는 또 다른 방법이 있습니까? 엉덩이 - 뒤로 때때로. 감사.
[State Pattern] (http://en.wikipedia.org/wiki/State_pattern) ...을보세요. –