Commit 8daa4c3e by BellCodeEditor

save project

parent 0d877884
Showing with 9 additions and 32 deletions
import random class Hero(object):
class Hero:
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.level = 1 self.level = 1
...@@ -8,12 +7,12 @@ class Hero: ...@@ -8,12 +7,12 @@ class Hero:
self.max_hp = self.hp self.max_hp = self.hp
def cure(self): # 治疗 def cure(self): # 治疗
c=random.randint(30,60)
self.hp+=c self.hp+=60
if self.hp>self.max_hp: if self.hp>self.max_hp:
self.hp=self.max_hp self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:",c ,",目前的血量为:",self.hp) print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻," info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害," info2 = "造成"+str(self.attack)+"点伤害,"
...@@ -40,29 +39,7 @@ class Player(Hero): ...@@ -40,29 +39,7 @@ class Player(Hero):
houyi = Player("射手", "后羿") houyi = Player("射手", "后羿")
yase = Hero("垭瑟") yase = Hero("垭瑟")
print("-"*50,'\n',' 战斗开始!','\n','-'*50) houyi.combat(yase)
yase.combat(houyi)
while True: houyi.cure()
a=input("请选择要使用的技能,1攻击/2治疗 按Q退出游戏~") yase.cure()
if a=="Q": \ No newline at end of file
exit()
elif a=='1':
houyi.combat(yase)
elif a=='2':
houyi.cure()
else:
print("请重新输入!")
continue
b=random.randint(1,2)
if b==1:
yase.combat(houyi)
if b==2:
yase.cure()
#print("$"*50)
#
# yase.combat(houyi)
# houyi.cure()
# yase.cure()
\ 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