用户:
熊熊糖果查看:0 回复:0 评论:0 创建时间:2020-03-12T13:54:50
【作品展示】

【作品介绍】
简单的猫鼠大战游戏
【作品源代码】
import random
class Human:
def __init__(self,name,age=10,hp=20,mp=100,atk=1):
self.name=name
self.age=age
self.hp=hp
self.mp=mp
self.atk=atk
def atk_(self):
print('%s使用了普通攻击,造成了%s点伤害!'%(self.name,self.atk))
class Cat(Human):
def skill_(self):
print('%s使用了技能挥报纸,造成了%s点伤害!'%(self.name,self.atk*2))
self.mp-=20
class Mouse(Human):
def skill_(self):
print('%s使用了技能尖叫,造成了%s点伤害!'%(self.name,self.atk*2))
print('| 欢迎来到猫鼠大战 |')
print('猫:请输入1 鼠:请输入2')
p=input()
while p!='1' and p!='2':
print('请输入正确内容!')
p=input()
if p=='1':
play=Cat(input('请输入玩家名:'))
comp=Mouse('Jerry')
elif p=='2':
play=Mouse(input('请输入玩家名:'))
comp=Cat('Tom')
print('| 游戏开始 |')
for a in range(1,100):
print('%s : %s %s'%(play.name,'★'*play.hp,'☆'*(20-play.hp)))
print('%s : %s %s'%(comp.name,'★'*comp.hp,'☆'*(20-comp.hp)))
if play.hp==0 or comp.hp==0:
break
print('当前是第%s回合'%(a))
if a%2==0:
print('对方回合')
h='comp'
else:
print('你的回合')
h='play'
if h=='comp':
if random.randint(0,1)==1:
if comp.mp==0:
print('%s使用技能失败'%(comp.name))
comp.atk_()
play.hp-=comp.atk
else:
comp.skill_()
play.hp-=comp.atk*2
else:
comp.atk_()
play.hp-=comp.atk
if h=='play':
print('普通攻击输入1,技能输入2')
print('⚠输入其他内容将跳过此回合⚠')
play_atk=input()
if play_atk=='1':
play.atk_()
comp.hp-=play.atk
elif play_atk=='2':
if play.mp==0:
print('%s使用技能失败'%(play.name))
play.atk_()
comp.hp-=play.atk
else:
play.skill_()
comp.hp-=play.atk*2
else:
print('跳过回合')
print('| 游戏结束 |')
if play.hp==0:
print('电脑胜利')
else:
print('玩家胜利')
print()
print()
stop=input('按Enter停止程序')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端: