2

だから、私はこの問題に取り組んでいます。誰かが私を正しい方向に向けることができれば、とても感謝しています. 設定させてください。

次のように、クラスで満たされた部屋という名前のPythonファイル/モジュールが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?

私が望んでいることは、各部屋/レベル クラス内のユーザーの決定に基づいていることを確認してください。エンジンは、その記述関数/属性を使用して新しいクラスを呼び出します。それは理にかなっていますか?それとも、これについて考えるべき別の方法はありますか?私は時々お尻を後ろに向けます。ありがとう。

4

1 に答える 1

2

次に使用するクラスの選択を部屋に委任します。例えば

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"

    def north(self):
        return Dungeon()

    def west(self):
        return Outside()

    #etc

そのため、プレーヤーがイントロ ルームで「西に行く」と言うと、エンジンが呼び出さroom.west()れ、Introルームがルームに戻りますOutside

うまくいけば、それはヒントで十分です!自分だけのデザインを作りたくなるはずです。

于 2012-05-12T18:36:24.413 に答える