2015-11-06 49 views
-5
from sys import exit 
from random import randint 

print "NOVA" 
print "Created by Zachary C. Boedeker " 
print "Copyright 2016" 
print "Start" 

name = raw_input("What is your name?") 
# This is for the player or user to input there name and alow them to have there name registerd later on. 
print "okay %r , Would you like to join me?" % (name) 
question = raw_input("Yes or no ?") 

if raw_input == "yes" "y": 
    print "Great, %r !" % (name) 
    print "Are you ready %r ?" % (name) 
    print "do you remamber anything ?" 
    print "The Sky, The Stars, Earth, Home,The Accident ?" 
    print "Anderson %r is still recovering im going back to the bridge call me if anything changes." 
    print " HEY %r Can you hear me ?" % (name) 
    print " %r you work as a space miner for NOVA." % (name) 
    print "Nitro Omega Ventura Apollo." 
    print "A top secret branch of the military." 
    print " %r you have been assined the Apollo branch...or deep space opperations." % (name) 
    print "That is all I can give you right now ." 
    print "%r you took some damage but you should be fine." % (name) 
    print "I think the medication is wearing off lets go back to the bridge." 
    print "WARNING WARNING WARNING UNKNOW OBJECT IN .............." 
    print "........................................................" 
    print "........................................................." 

# this is a issue as well doesnt want to let user decide yes or no 
# I have yes but no doesnt work... elif and else dont seem to work.They are comments because im trying to test out the beguining. 
elif raw_input == "No" "no": 
    print "Okay sorry for asking %r ....." % (name) 
    print "Restart game to play...." 
    print "Thanks for playing." 
    exit(2) 


class Scene(object): 

    def enter(self): 
     print "This is not yet configured.Subcllass it and implementeer()." 
     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() 
      last_scene = self.scene_map.next_scene('finished') 

      while current_scene != last_scene: 
       next_scene_name = current_scene.enter() 
       current_scene = self.scene_map.next_scene(next_scene_name) 

      # be sure to print out the last scene 
      current_scene.enter() 

class Death(Scene): 

    quips = [ 
     "You died...Well now what do we do?", 
     "Your mom would be so proud if you were smarter.", 
     "Wish you had lives?", 
     "Can we try this again jsut this time dont die?" 
    ] 

    def enter(self): 
     print Death.quips[randint(0,len(self.quips)-1)] 
     exit(1) 

class MedLab(Scene): 

    def enter(self): 
     print "Your are in space on a deep space mining oppperation" 
     print "You roll over still recovering from that crazy, Minning accident." 
     print "The stiches still fresh in your side.The soaked bandages keep your blood from ozing out." 
     print "I must get up ! I will get up!" 
     print "The pain from your injury burns with every move you make." 
     print "Standing on the icy floor pricks your feet" 
     print "You need your suit, But you also what to know where the Doctor is?" 
     print "Do you put on your spacesuit? Or walk out of the MedLab to find the doctor ?" 

     action = raw_input("> ") 

     if action == "spacesuit" "Put on suit": 
      print "It hurts to put on your spacesuit." 
      print "LT %r is written on the Helemt." % (name) 
      print "The helmet powers on and the lodading screen apperes." 
      print "Lt %r its good to see your up and about." % (name) 
      print "Downloading ships info." 
      print "DAMAGE ALL CREW DEAD WARNING AIR LOCK BREACH IN Corridor." 
      print "UNKNOWN LIFE-FORMS DETECTED.REQUESTED QUARENTENE." 
      print "WARNING AUTO PILOT ENGAGED TIME TO LIGHTSPEED 5 HOURS TILL ARIVAL TO EARTH." 
      print "The computer turns off and the light on your helmet turns on" 
      print "Warning Air supply 50%" 
      print "I need O2 thats in My Room,but I need to cancle the Auto-Piolt.What should I do ?" 
      print "Exit out to the Corridor." 

      return 'Corridor' 

     elif action == "walk out of MedLab" "Find Doctor.": 
      print "You open the door and get sucked out of the MedLab!!!!" 
      print "WARNING BREACH AIR LOCK ERROR." 
      print "You get the life sucked out of you." 
      return 'death' 

class Corridor(Scene): 

    def enter(self): 
     print "The EMERGENCY LIGHTS and SIREN BLARES." 
     print "The Anti-Gravity has been knocked out." 
     print "LIFE-FORMS DETECTED ON LOWER LEVEL." 
     print "The body of Dr.Anderson Floats lifeless." 
     print "ACTIVATING MAGNETIC BOOTS.The lights show many scratch marks on the walls." 
     print "The window has been broken and space is every where." 
     print "The Sun and planet jupiter can be seen." 
     print "What are we doing way out here? We where suppost to be going to mars." 
     print "WARNING O2 Levels 40%" 
     print "I should get more O2 in my room.But I need to Stop the Auto-Piolt." 

     action = raw_input("> ") 

     if action == "Go to my Room" "Get O2" "My Room" "O2": 

      return 'MyRoom' 

     elif action == "Go to Bridge" "Bridge": 
      return 'TheBridge' 

class TheBridge(Scene): 

    def enter(self): 
     print "THE DOORS OPEN AND AN ALIEN JUMPS AT YOU!!!!!!" 
     print "Its is covered in a slime and black as space." 
     print "I looks you in the eye and lunges at you." 
     print "Its Mouth goes to bite you!!!" 
     print "Hit It with your fists!!! or push it away from you!!!" 

     action = raw_input("> ") 

     if action == "Hit it" "Hit it with your fists" "Punch it": 
       print "It bites your arm and slithers into your suit." 
       print "Oh the slime it BURNS you feel it trurning you into soup." 

       return 'death' 

     elif action == "Push it" "Push it away from you": 
       print "you push it away from you." 
       print "you turn to run back into the Corridor but alas." 
       print "your smiling into the mouth of ailen on the door." 
       print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

     elif action == "Shoot it" "fire your gun": 
       print "It explodes all over the place" 
       print "You enter the main control panel and pick up the access codes for the Reactor." 
       print "NOVA" 
       print "You can go to the Reactor now and arm to Reactor." 
       print "Looking at the escape pods you see only one working that is Number 4." 

       return 'Reactor' 


class Reactor(Scene): 

    def enter(self): 
     print "The door to the Reactor is locked." 
     print "input code" 
     print "Are you sure you want to do this?" 
     print "wrong 10 times then the lock closes forever and you can't" 
     print "Enter the REACTOR. The code is 3 digits." 
     code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9)) 
     guess = raw_input("[keypad]> ") 
     guesses = 0 

     while guess != code and guesses < 10: 
      print "BZZZZEDDD!" 
      print "INCORRECT PIN" 
      guesses += 1 
      guess = raw_input("[keypad]> ") 

     if guess == "code": 
      print "Doors open and you walk into the Reactor." 
      print "You open up the self-destruct system." 
      print "WARNING WARNING THE SELFDESTRUCT SYSTEM IS BEING ARMED" 
      print "WARNING WARNING TO DE-ACTIVATE SELF ESTRUCT PLEASES ALOT 2 MINIUTES." 
      print "WARNING WARNING INPUT TIMER." 
      print " %r is setting SELFDESTRUCT to 10 MINIUETS. " 
      print "ALL CREWMEBERES REPORT TO ESCAPE PODS." 
      print "Timer set 10 Miniutes to SELFDESTRUCT!" 
      print "Were getting out of here" 
      print "To the escape pods." 
      print "Okay lets go." 
      return 'Escapepods' 

     else: 
      print "THE ALARM ATTRACTS ALIENS !!!" 
      print "WAHT DO YOU DO ?" 
      print "HIT IT OR PUSH IT ?" 
     if action == "Hit it" "Hit it with your fists" "Punch it": 
       print "It bites your arm and slithers into your suit." 
       print "Oh the slime it BURNS you feel it trurning you into soup." 

       return 'death' 

     elif action == "Push it" "Push it away from you": 
       print "you push it away from you." 
       print "you turn to run back into the Corridor but alas." 
       print "your smiling into the mouth of ailen on the door." 
       print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

     elif action == "Shoot it" "fire your gun": 
       print "It explodes all over the place" 

       return 'Reactor' 

class Escapepods(Scene): 

    def enter(self): 
     print "Take what pod?" 
     action = raw_input("> ") 

     if action == "1": 
       print "INPUT PASSWORD." 

       if action == "1230" "Code" "Open": 
         print "INCORECT" 
         print "AN ALIEN APPERES!!!!" 
         print "Hit It with your fists!!! or push it away from you!!!" 

         if action == "Hit it" "Hit it with your fists" "Punch it": 
           print "It bites your arm and slithers into your suit." 
           print "Oh the slime it BURNS you feel it trurning you into soup." 

           return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 

       elif action == "Hoth" "hoth" "HOTH": 
        print "ACESS GRANTED" 
        print "%r were getting out of here!!!" 
        print "The air lock closes." 
        print "You buckle in and look up ITS AN ALIEN!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 
        print "The Pod Detaches from the Nevada." 
        print "You get away and see the nevada destroyed." 
        print "You get ready for hypersleep opening your bed and getting in it." 
        print "You get in and close the tube shut." 
        print "An alien spore is inside of your filters for O2 and it slides into your pod." 
        print "You are a host, you dont know it." 
        print "%r you drift into space forever never to be found because you have been infected." (name) 

        return'death' 

       if action == "2": 
        print "INPUT PASSWORD." 

       if action == "1230" "Code" "Open": 
        print "INCORECT" 
        print "AN ALIEN APPERES!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 

       elif action == "Alderan" "alderean" "ALDERAN": 
        print "ACESS GRANTED" 
        print "%r were getting out of here!!!" 
        print "The air lock closes." 
        print "You buckle in and look up ITS AN ALIEN!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 
        print "The Pod Detaches from the Nevada." 
        print "You take off your helmat" 
        print "Another alien gets you from behind." 

       if action == "3": 
        print "INPUT PASSWORD." 

       if action == "1230" "Code" "Open": 
        print "INCORECT" 
        print "AN ALIEN APPERES!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 

       elif action == "Mustafar" "mustafar" "MUSTAFAR": 
        print "ACESS GRANTED" 
        print "%r were getting out of here!!!" 
        print "The air lock closes." 
        print "You buckle in and look up ITS AN ALIEN!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 
        print "The Pod is stuck on the Nevada." 
        print " The bomb goes off and you died" 

        return'death' 

       if action == "4": 
        print "INPUT PASSWORD." 

       if action == "1230" "Code" "Open": 
        print "INCORECT" 
        print "AN ALIEN APPERES!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 

       elif action == "Endor" "endor" "ENDOR": 
        print "ACESS GRANTED" 
        print "%r were getting out of here!!!" 
        print "The air lock closes." 
        print "You buckle in and look up ITS AN ALIEN!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 
        print "The Pod Detaches from the Nevada." 
        print "Yes freedom!!!!" 
        print "The Nevada explodes destroying the alien. " 
        print "You go into hypersleep and wait to be rescued. " 

        return 'finished' 

       if action == "5": 
        print "INPUT PASSWORD." 

       if action == "1230" "Code" "Open": 
        print "INCORECT" 
        print "AN ALIEN APPERES!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 

       elif action == "NABOO" "Naboo" "naboo": 
        print "ACESS GRANTED" 
        print "%r were getting out of here!!!" 
        print "The air lock closes." 
        print "You buckle in and look up ITS AN ALIEN!!!!" 
        print "Hit It with your fists!!! or push it away from you!!!" 

       if action == "Hit it" "Hit it with your fists" "Punch it": 
        print "It bites your arm and slithers into your suit." 
        print "Oh the slime it BURNS you feel it trurning you into soup." 

        return 'death' 

       elif action == "Shoot it" "fire your gun": 
        print "It explodes all over the place" 
        print "The Pod Detaches from the Nevada." 
        print "You frogot to close the door." 
        print "you get sucked out into space." 
        print "You die in the cold dark space," 
        " because in space no one can here you scream." 

        return'death' 
class MyRoom(Scene): 

    def enter(self): 
     print "Your room is a mess %r" % (name) 
     print "Hey thats your gun if you see any alien shoot them." 
     print "Attatch the O2 tank to that pannel." 
     print "O2 tanks being filled." 
     print "Email from Captin dated almost 1 week ago." 
     print "Read email or go to bridge?" 

     action = raw_input("> ") 

     if action == "read email" "Read": 
      print "This is Captin Walker, We have a situation this email was writen up," 
      "to any salvagers or explores that may find the Nevada." 
      "WE are infeced with an unidentified organiziam we think it may be sort of bacteria." 
      "It can move in space and has the ability to cling to objects." 
      "I am the sole suvivor abord...Our Lt %r Took a beating and Dr.Anderson fixed them up before," 
      "His death in experemnting with the unidentified alien." 
      "We have changed the codes for the Reactor... and escape pods." 
      "The password for the escape pod is 1.Hoth 2.Alderan 3.Mustafar 4.Endor 5.Naboo" 
      "I have the Reactor password in the bridge but have been attaced by the alien." 
      "We blew up the Corridor so I can not leave the room.Due to a broken helmet," 
      "I will die here tell my wife i loved her.-Captin Walker." 
      print "Good info to know, Lets get out of here" 

      return'Corridor' 

     elif action == "Bridge" "Go to Bridge": 

      return 'Corridor' 

class finished(Scene): 

    def enter(self): 
     print "%r you live and get rescued." 
     return 'finished' 

class Map(object): 

    scenes = { 
    'MedLab': MedLab(), 
    'Corridor': Corridor(), 
    'TheBridge': TheBridge(), 
    'Reactor': Reactor(), 
    'Escapepods': Escapepods(), 
    'MyRoom': MyRoom(), 
    'death': Death(), 
    'finished': finished(), 
    } 
    def __init__(self, start_scene): 
     self.start_scene = start_scene 

    def next_scene(self, scene_name): 
     val = Map.scenes.get(scene_name) 
     return val 
    def opening_scene(self): 
     return self.next_scene(self.start_scene) 

a_map = Map('MedLab') 
a_game = Engine(a_map) 
a_game.play(play) 

在代码中有一个不想玩的错误。帮助please.i不知道问题出在哪里确定它是与a_game.play(玩)和引擎中的某个地方。但是,然后我仍然在学习。让这款游戏发挥作用 - Python学习Python的难题 - Zed Shaw Ex43

+1

当您尝试运行时,错误信息是什么> ??? – 2015-11-06 22:04:25

+3

什么是错误? – ppperry

+0

我们不能帮助你,直到你帮助我们:) – 2015-11-06 22:06:02

回答

2

一个问题,我看到那肯定就会停止你的代码的形式做你想要西隧是这样的:

if raw_input == 'yes' 'y':

对于一个没有使用你的字符串列表或其他容器中,该格式它们被连接所以你在做:

if raw_input == 'yesy'

第二个问题是raw_input是一个函数不是你所得到的形式,它的价值所以你到底有:

if <built-in function raw_input> == 'yesy':

这不会是True

你想要的是一样的东西:

answer = raw_input(...) 
if answer in ['yes', 'y']: 
    do_stuff() 

这样的事情:

elif action == "Shoot it" "fire your gun": 

你会想:

elif any(['Shoot it' in action, 'fire your gun' in action]): 

你可能会想一定要规范你输入通过使其全部小写,因为'A' == 'a'False。我建议给您的用户选项或寻找字数较少和更加普遍,因为

>>> action = 'shoot your gun' 
>>> any(['Shoot it' in action, 'fire your gun' in action]) 
False 

更健壮的方式做这将是列出你的用户或仅测试采取具体行动的话当然的选项:

if any(['shoot' in action, 'fire' in action]) 
+0

先生,我的帽子不在您身边,您需要梳理所有代码。 – McGlothlin

+0

只是无语 – 2015-11-06 22:28:32

+0

谢谢我对所有这些抱歉,因为没有足够快速的回应。我从来没有任何正式的培训只是想看看我能不能做出一些事情......我明白这可能是它不起作用的原因。感谢您的帮助IanAuld我实际上是在尝试在计算机中输入新的更改。 –