Commit 460dc368 by BellCodeEditor

save project

parent 79fd67ff
Showing with 11 additions and 1 deletions
...@@ -5,14 +5,23 @@ class Hero(object): ...@@ -5,14 +5,23 @@ class Hero(object):
self.hp = 250 self.hp = 250
self.attack = 40 self.attack = 40
self.name = name self.name = name
print('英雄',str(self.name),'创建成功!血量:'+str(self.hp)+',攻击力:'+str(self.attack))
def combat(self, ememy): # 攻击 def combat(self, ememy): # 攻击
ememy.hp = ememy.hp - self.attack ememy.hp = ememy.hp - self.attack
if ememy.hp < 0 or ememy.hp == 0: if ememy.hp < 0 or ememy.hp == 0:
print(str(ememy.name),'阵亡,游戏结束') print(str(ememy.name),'阵亡,游戏结束')
exit()
else: else:
print(str(self.name)+'使用了攻击,对'+str(ememy.name)+'造成了'+str(self.attack)+'点伤害,'+str(ememy.name)+'还剩'+str(ememy.hp)+'点血量') print(str(self.name),'使用了攻击,对',str(ememy.name),'造成了'+str(self.attack)+'点伤害,',str(ememy.name),'还剩'+str(ememy.hp)+'点血量')
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi= Hero("后羿") houyi= Hero("后羿")
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi)
yase.combat(houyi) yase.combat(houyi)
\ 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