它也会根据具体取决于您传递给它的关键字scenes
字典场景的对象,并返回回给你。
为什么它切换到下一个场景?
它切换到下一个场景的原因是因为在基类各场景扩展指定的序列中的下一个场景它完成通过enter()
功能运行后:
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
while True:
print "\n--------"
next_scene_name = current_scene.enter() # returns next scene key
current_scene = self.scene_map.next_scene(next_scene_name) # initiates next scene and sets it as `current_scene`
例如,CentralCorridor
场景最后根据输入的动作返回下一个场景的关键字:
def enter(self):
print "The Gothons of Planet Percal #25 have invaded your ship and destroyed"
...
print "flowing around his hate filled body. He's blocking the door to the"
print "Armory and about to pull a weapon to blast you."
action = raw_input("> ")
if action == "shoot!":
print "Quick on the draw you yank out your blaster and fire it at the Gothon."
...
print "you are dead. Then he eats you."
return 'death' # next scene `Death`
elif action == "dodge!":
print "Like a world class boxer you dodge, weave, slip and slide right"
...
print "your head and eats you."
return 'death' # next scene `Death`
elif action == "tell a joke":
print "Lucky for you they made you learn Gothon insults in the academy."
...
return 'laser_weapon_armory' # next scene `LaserWeaponArmory`
else:
print "DOES NOT COMPUTE!"
return 'central_corridor' # next scene `CentralCorridor`
并且整个序列以死亡场景的结尾enter()
功能退出程序:
def enter(self):
print Death.quips[randint(0, len(self.quips)-1)]
exit(1)
它不切换到* next *场景。它切换到您在传递给函数的参数中指定的场景。 – Lix
我不太确定你在这里问的是什么......你面临的问题到底是什么? – Lix