您可以为该类创建一个属性,以跟踪您之前是否打印过文本。当您打印文本时,请适当地设置属性。例如:
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
,并且在所有后续调用中都会跳过它。