2012-01-19 6 views
3

私は現在、で働いています。Python the Hard Wayを学ぶ by Zed Shaw。私は、次のプロパティのテキストゲームを作成するために私に指示エクササイズ43、に苦しんでいます:難解な方法でPythonを学ぶ、エクササイズ43

  • が1つの以上のファイルを使用します
  • これまでのところ、私が持っている「部屋」

をごとに1つのクラス

game_runner.py

from game_map import * 

class Runner(object): 
    def __init__(self, start): 
     self.start = start 

    def play(self): 
     next_room = self.start 

     while True: 
      print '\n' 
      print '-' * 7 
      print next_room.__doc__ 
      next_room.proceed() 

firstroom = Chillin() 

my_game = Runner(firstroom) 

my_game.play() 
:二つのファイル、ランナーのための1つの客室と1を開始しました

game_map.py

from sys import exit 

class Chillin(object): 
    """It's 8pm on a Friday night in Madison. You're lounging on the couch with your 
roommates watching Dazed and Confused. What is your first drink? 
    1. beer 
    2. whiskey 
    3. vodka 
    4. bowl 
""" 
    def __init__(self): 
     self.prompt = '> ' 

    def proceed(self): 
     drink = raw_input(self.prompt) 

     if drink == '1' or drink == 'beer': 
      print '\n Anytime is the right time.' 
      print 'You crack open the first beer and sip it down.' 
      room = Pregame() 
      return room 
     #rest of drinks will be written the same way 


class Pregame(object): 
    """It's time to really step up your pregame. 
How many drinks do you take? 
""" 

    def proceed(self): 
     drinks = raw_input('> ') 
    #and so on 

私の問題は、私は隣の部屋に進むgame_runnerを得ることができないということです。私はそれを実行すると、最初の部屋の無限ループを演奏します:Chillin()のドキュメントストリングを印刷し、入力を求めてから、繰り返します。

ランナーおよび/またはマップを変更して、ファーストクラスで正しい応答を入力した後、次のクラス、つまりPregame()を返すにはどうすればよいですか?

next_room = next_room.proceed() 

あなたが変数に再代入れることはありません:これまで

next_room.proceed() 

+3

男、このコードは、潜在的なメッセージでビール広告のように見えます – juliomalegria

答えて

6

私は(私が正しくあなたのコードに従っている場合)、これを変更しているあなたがする必要があるすべてだと思いますwhile True:ループ内で使用しているので、同じ動作が永遠に得られます。

関連する問題