Commit 97a5fd04 by BellCodeEditor

auto save

parent a730203c
Showing with 24 additions and 7 deletions
import random
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -11,7 +12,7 @@ class Hero(object): ...@@ -11,7 +12,7 @@ class Hero(object):
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+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp) print(self.name+"使用了治疗,血量增加:", 30,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻," info1 = self.name+"对"+enemy.name+"发起进攻,"
...@@ -22,7 +23,7 @@ class Hero(object): ...@@ -22,7 +23,7 @@ class Hero(object):
info = info1+info2+info3 info = info1+info2+info3
print(info) print(info)
else: else:
info3 = enemy.name+"阵亡,游戏结束" info3 = enemy.name+"阵亡,游戏结束,我赢了!"
info = info1+info2+info3 info = info1+info2+info3
print(info) print(info)
exit() exit()
...@@ -39,7 +40,24 @@ class Player(Hero): ...@@ -39,7 +40,24 @@ class Player(Hero):
houyi = Player("射手", "后羿") houyi = Player("射手", "后羿")
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi.combat(yase) # houyi.combat(yase)
yase.combat(houyi) # yase.combat(houyi)
houyi.cure() # houyi.cure()
yase.cure() # yase.cure()
\ No newline at end of file print('-'*30)
print(" 战斗开始")
while True:
print('-'*30)
a=input("1、攻击,2、治疗:")
if a=='q':
exit()
if a=='1':
houyi.combat(yase)
if a=="2":
houyi.cure()
b=random.randint(1,3)
if b==1:
yase.cure()
elif b==2:
yase.combat(houyi)
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