• first_game


    from sys import exit
    from random import randint


    # 场景
    class Scene:
    def enter(self):
    print("This scene is not yet configured. Subclass it and implement enter().")
    exit(1)


    # 死亡场景
    class Death(Scene):
    quips = [
    "You died. You kinda suck at this.",
    "Your mom would be proud...if she were smarter.",
    "Such aluser.",
    "I have a small puppy that's better at this."

    ]

    def enter(self):
    print(Death.quips[randint(0, len(Death.quips)) - 1]) # randint 都是闭区间
    exit(1)

    # 走廊场景
    class CentralCorridor(Scene):
    def enter(self):
    print("The Cothons of Planet Percal #25 have invaded your ship and destrored")
    print("your entire crew. You are the last surviving member and your last")
    print("mission is to get the neutron destruct bomb from the Weapons Armory,")
    print("put it in the bridge, and blow the ship up after getting into an")
    print("escape pod.")
    print(' ')
    print("You're running down the central corridor to the Weapons Armory when")
    print("a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume")
    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.")
    print("""
    25号行星的Cothons已经侵入你的飞船并被驱逐
    全体船员。你是最后一个幸存的成员,也是最后一个
    任务就是从武器库中获取中子爆弹,
    把它放在桥上,然后把船吹起来
    逃生舱。
    """)
    print("""
    选项 1. "shoot!" or "1"
    2. "dodge!(回避)" or "2"
    3. "tell a joke(讲个笑话)" or "3"
    """)

    action = input(">")

    if action == "shoot!" or action == "1":
    print("Quick on the draw you yank out your blaster and fire it at the Gothon.(快把你拽出来,把你的爆喷器喷出来,然后把它点燃)")
    print("His clown costume is flowing and moving around his body, which throws(他的小丑服装在他的身体里流动,在他的身体周围移动)")
    print("off your aim. Your laser hits his costume but misses him entirely. This(这使你的目标偏离了目标。你的激光击中了他的服装,但他完全没有击中他。)")
    print("completely ruins his brand new costume his mother bought him, which(这完全毁掉了他母亲给他买的新衣服)")
    print("makes him fly into a rage and blast you repeatedly in the face until(这让他变得暴怒,不断地在你面前炸开你的脸)")
    print("you are dead. Then he eats you.(你死了,然后吃掉你)")
    return "death"
    elif action == "dodge!" or action == "2":
    print("Like a world class boxer you dodge, weave, slip and lide right()")
    print("as the Gothon's blaster cranks a laser past your head.")
    print("In the middle of your artful dodge your foot slips and you")
    print("bang your head on the metal wall and pass out.")
    print("You wake up shortly after only to die as the Gothon stomps on")
    print("your head and eats you")
    return "death"
    elif action == "tell a joke" or action == "3":
    print("Lucky for you they made you learn Gothon insults in the academy.")
    print("You tell the one Gothon joke you know:")
    print("Lbhe zbgdsdaddasdadadadadad")
    print("The Gothon stops, tries not to laugh, then busts out laughing and can't move.")
    print("While he's laughing you run up and shoot him square in the head")
    print("putting him down, then jump through the Wwapon Armory door.")
    return 'laser_weapon_armory'


    else:
    print("DOES NOT COMPUTE!")
    return "central_corridor"


    # 武器库
    class LaserWaponArmory(Scene):
    def enter(self):
    print("You do a dive roll into the Weapon Armory, crouch and scan the room")
    print("for more Gothons that might be hiding. It's dead quiet, too quiet.")
    print("You stand up and run to the far side of the room and find the")
    print("neutron bomb in its container. There's a keypad lock on the box")
    print("and you need the ode to get the bomb out. If you get the code")
    print("wrong 10 times then the lock closes forever and you can't")
    print("get the bomb. The code is 3 digits.")
    code = "%d%d%d" % (randint(1, 9), randint(1, 9), randint(1, 9))
    print(code)
    guess = input("[keypad]>")
    guesses = 0

    while guess != code and guesses < 10:
    print("BZZZZEDDDD")
    guesses += 1
    guess = input("[keypad]>")

    if code == guess:
    print("The container clicks open and the seal breaks, letting gas out.")
    print("You grab the neutron bomb and run as fast as you can to the")
    print("bright where you must place it in the right spot")
    return "the_bridge"

    else:
    print("The lock buzzes one last time and then you hear a sickening")
    print("melting sound as the mechanism is fused together")
    print("ship from thier ship and you die.")
    return "death"


    # 主控舱
    class TheBridge(Scene):
    def enter(self):
    print("You burst onto the Bridge with the netron destruct bomb")
    print("under your arm and surprise 5 Gothons who are trying to")
    print("take control of the shio. Each of them has an even uglier")
    print("clown costume than the last. They haven't pulled their")
    print("weapons out yet, as they see the active bomb under your")
    print("arm and don't want to set it off.")

    action = input(">")
    if action == "throw the bomb":
    print("In a panic you throw the bomb at the group of Gothons")
    print("and make a leap for the door. Right as you drop it a")
    print("Gothon shoots you right in the back killing you.")
    print("As you die you see anothe Gothon frantically try to disarm")
    print("the bomb. You die knowing they will probably blow up when")
    print("it goes off")
    return "death"
    elif action == "slowly place the bomd":
    print("You point your blaster at the bomb under your arm")
    print("and the Gothons put their hands up and start to sweat.")
    print("You inch backward to the door, open it, and the carefully")
    print("place the bomb on the floor, pointing your blaster at it.")
    print("You then jump back through the door, punch the close button")
    print("and blast the lock so Gothons can't get out.")
    print("Now that the bomb is placed you run to the escape pod to")
    print("get off this tin can.")
    return "escape_pod"
    else:
    print("DOSE NOT CMPUTE")
    return "the_bridge"


    # 救生舱
    class EscapePod(Scene):
    def enter(self):
    print("You rush through the shio desperately trying to make it to")
    print("the escape pod before the whole ship explodes. It seems like")
    print("hardly any Gothons are on the ship, so your run is clear of")
    print("interference. You get to the chamber with the escape pods,and")
    print("now need to pick one to take. Some of them coulf be damaged")
    print("but you don't have time to look. There's 5 pods, which one")
    print("do you take?")

    good_pod = randint(1, 5)
    print(good_pod)
    guess = input("[pod #]>")

    if int(guess) != good_pod:
    print("You jump into pod %s and hit the eject button." % guess)
    print("The pod escapes out into the void of space, then")
    print("impoldes as the hull ruptures, crushing your body")
    print("into jam jelly.")
    return "death"

    else:
    print("You jump into pod %s and hit the eject button." % guess)
    print("The pod easily slides out into space heading to")
    print("the planet below. As it files to the planet, you look")
    print("back and see your ship implode then expolde like a")
    print("bright star, taking out the Gothon ship at the same")
    print("time. You won")
    exit(0)


    # 引擎
    class Engine:
    def __init__(self, scene_map):
    self.scene_map = scene_map

    def play(self):
    star_scene = self.scene_map.opening_scene()
    while True:
    next_scene_name = star_scene.enter()
    star_scene = self.scene_map.next_scene(next_scene_name)


    # 地图
    class Map:
    scenes = {"death": Death(),
    "central_corridor": CentralCorridor(),
    "laser_weapon_armory": LaserWaponArmory(),
    "the_bridge": TheBridge(),
    "escape_pod": EscapePod(),
    }
    def __init__(self, start_scene):
    self.start_scene = start_scene

    def next_scene(self, scene_name):
    return Map.scenes.get(scene_name,None)

    def opening_scene(self):
    return self.next_scene(self.start_scene)


    a_map = Map("central_corridor")
    a_game = Engine(a_map)
    a_game.play()



  • 相关阅读:
    npm 常用命令
    jquery 滚动事件
    移动端触控事件封装(完整版)
    带动画的分页
    手机号码 座机号码验证
    js常用 弹出确认 取消对话框
    jQuery之select的option怎样绑定事件
    jQuery如何停止元素的animate动画,还有怎样判断是否处于动画状态
    jQuery live()方法使用及变更(事件委托)
    Could not publish server configuration for Tomcat v6.0 Server at localhost. Multiple Contexts have a path of "/tm".
  • 原文地址:https://www.cnblogs.com/learn-python-M/p/7277913.html
Copyright © 2020-2023  润新知