//学习笔记
双人简单对打程序:
class role:
def __init__(self
,name
,hp
,mp
):
self
.name
= name
self
.hp
= hp
self
.mp
= mp
pass
def pugong(self
,enemy
):
enemy
.hp
-=10
self
.mp
-=0
print('{}释放血气狂暴平a,{}还剩{}HP,{}还剩{}MP'.format(self
.name
,enemy
.name
,enemy
.hp
,self
.name
,self
.mp
))
pass
def jineng(self
,enemy
):
enemy
.hp
-=20
self
.mp
-=10
print('{}释放怒气爆发技能,{}还剩{}HP,{}还剩{}MP'.format(self
.name
,enemy
.name
,enemy
.hp
,self
.name
,self
.mp
))
pass
def huixue(self
):
self
.hp
+=10
print('{}血量恢复10点,HP={}'.format(self
.name
,self
.hp
))
pass
def __str__(self
):
return '{}--{}HP--{}MP'.format(self
.name
,self
.hp
,self
.mp
)
kuanzhan
= role
('狂战士',100,100)
hongyan
= role
('红眼',100,100)
while True:
if(kuanzhan
.hp
<=0 or hongyan
.hp
<=0):
if(kuanzhan
.hp
>hongyan
.hp
):
print('狂战胜利')
if (hongyan
.hp
> kuanzhan
.hp
):
print('红眼胜利')
if (hongyan
.hp
== kuanzhan
.hp
):
print('平局')
break
else:
kuanzhan
.pugong
(hongyan
)
print(kuanzhan
)
print(hongyan
)
print('*****************************************************************')
hongyan
.jineng
(kuanzhan
)
print(kuanzhan
)
print(hongyan
)
print('*****************************************************************')
hongyan
.huixue
()
print(kuanzhan
)
print(hongyan
)
**
结果:
**
转载请注明原文地址:https://blackberry.8miu.com/read-35337.html