它也會根據具體取決於您傳遞給它的關鍵字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