zoukankan      html  css  js  c++  java
  • Learn Python the hard way, ex41 来自Percal 25 号星星的哥顿人

    我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试

      1 #!/urs/bin/python
      2 #coding:utf-8
      3 from sys import exit
      4 from random import randint
      5 
      6 def death():
      7     quips=["you died. you kinda suck at this.",
      8     "nice job,you died ...jackass.",
      9     "such a luser",
     10     "I have a small puppy that's better at this."]
     11 
     12     print quips[randint(0,len(quips)-1)]
     13     exit(1)
     14 
     15 def central_corridor():
     16     print "the gothons of planet percal #25 have invaded your ship and destroyed"
     17     print "your entire crew. you are the last surviving member and your last"
     18     print "mission is to get the neutron destruct bomb from the weapons armory"
     19     print "put it in the bridge,and blow the ship up after getting into an "
     20     print "escape pod"
     21     print "
    "
     22     print "you're running down the central corrdior to the weapons armory when"
     23     print "a gothon jumps out,red scaly skin ,dark grimy teeth,and evil clown costume"
     24     print "flowing around his hate filled body.he's blocking the door to the"
     25     print "armory and about to pull a weapon to blast you."
     26 
     27     action =raw_input(">>")
     28 
     29     if action == "shoot!":
     30         print "quick on the draw you yank out your blaster and fire it at the gothon"
     31         print "his clown costume is flowing and moving around his body,which throws"
     32         return "you are dead.then he eats you."
     33 
     34     elif action == "dodge!":
     35         print "like a world class boxer you dodge,weave ,slip and slide right"
     36         print "as the gothon's blaster cranks a laser past your head."
     37         return "death"
     38 
     39     elif action == "tell a joke":
     40         print "lucky for you they made you learn gothon insults in the academy."
     41         print "you tell the one tothon joke you know:"
     42         return "laser_weapon_armory"
     43     else :
     44         print "DOES NOT COMPUTE"
     45         return 'central_corridor'
     46 
     47 def laser_weapon_armory():
     48     print "you do a dive roll into the weapon armory,crouch and scan the room"
     49     print "for more gothens that might be hiding. it's dead quiet,too quiet"
     50     print 'get the bomb. the code is 3 digits.'
     51     code = "%d%d%d" % (randint(1,9),randint(1,9),randint(1,9))
     52     guess = raw_input("[keypad]>>")
     53     guesses = 0
     54 
     55     while guess != code and guesses<10:
     56         print "BZZZZZZZ"
     57         guesses+=1
     58         guess = raw_input("[keypad]>>")
     59 
     60     if guess == code:
     61         print "bridge where you must place it in the right spot"
     62         return 'the_bridge'
     63     else :
     64         print "ship from their ship and you die"
     65         return 'death'
     66 
     67 def the_bridge():
     68     print "arm and don't want to set it off."
     69 
     70     action = raw_input(">>")
     71 
     72     if action == "throw the bomb":
     73         print "it goes off"
     74         return 'death'
     75     elif action == "slowly place the bomb":
     76         print "get off this tin can"
     77         return 'escape_pod'
     78     else:
     79         print "DOES NOT"
     80         return "the_bridge"
     81 
     82 def escape_pod():
     83     print "do you take?"
     84     good_pod = randint(1,5)
     85     guess = raw_input("[pod #]>>")
     86 
     87     if int(guess) != good_pod:
     88         print "into jam jelly"
     89         return 'death'
     90     else:
     91         print "time .you won"
     92         exit(0)
     93 
     94 ROOMS = {
     95     'death':death,
     96     'central_corridor':central_corridor,
     97     'laser_weapon_armory':laser_weapon_armory,
     98     'the_bridge':the_bridge,
     99     'escape_pod':escape_pod
    100 }
    101 
    102 def runner(map,start):
    103     next = start
    104 
    105     while True:
    106         room= map[next]
    107         print "
    -----------"
    108         next = room()
    109 
    110 runner(ROOMS,'central_corridor')

    Output:

     1 -----------
     2 the gothons of planet percal #25 have invaded your ship and destroyed
     3 your entire crew. you are the last surviving member and your last
     4 mission is to get the neutron destruct bomb from the weapons armory
     5 put it in the bridge,and blow the ship up after getting into an 
     6 escape pod
     7 
     8 
     9 you're running down the central corrdior to the weapons armory when
    10 a gothon jumps out,red scaly skin ,dark grimy teeth,and evil clown costume
    11 flowing around his hate filled body.he's blocking the door to the
    12 armory and about to pull a weapon to blast you.
    13 >>tell a joke
    14 lucky for you they made you learn gothon insults in the academy.
    15 you tell the one tothon joke you know:
    16 
    17 -----------
    18 you do a dive roll into the weapon armory,crouch and scan the room
    19 for more gothens that might be hiding. it's dead quiet,too quiet
    20 get the bomb. the code is 3 digits.
    21 [keypad]>>123
    22 BZZZZZZZ
    23 [keypad]>>369
    24 BZZZZZZZ
    25 [keypad]>>789
    26 BZZZZZZZ
    27 [keypad]>>741
    28 BZZZZZZZ
    29 [keypad]>>456
    30 BZZZZZZZ
    31 [keypad]>>951
    32 BZZZZZZZ
    33 [keypad]>>753
    34 BZZZZZZZ
    35 [keypad]>>852
    36 BZZZZZZZ
    37 [keypad]>>147
    38 BZZZZZZZ
    39 [keypad]>>963
    40 BZZZZZZZ
    41 [keypad]>>563
    42 ship from their ship and you die
    43 
    44 -----------
    45 such a luser
    46 
    47 ***Repl Closed***
  • 相关阅读:
    MySQL严格模式总结
    python筛选关键字---error
    将pem证书转换成p12格式证书
    ## 游戏网关源码赏析
    pid获取
    顺序io_磁盘队列
    nsq源码阅读3_编译nsqd
    nsq源码阅读2_核心数据结构
    nsq源码阅读1_目录结构
    如何设计Mqtt的Retain?
  • 原文地址:https://www.cnblogs.com/sub2020/p/7873463.html
Copyright © 2011-2022 走看看