Commit b99dbb1b by BellCodeEditor

save project

parent 460dc368
Showing with 7 additions and 13 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class 游戏(object):
def __init__(self, name): def __init__(self, name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
...@@ -7,7 +7,7 @@ class Hero(object): ...@@ -7,7 +7,7 @@ class Hero(object):
self.name = name self.name = name
print('英雄',str(self.name),'创建成功!血量:'+str(self.hp)+',攻击力:'+str(self.attack)) print('英雄',str(self.name),'创建成功!血量:'+str(self.hp)+',攻击力:'+str(self.attack))
def combat(self, ememy): # 攻击 def 攻击(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),'阵亡,游戏结束')
...@@ -15,13 +15,7 @@ class Hero(object): ...@@ -15,13 +15,7 @@ class Hero(object):
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= 游戏("后羿")
yase.combat(houyi) for i in range(10):
yase.combat(houyi) yase.攻击(houyi)
yase.combat(houyi) \ No newline at end of file
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