笨方法学python 习题36家庭作业-设计并实现文字游戏

笨方法学python 习题36家庭作业

设计

选择房间-神犬-摸头-获得神犬一条-打怪-如果有最少3条小狗则胜利
				    		 	  -如果少于3条小狗则被丢进老虎房间
   			       			-留下
	        -摸尾巴-被咬狂犬病游戏结束
	   -老虎(饿)-退出房间
	     	     -丢肉-老虎(饱)
	     	     -走过去-饿的话就死亡游戏结束
		    	       -饱的话就进入小狗房间
	   -返回选择房间

实现

#coding=utf-8
from sys import exit


def dog_room(dog):
    play = raw_input("would you play the dog?")
    if "head" in play :
        for i in range(1,6):
            print "you play the dog's head %d time" % i
        dog = int(dog) + 1
        fight = raw_input("Do you want to fight with god?  or no?")
        if fight == "yes":
            fight_god(dog)
        else :
            dog_room(dog)
    elif "tail" in play:
        dead("dog bite you")
    else:
        print "you can play head or tail"
        dog_room(dog)
                
def tiger_room(dog):
    hungry = True
    while True:
        do = raw_input("there is a tiger in front of the door,you would ?")
        if "flee" in do:
            start(dog)
        elif "give meat" in do:
            hungry = false
        elif "move" in do:
            if hungry:
                dead("tiger eat you")
            else :
                dog_room(dog)
        else :
            print "you can flee 、give meat or move"
            tiger_room(dog)

def fight_god(dog):
    if dog >= 3:
        print "you kill the god,you are winner"
        exit(0)
    else:
        tiger_room(dog)
            
def start(dog):
    print "now we have two room"
    room = raw_input("please select a room:")
    if room == "dog":
        dog_room(dog)
    elif room == "tiger":
        tiger_room(dog)
    else :
        print "you must select dog or tiger"
        start(dog)
    
def dead(why):
    print why,"good job!"
    exit(0)
    

start(2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值