Commit ff1d6fb9 by BellCodeEditor

save project

parent 01577f95
Showing with 34 additions and 11 deletions
# 英雄角色类
import random# 英雄角色类
class Hero(object):
def __init__(self, name):
def __init__(self, name,hp,att):
self.level = 1
self.hp = 250
self.att = 40
self.hp = hp
self.att = att
self.name = name
self.type='pc'
def combat(self,enemy): # 攻击
enemy.hp-=self.att
print(f'{self.name}attack to{enemy.name},',end="")
print(f'it got{self.att}blode,',end="")
def combat(self,enemy):
m=True
if self.type=='pc':
self.hp>60
else:
m=input(f'{self.name} 1=att 2=hp')=='1'
if enemy.hp>0:
if m:
if random.randint(1,100)<=50:
enemy.hp-=self.att*2
print(f'{self.name} high attack to {enemy.name},',end="")
print(f'it got {self.att*2} blode,',end="")
else:# 攻击
enemy.hp-=self.att
print(f'{self.name} attack to {enemy.name},',end="")
print(f'it got {self.att} blode,',end="")
else:
self.hp+=20
print(f'{self.name} heal 20 bolde')
if enemy.hp<=0:
print(f'{enemy.name}dide,game over.')
print(f'{enemy.name} dide,game over.')
exit()
else:
print(f'{enemy.name} surplus {enemy.hp} blode.')
yase = Hero("垭瑟")
houyi= Hero("后羿")
yase = Hero("垭瑟",300,25)
houyi= Hero("后羿",260,30)
ch=input('1=yase 2=houyi 3=none')
if ch=='1':
yase.type='human'
elif ch=='2':
houyi.type='human'
while True:
yase.combat(houyi)
houyi.combat(yase)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment