2
所以,我遇到了這個問題,如果有人能指引我朝着正確的方向行事,我會非常感激。讓我爲你設置它。在Python中將「從一個類」移動到另一個類
我有1個Python的文件/模塊命名的房間充滿了類,像這樣:
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 /其描述功能/屬性。那有意義嗎?或者還有另外一種方法我應該考慮這個問題?我有時會屁股後退。謝謝。
看看[狀態模式](http://en.wikipedia.org/wiki/State_pattern)... –