te41

from sys import exit
from random import randint  #aimed to create random number


def death():
	'''you will die with a random words'''
	die = ["you died.you kinda suck at this.","nice job, you died ... jackass.","suck a luser.","i have a puppy that's better at this."]
	
	print die[randint(0,len(die)-1)]
	print death.__doc__
	exit(1)
	
	

	
	
def central_corridor():
	print"the Gothons of planet percal #25 have invaded your ship an destroyed"
	print"your entire crew. you are the last surviving menber an your last"
	print"mission is to get the neutron destruct bomb from the weapons armory"
	print"put it in the brige, and blow the ship up after geting into an"
	print"escape pod"
	print"\n"
	print"you're running down the central corridor to the weapons armory when"
	print"a Gothon jumps out, red scaly skin, ark grimy teeth, and evil clown costume"
	print"flowing around his hate filled bidy.he's blocking the door to the"
	print"armory and about to pull a weapon to blast you. "
	
	action = raw_input(">")
	
	if action == "shoot":
		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 an insane rage and blast you repeatedly in the face until"
		print"you are dead. then he eats you."
		return "death"
	elif action == "dodge":
		print"like a world class boxer you dodge, weave, slip and slide 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."
		print"death"
		
	elif action == "tell a joke":
		print"lucky for you they made you learn Gothon insults in the academy."
		print"you tell the one Gothon joke you know:"
		print"lbhe sa aoih aoid aiu aoih aojf aoijoafijo."
		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 weapon armory door."
		return"laser_weapon_armory"
		
	
	else:
		print"does not compute."
		return"centeal_corridor"
		
def laser_weapon_armory():
	print"you do a dove 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 the container. there's a keypad lock on the box"
	print"and you need the code to get the bomb out.if you get code"
	print"wrong 10 times then the lock closes forever an 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))
	guess = raw_input("[keypad]>")
	guesses = 0
	
	while guess != code and guesses <10:
		print"bzzzzd"
		guesses += 1
		guess = raw_input("[keypad]>")
		
	if guess == code:
		print "the comntainer 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"brige where you must place it in the right spot"
		return"the_brige"
	else:
		print"the lock buzzes one last time and then you hear a sickening"
		print"melting sound as the mechanism is fused together."
		print"you decide to sit there, and finally the Gothons blow the"
		print"ship from their ship and you die."
		return"death"
		
		
def the_bridge():
	print"you burst onto the brige with the neutron destruct bomb"
	print"under your arm and surprises 5 Gothons who are trying to"
	print"take control of the ship. each of them have 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 your right in the bavk killing you."
		print"as you die you see another 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 pace the bomb":
		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 then carefully"
		print"you jumped back the lock so the Gothons can't get out."
		print"now that the bomb is placed your run to escape pod to"
		print"get off this tin can"
		return"escape_pod"
	else:
		print"does not compute"
		return "the_bridge"
		
		
		
def escape_pod():
	print"you rush through the ship 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 could be damaged"
	print"but you don't have time to look. there's 5 pods, whic one"
	print"do you take?"
	
	good_pod= randint(1,5)
	guess = raw_input("[pod]>")
	
	
	if int(guess) != good_pod:
		print"you jumped into %s and hit the eject buttom."%guess
		print"the pod escapes out into the void of space, then"
		print"implodes as the hull ruptures, crushing your body"
		print"into jam jelly"
		return"death"
	else:
		print"you jumped into %s and hit the eject buttom."%guess
		print"the pod easily slides out into the space heading to"
		print"the planet below. as it flies to the planet, as you look"
		print"back and see your ship implode then explose like a"
		print"bright star, taking put the Gothon ship at the same"
		print"time, you won!"
		exit(0)
		

ROOMS= {
	"death":death,
	"central_corridor":central_corridor,
	"the_brige":the_bridge,
	"laser_weapon_armory":laser_weapon_armory,
	"escape_pod":escape_pod
}


def runner(map, start):
	next = start
	
	while True:
		room = map[next]
		print"\n-------"
		next= room()
		
runner(ROOMS,"central_corridor")
  1. 先进入runner两个参数分别为ROOMS 和"central_corridor"
  2. 函数中next赋值为"central_corridor" 进入循环 room赋值为central_corridor() 在打印 虚线
  3. 给next赋值为 room()先进入 central_corridor()在让next为返回值
  4. 以此类推直到exit()
  5. 疑问 开始 die是用 quips代替的老出现NameError: global name 'qiups' is not defined 不知道原因
  6.  doc strings 可用用于注释函数并打印出来 function._doc_
  7. exit(0) and exit(1)   is there any difference?
  8. 有限状态机(finite state machine)  (类似图灵机 进入动作(entry action):在进入状态时进行 退出动作:在退出状态时进行 输入动作:依赖于当前状态和输入条件进行 转移动作:在进行特定转移时进行)
  9. 为什么 可以输入11次密码 因为开始就输入了一次对应数字0 yu9对应时已经输入了10次因为9小于10还会再输一次


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值