from sys import exit
from random import randint
from textwrap import dedent
class Scene(object):
def enter(self):
print("This scene is not yet configured此场景尚未配置.")
print("Subclass it and implement enter()对它进行子类化并实现输入().")
exit(1)
class Engine(object):
def __init__(self,scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
#当前场景类的实例化 current_scene = 当前场景类名()
last_scene = self.scene_map.next_scene('finished')
#建立一个胜利结束场景类对象,准备好后下面进入关键的循环阶段
while current_scene!=last_scene:
next_scene_name = current_scene.enter()
#如果游戏还没胜利,进入循环后就要先进行目前场景的游戏部分 .enter()运行,结束后返回的是下一个场景的key
current_scene = self.scene_map.next_scene(next_scene_name)
#一个场景enter结束了要开始进入下一个场景了,下一场景类的实例化
#循环的过程中,.enter()如果进入的是Death场景,无返回值,游戏直接结束
# be sure to print out the last scene
current_scene.enter()
#相当于last_scene.enter() #顺利结束循环,游戏胜利
class Death(Scene):
quips = [
"You died .You kinda suck at this.你死了。你有点不好意思",
"Your mom would be pound...if she were smarter.如果她更聪明,你的妈妈会感到自豪",
"such a luser.这样的失败者",
"I have a small puppy that's better at this.我有一只小狗在这方面做得更好",
"You're worse than you Dad's jokes.你比你爸爸的笑话更糟糕"
]
def enter(self):
print(Death.quips[randint(0,len(self.quips)-1)])
exit(1)
class CentralCorridor(Scene):
def enter(self):
print(dedent("""
The Gothons of planet Percal #25 haveinvaded your ship and
desteoyed your entire crew.You are the last surviving
member and your last mission is to get the neutron destruct
bomb from the Weapons Armory, put it in the bridge, and
blow the ship up afther getiing into an escape pod .
You're running down the central corridor to the Weapons
Armory when a Gothon jumps out , red scaly skin, dark grimy
filled body . He's blocking the door to the Armory and
about topull a weapon blast you.行星Percal#25的Gothons已经侵入
你的船并使你的整个船员消失。你是最后一个幸存的成员,你的最后一个任务
是从武器军械库获得中子毁灭炸弹&#
from sys import exit from random import randintfrom textwrap import dedentclass Scene(object): def enter(self): print("This scene is not yet configured此场景尚未配置.") print("Subclass it and imple...