3
我正在從事學習Python的艱辛之路作者:Zed Shaw。我與練習43,指示我創建一個文本遊戲具有以下屬性掙扎:Learn Python the Hard Way,練習43
- 使用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()
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()?
男人,這段代碼看起來像一個帶有潛意識信息的啤酒廣告 – juliomalegria