Commit 77e87da0 by BellCodeEditor

save project

parent 984850c8
Showing with 29 additions and 11 deletions
...@@ -4,16 +4,34 @@ class Hero(): ...@@ -4,16 +4,34 @@ class Hero():
self.name = name self.name = name
self.hp = hp self.hp = hp
self.attack = attack self.attack = attack
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.hp + 5 # self.attack = self.hp + 5
yase = Hero('亚瑟',300,20) # yase = Hero('亚瑟',300,20)
houyi = Hero('后羿',250,25) # houyi = Hero('后羿',250,25)
print('亚瑟的血量为' + ':' + str(yase.hp)) # print('亚瑟的血量为' + ':' + str(yase.hp))
print('后羿的血量为' + ':' + str(houyi.hp)) # print('后羿的血量为' + ':' + str(houyi.hp))
yase = Hero('亚瑟',300,20) # yase = Hero('亚瑟',300,20)
yase.upgrade() # yase.upgrade()
print(yase.hp) # print(yase.hp)
def combat(self,i):
i.hp = i.hp - self.attack
c1 = self.name + '对' + i.name + '发动进攻,'
c2 = '造成' + str(self.attack) + '点伤害,'
if i.hp > 0:
c3 = i.name + '还剩下' + str(i.hp) + '血量'
c = c1 + c2 + c3
print(c)
else:
c3 = i.name + '阵亡,游戏结束。'
c = c1 + c2 + c3
print(c)
yase=Hero('亚瑟',250,40)
houyi=Hero('后羿',250,50)
yase.combat(houyi)
houyi.combat(yase)
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