如何跳过self.prompt?

时间:2013-06-12 15:25:11

标签: python python-2.7

我正在看一个人的代码问一年有关制作游戏时出现问题,我遇到了一个关于他们代码的另一部分我无法弄清楚的问题。以下是代码......

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

所以我的问题是firstroom = Chillin() def __init__被调用,但不知何故,self.prompt = '> '直到While循环遍历一次后才出现。我对编码仍然很陌生,所以这个问题可能看起来很模糊,但希望有人可以回答,因为我很困惑。谢谢!

1 个答案:

答案 0 :(得分:1)

在调用process()之前,不会显示self.prompt。

在while循环结束时调用proceed()