Commit 7b239d2c by BellCodeEditor

save project

parent 825a6ea7
Showing with 27 additions and 12 deletions
class Hero: class Hero:
def __init__(self, name, hp, attack): def __init__(self, name):
self.level = 1 self.level = 1
self.name = name # name:名字 self.name = name # name:名字
self.hp= hp self.hp= 20000
self.attack= attack # attack:攻击 self.attack= 900 # attack:攻击
def combat(self,enemy):
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
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()
def upgrade(self): # def upgrade(self):
self.level=self.level+1 # self.level=self.level+1
self.hp=self.hp+50 # self.hp=self.hp+50
self.attack=self.attack+4 # self.attack=self.attack+4
yase = Hero("垭瑟",300,20) yase = Hero("亚瑟")
print("垭瑟的初始血量值为:",yase.hp) houyi = Hero("后羿")
yase.upgrade() yase.combat(houyi)
print("升级1次后,垭瑟的血量值为:",yase.hp) # print("垭瑟的初始血量值为:",yase.hp)
\ No newline at end of file # yase.upgrade()
# print("升级1次后,垭瑟的血量值为:",yase.hp)
\ 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