2015-11-06 39 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我實際上是在嘗試在計算機中輸入新的更改。 –