Note that there are some explanatory texts on larger screens.

plurals
  1. POLearn Python the Hard Way, Exercise 43
    primarykey
    data
    text
    <p>I am currently working on <em>Learn Python the Hard Way</em> by Zed Shaw. I am struggling with Exercise 43, which instructs me to create a text game with the following properties:</p> <ul> <li>Uses more than 1 file</li> <li>One class per "room"</li> </ul> <p>So far I have started two files, one for the runner and one with the rooms:</p> <p><strong>game_runner.py</strong></p> <pre><code>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() </code></pre> <p><strong>game_map.py</strong></p> <pre><code>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 = '&gt; ' 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('&gt; ') #and so on </code></pre> <p>My problem is that I cannot get the game_runner to proceed to the next room. When I run it, it plays an infinite loop of the first room: prints the docstring for Chillin(), asks for input, then repeats.</p> <p>How can I change my runner and/or map to return the next class, i.e. Pregame(), after entering a correct response in the first class? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload