因此,我试图跳过我的打印行,回到我的raw_input。我需要一个循环吗?
class stuff(Scene):
def enter(self):
print "This is text"
print "This is text"
print "This is text"
print "This is text"
print "This is text"
action = raw_input("> ")
if action == "blah"
print "This is text"
return 'stuff'当我这样做时,它会重复我所有的打印行,如何让它返回到raw_input?
发布于 2013-10-07 18:32:00
您可以为类创建一个属性,以跟踪您以前是否打印过文本。打印文本时,适当地设置属性。例如:
class stuff(Scene):
def __init__(self):
self.seen_description = False
#other initialization goes here
def enter(self):
print "End Of The Road"
if not self.seen_description:
print "You are standing beside a small brick building at the end of a road from the north."
print "A river flows south."
print "To the north is open country, and all around is dense forest."
self.seen_description = True
action = raw_input("> ")
if action == "go inside":
print "You enter the brick building"
return 'brick building'
x = stuff()
x.enter()
x.enter()结果:
End Of The Road
You are standing beside a small brick building at the end of a road from the north.
A river flows south.
To the north is open country, and all around is dense forest.
> wait
End Of The Road
> wait在这里,我们在第一次调用enter时得到了一个扩展描述,并且在所有后续调用中都跳过了它。
https://stackoverflow.com/questions/19231610
复制相似问题