import random
import time
evevt=["衣衫褴褛的人","沼泽"]
source=["木材","肉","布"]
SKILL=["降龙十八掌","打狗棒法","九阴白骨掌","如来神掌","九阴真经"]
def Init():
person={"HP":100,"hungry":100,"IQ":100,"skill":"","木材":100,"fire":0}
time.sleep(3)
print("人物生成中》》》》》》》》50%")
time.sleep(3)
print("人物生成中》》》》》》》》90%")
time.sleep(3)
print("人物生成完毕》》》》》》》》》》》》》》100%")
showPerson(person)
return person
def fire(person):
person["木材"]=person["木材"]-1
person["fire"]=1
print("火堆燃起来了!")
showPerson(person)
return person
def PlayGame():
#point=random.randint(0,1)
point=0
if point ==0:
print("碰到了衣衫褴褛的人")
choose=input("是否要给予木柴:")
if choose =="是":
person["木材"]=person["木材"]-1
if 80<random.randint(0,100):
skill=random.choice(SKILL)
skill.remove(skill)
person["skill"]=person["skill"]+skill
person["HP"]=person["HP"]+100
else:
print("你获得衣衫褴褛的人的武功秘籍")
return person
def showperson(person):
print("你现在的状态是",person)
def showPerson(person):
print(person)
person=Init()
person=fire(person)
person=PlayGame()
showPerson(person)
运用了def函数的嵌套,写的过程中我出现了许多失误,所幸最后都解决了。
运行效果:人物生成中》》》》》》》》50%
人物生成中》》》》》》》》90%
人物生成完毕》》》》》》》》》》》》》》100%
{‘HP’: 100, ‘hungry’: 100, ‘IQ’: 100, ‘skill’: ‘’, ‘木材’: 100, ‘fire’: 0}
火堆燃起来了!
{‘HP’: 100, ‘hungry’: 100, ‘IQ’: 100, ‘skill’: ‘’, ‘木材’: 99, ‘fire’: 1}
碰到了衣衫褴褛的人
是否要给予木柴:是
{‘HP’: 100, ‘hungry’: 100, ‘IQ’: 100, ‘skill’: ‘’, ‘木材’: 98, ‘fire’: 1}