笨方法学Python笔记(8)

上一道习题我们跟着作者写了一个长长的(其实也就60多行)代码,现在进行下一个习题--习题 36: 设计和调试。根据要求,在这一部分,我们将要自己设计一个文字类的游戏,先画一个地图,标出障碍和怪物,然后编写程序来实现。不过本宝宝怎么能落入俗套,和外面那些妖艳贱货比呢?作为不一样的烟火,本宝宝要另辟蹊径,画一张燃的地图,游戏的主题就是——解救薛之谦!故事的背景是:wuli谦谦被大魔王拐走了,本宝宝化身女侠要进入迷宫,解救谦谦,然后一起策马奔腾共赴人间天堂......(捂脸中)

-----------------------------------------------------这是分割线-------------(画歪了)----------------------------------------------------------

----------------------------------------------下面是代码,请运行,谦谦的生死就靠你------------------------------------------------------

代码拷贝过去之后直接python 文件名.py运行即可。循环什么的我都已经考虑好了。

def search_around1():
	print "1.Climbe out the hole."
	print "2.Wait for the great devil come to kill you."
	next = raw_input("> ")
	if next == "1":
		try_again()
		search_around2()
	elif next == "2":
		dead()
	else:
		unknow_input()
		search_around1()

def search_around2():
	print "1.Climbe out the hole."
	print "2.Wait for the great devil come to kill you."
	next = raw_input("> ")
	if next == "1":
		print "Good job!You are now out of the deep hole."
		search_around3()
	elif next == "2":
		dead()
	else:
		unknow_input()
		search_around2()

def search_around3():
	hint1()
	next = raw_input("> ")
	if next == "1":
		print "Oh,shit!You falled into a deep hole!"
		search_around1()
	elif next == "2":
		origi_room()
	else:
		unknow_input()
		search_around3()

def dead():
	print "Sorry, this mission fails and you'll die soon."
	exit(0)
		
def try_again():
	print "Sorry, try again. It seems difficult for you."
	
def unknow_input():
	print "Sorry, I don't know what you want to do."
	
def hint1():
	print "1.Search around."
	print "2.Open the door"
	
def origi_room_map():
	print """
	|====================================================================================================|
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|----------------| |-----------------------------|  |----------------------------|  |----------------|
	|                 1                                2                               3                 |
	|                                                 YOU                                                |
	|																									 |
	|===============================================||   ||==============================================|
	
	"""
	origi_room_hint()
	
def origi_room():
	origi_room_hint1()
	next = raw_input("> ")
	if next == "1":
		door1_room_map()
		door1_room_action1()
	elif next == "2":
		door2_room_map()
		door2_room_action()
	elif next == "3":
		door3_room();
	else:
		unknow_input()
		origi_room()
		
def origi_room_hint():
	print "Now you are in the castle."
	print "There are three doors in front of you."
	
def origi_room_hint1():
	print "1.Open the door1."
	print "2.Open the door2."
	print "3.Open the door3."
	
def go_into_room():
	return 0
	
def door1_room_map():
	print """
	|====================================================================================================|
	|                            |																		 |
	|                            |																		 |
	|                          	 |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|                          ^ |                                                                       |
	|                YOU      |_|                                                                        |
	|----------------| |-----------------------------|  |----------------------------|  |----------------|
	|                 1                                2                               3                 |
	|                                                                                                    |
	|																									 |
	|===============================================||   ||==============================================|
	
	"""
	print "You come into the room."
	print "There is  a candle on your right."

def door1_room_hint2():
	print "You move along the wall.Find a deep hole in front of you."
	print "There is a pool on your left."
	print "You use the candle to find that a tigher is sitting on the other side."

def door1_room_action1():
	print "1.Take the candle"
	print "2.Walk and search around."
	next = raw_input("> ")
	if next == "1":
		door1_room_hint2()
		door1_room_action2()
	elif next == "2":
		print "You come across a tiger, and it eat you soon."
		print "Mission fails."
	else:
		unknow_input()
		door1_room_action1()
	
def door1_room_action2():
	print "1.Run away now."
	print "2.Jump into the pool."
	print "3.Scream out."
	next = raw_input("> ")
	if next == "1":
		print "Unfortunately, tiger runs faster than you."
		print "You lose your legs and the head."
		print "Mission fails."
	elif next == "2":
		print "It is a nice choose. You swim to the other side and find a door there."
		door1_room_map2()
		door1_room_out()
	elif next3 == "3":
		print "Because of your screaming, the great devil comes and kills you immediately."
	else:
		unknow_input()
		door1_room_action2()	
		
def door1_room_map2():
	print """
	|====================================================================================================|
	|                            |																		 |
	|                            |																		 |
	|                _______   	 -                                                                       |
	|                |	p  | YOU -                                    	                                 |
	|                |  o  |     |                                                                       |
	|                |  o  |     |                                                                       |
	|                |  l  |     |                                                                       |
	|                |     |     |                                                                       |
	|      _______   |_____|     |                                                                       |
	|     | Tiger |              |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|----------------| |-----------------------------|  |----------------------------|  |----------------|
	|                 1                                2                               3                 |
	|                                                                                                    |
	|																									 |
	|===============================================||   ||==============================================|
		"""	

def door1_room_out():
	hint1()
	next = raw_input("> ")
	if next == "1":
		print "Tiger catches you and you die." 
		print "Mission fails."
	elif next == "2":
		door2_room_map()
		door2_room_action()
	else:
		unknow_input()
		door1_room_out()

def door2_room_map():
	print """
	|====================================================================================================|
	|                            |																		 |
	|                            |														|			|	 |
	|                _______   	 -  YOU                                                 |           |    |
	|                |	p  |     -                                    the great devil   |           |    |
	|                |  o  |     |                                                      |           |    |
	|                |  o  |     |                                                      |           |    |
	|                |  l  |     |                                                      |           |    |
	|                |     |     |                                                                       |
	|      _______   |_____|     |                                                                       |
	|     | Tiger |              |                                                                       |
	|                            |  |                                                                    |
	|                            |  |knife                                                               |
	|----------------| |-----------------------------|  |----------------------------|  |----------------|
	|                 1                                2                               3                 |
	|                                                                                                    |
	|																									 |
	|===============================================||   ||==============================================|
		"""	
	print "You look around, finding that the great devil is staring at you."
	print "You also find a knife that is on the corner on your right."

def door2_room_action():
	print "1.Run to the door2."
	print "2.Run to get the knife."
	print "3.Fight to the great devil."
	next = raw_input("> ")
	if next == "1":
		print "Fail to run away, the great devil catch you and kill you."
		print "Mission fails."
	elif next == "2":
		print "Good job!Now you can fight against the great devil!"
		door2_room_action2()
	elif next == "3":
		print "Because of strength disparity, you are killed by the great devil."
		print "Mission fails."
	else:
		unknow_input()
		door2_room_action()
	
def door2_room_action2():
	print "1.Fight against."
	print "2.Negociat with the great devil."
	next = raw_input("> ")
	if next == "1":
		fight_1()
	elif next == "2":
		print "The great kill you finally."
		print "Mission fails."
	else:
		unknow_input()
		door2_room_action2()
			
def fight_1():
	print "You lose your leg."
	print "Do you want to continue?"
	print "1.Fight against!"
	print "2.Surrender to the great devil."
	next = raw_input("> ")
	if next == "1":
		print "You are a hero. The God blesses you and help you defeat the great devil."
		print "Now you can take your princess away."
		print """
	|====================================================================================================|
	|                            |																		 |
	|                            |														|			|	 |
	|                _______   	 -                                                      |           |    |
	|                |	p  |     -                                                      |           |    |
	|                |  o  |     |                                                      |           |    |
	|                |  o  |     |                                                      |           |    |
	|                |  l  |     |                                                      |           |    |
	|                |     |     |                                                                       |
	|      _______   |_____|     |                                                                       |
	|     | Tiger |              |                                                                       |
	|                            |                                                                       |
	|                            |                                                                       |
	|----------------| |-----------------------------|  |----------------------------|  |----------------|
	|                 1                                2                               3                 |
	|                                                                                                    |
	|																									 |
	|===============================================||   ||==============================================|
											
										||||||||      |||||||
									   |		|	 |		 |
									  |		 ||||			  |
									 |  You and your princess  |
									  |						  |
									    |					|
										  |   			  |
											|		    |
											  |       |
												|   |
												  |
		"""		
	elif next == "2":
		print "The great kill you finally."
		print "Mission fails."
	else:
		unknow_input()
		fight_1()
		
def door3_room():
		print "The great devil is looking at you. Bad luck, you dead."
		exit(0)
		
def guard_room():
	return 0
	
def dini_room():
	return 0
	
def dog_room():
	return 0
	
def final_room():
	return 0
	
def hint():
	print "I can not understand what you want to."

def story_begin():
	print "One day, when Qianqian was giving a concert in Shanghai, the devil appeared and took him away."
	print "Qianqian falled in danger."
	print "Many people wanted to save Qianqian,however,no one had succeeded ever."
	print "Many years later, you showed up and decided to rescue Qianqian."
	print "Then you comes to a gruesome castle."
	print """
	|====================================================================================================|
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|                                                                                                    |
	|===============================================||   ||==============================================|
	
	                                              YOU ARE HERE
	"""
	
def game_process():
	hint1()
	next = raw_input("> ")
	if next == "1":
		print "Oh,shit!You falled into a deep hole!"
		print """
		|====================================================================================================|
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|                                                                                                    |
		|===============================================||   ||==============================================|
									+++++
									+YOU+
									+++++
				"""
		search_around1()
	elif next == "2":
		origi_room_map()
		origi_room()
	else:
		unknow_input()
		game_process()
		
story_begin()
game_process()

-----------------------------------------------------------------下面是解密时刻------------------------------------------------------------------

=====================================灵魂画手华丽登场====================================

我走过最深的套路,就是从策划版到实现版的差距、、、、(此时哭一分钟)下面是我贴出的策划版地图和最后程序实现版得到的结果。哎、、、难受、香菇。。。




=======================================================================================

总结:这个小游戏我只做了大半天,如果真的用一个星期的时间去完成,应该是可以达到策划版的效果的。在写的过程中,最经常的犯的错误就是if 后面用的是=而不是==,错了好多次。还有就是在写逻辑分支的时候,没有用循环来做,不然趣味性更好,而是用函数调用来实现的,只能说中规中矩。所以、、、你们最后成功了么?





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值