ex36 自己编的一个冒险小游戏(未完待续)

Posted 丁头零零

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ex36 自己编的一个冒险小游戏(未完待续)相关的知识,希望对你有一定的参考价值。

  1 #-*- coding: UTF-8 -*-
  2 from sys import exit
  3 #作出判断选择进森林还是出海冒险
  4 def start():
  5     print "Now you are on an island,"
  6     print "you got a lot of things,but you‘re lonely and bored at your surroundings,"
  7     print "you gonna do something."
  8     do_sth = raw_input(">")
  9     if "yes" in do_sth:
 10         print "OK,now let‘s make a choice for what to do next."
 11         print "You can go inside the forest or you can take a ship to the sea."
 12         choice = raw_input(">")
 13         if "forest" in choice:
 14             forest()
 15         elif "sea" in choice:
 16             sea()
 17         else:
 18             dead("you‘ve just made the wrong choice,and you died.please restart the game.")
 19     else:
 20         print "Come on man ,don‘t be a sluggard ,say yes and let‘move."
 21         start()
 22         
 23         
 24 
 25 
 26 #定义死亡:打印死亡原因,并退出游戏
 27 def dead(why):
 28     print why,"What a pity."
 29     exit(0)
 30     
 31 #定义 兔子 事件,选择“shoot"之后,包里有枪就打死兔子并带走
 32 def rabbit():
 33     print "Now there is a rabbit in front of you.Propably you can shoot it and take it as your prey."
 34     print "shoot or not?"
 35     choice_of_rabit = raw_input(">")
 36     if "sho" in choice_of_rabit :#为什么这里用 if choice_of_rabit = "shoot"就不行?
 37         if "gun" in package:
 38             print "Bang,you got it!awesome."#如果我想要任何时候输入一个指令都能够查看我包裹里的东西,该怎么做?
 39             package.append("dead rabbit")
 40             print "Check your package.",package#这么写行么?
 41         else:
 42             print "Stupid! You forgot to take a gun."
 43     else:
 44         print "God bless you.Go ahead."
 45 
 46 #定义“熊”事件,包含“run"和”fight"两种应对模式        
 47 def bear():
 48     print "Hey,watch out man."
 49     cotinue = raw_input(">")
 50     print "There is a bear in front of you ,and it‘s staring at you ."
 51     cotinue = raw_input(">")
 52     print "So what would do? run? or fight?"
 53     while True:
 54         choice_of_bear1 = raw_input(">")
 55         if "run" in choice_of_bear1:
 56             run()
 57             break
 58         elif "fight" in choice_of_bear1:
 59             fight()
 60             break
 61         else:
 62             print"illeagal input,please try again."
 63 
 64 
 65 #逃跑 函数,需要判断包裹内物品然后决定生死            
 66 def run ():
 67     if "dead rabbit" in package:
 68         print "Oh,I got an idea,maybe you can throw your rabbit so the bear would be distracted."
 69         cotinue = raw_input(">")
 70         print"Do you wanna throw your rabbit?"
 71         while True:
 72             choice_of_run = raw_input(">")
 73             if "yes" in choice_of_run:
 74                 print"Excellent,the bear is eating the rabbit,and you made it to run."
 75                 break
 76             elif "no" in choice_of_run:
 77                 dead("You died because of your mean")
 78                 break
 79             else:
 80                 "Illeagal input ,say yes or no."
 81     else:
 82         dead("The bear catch you and eats you.")
 83         
 84 #战斗 函数,同样判断包裹内物品决定生死,但我觉得其实应该可以在使用axe后者dagger哪里不设置死亡,而是造成不同伤害值。        
 85 def fight():
 86     print "Now my hero,pick up something from your bag,and start fighting."
 87     print "What do you want?"
 88     while True:
 89         choice_of_fight = raw_input(">")
 90         if choice_of_fight in package:
 91             if "gun" in choice_of_fight:
 92                 print"BANG!BANG BANG BANG!You shoot it,and the bear died."
 93                 break
 94             else:
 95                 dead("You fight with %s,you‘re so brave,but still killed by the bear." %choice_of_fight)
 96         else:
 97             print "You don‘t have a %s,please make sure it‘s in your package." %choice_of_fight
 98     
 99     
100 
101         
102 
103 
104 
105     
106 
107     
108         
109 #整个森林冒险函数            
110                 
111 def forest():    
112     ware_house = ["water","axe","dagger","bread","gun","boots","electric torch","compass","life jacket","beer","dog"]
113     print "You need to make a package before you leave.You can only choose five stuffs.Now go and get what you want."
114     print ware_house
115     stuff_number = len (package)
116     while stuff_number < 5:
117         stuffs = raw_input(">")
118         if stuffs in ware_house :
119             package.append(stuffs)
120             ware_house.remove(stuffs)
121             print "Now that what you have:",package
122             print "You can also take something from ware_house.",ware_house#这里想不明白:第五次输入之后,按理说应该直接到“You‘ve taken enough things "那里,但是现在的情况是还会多打印两行
123         else:
124             print "Wrong input,please try again."
125         stuff_number = len (package)
126     else:
127         print "You‘ve taken enough things ,or it will be to heavy."
128     cotinue = raw_input(">")
129     print"--------------------------------------------------------"
130     print"Now let‘s start the journey."
131     print"There is a mushroom on the roadside,you wanna take it?"
132     
133     while True:
134         choice_mshrom = raw_input(">")
135         if "yes" in choice_mshrom:
136             package.append("mushroom")
137             print "OK,you have mushroom in your package now."
138             break
139         elif "no" in choice_mshrom:
140             print "Well,a good choice,Ah~"
141             break
142         else:
143             print"illeagal input,say yes or no."#这里如果出现非法输入,应当是回到前面的,怎么实现该?解决方案:While True 来实现。
144     print"--------------------------------------------------------"
145     rabbit()
146     print"--------------------------------------------------------"
147     bear()
148 
149 #要想正常运行那些函数,首先要定义一个package,否则会出错。    
150 package = []
151 start()
152 
153 
154     
155 
156     

 

以上是关于ex36 自己编的一个冒险小游戏(未完待续)的主要内容,如果未能解决你的问题,请参考以下文章

分布式 Git(未完待续)

接口继承与多态 总结(未完待续)

高精度模板(未完待续)

待续未完- 自己写后台内容管理程序的辅助内容

连接远程库踩的坑(未完待续)

2018.02.12 noip模拟赛T2(未完待续)