Commit 31ea2311 by BellCodeEditor

save project

parent dfb5d1b6
Showing with 32 additions and 0 deletions
class Hero:
def __init__(self, name,hp,gj):
self.level = 1
self.hp = hp
self.gj = gj
self.name = name
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.gj)+"点伤害,"
enemy.hp -= self.gj
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
class Player(Hero):
def __init__(self,name,hp,gj,lx):
super().__init__(name,hp,gj)
self.hp=hp
self.gj=gj
self.lx=lx
print('已选择'+self.name+',角色类型为'+self.lx)
print(self.name+'的等级、血量、攻击力分别为'+self.level+self.hp+self.gj)
rj=Player('艾尔.普利莫',6000,1500,'战士')
xl = Hero("雪莉",4000,1200,'射手')
sq= Hero("瑟骑",2800,1600,'射手')
xl.combat(sq)
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