Commit b39a8d79 by BellCodeEditor

save project

parent 9a8f86cd
Showing with 61 additions and 10 deletions
...@@ -9,7 +9,6 @@ class Hero: # 英雄类 ...@@ -9,7 +9,6 @@ class Hero: # 英雄类
self.attack = '出错了!"attack"未设置' self.attack = '出错了!"attack"未设置'
self.max_hp = self.hp self.max_hp = 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)+"点伤害,"
...@@ -25,12 +24,33 @@ class Hero: # 英雄类 ...@@ -25,12 +24,33 @@ class Hero: # 英雄类
exit() exit()
def cure(self): def cure(self):
self.hp = self.hp + 10 curehp = random.randint(5,30)
self.hp = self.hp + curehp
if self.hp > self.hp_max: if self.hp > self.hp_max:
self.hp = 250 self.hp = 250
print(str(self.name),'血量已达到最大限制!')
else: else:
print(str(self.name),'回血成功!血量加10点,目前血量:',str(self.hp)) pass
print(str(self.name),'回血成功!目前血量:',str(self.hp))
# print('log:',curehp)
def wk(self):
wkmax = random.randint(0,20)
# print('log:',wkmax)
if wkmax > 9:
print(self.name,'没有挖到任何东西')
else:
wkmax2 = int(random.randint(1,3))
self.level = self.level + wkmax2
print(self.name,'挖到了',wkmax2,'经验,目前经验:',self.level)
def sj(self):
if self.level >= 5:
self.hp = self.hp + 30
self.attack = self.attack + 5
self.level = self.level - 5
print(str(self.name),'升级成功!血量加30,攻击力加5,扣除经验5')
else:
print(str(self.name),'经验不足,无法升级')
class Player(Hero): # 玩家英雄 class Player(Hero): # 玩家英雄
def __init__(self,name,hp,attack): def __init__(self,name,hp,attack):
...@@ -41,17 +61,42 @@ class Player(Hero): # 玩家英雄 ...@@ -41,17 +61,42 @@ class Player(Hero): # 玩家英雄
print(str(self.name)+'创建成功!血量:',str(self.hp),',攻击力:',str(self.attack)) print(str(self.name)+'创建成功!血量:',str(self.hp),',攻击力:',str(self.attack))
player1 = Player("后羿",220,15) player1 = Player("后羿",200,5)
player2 = Player("亚瑟",250,10) player2 = Player("亚瑟",200,5)
while True: while True:
print('--------------------------------') print('=' * 35)
user_input = str(input('请选择英雄技能(1:攻击,2:回血)')) user_input = str(input('请选择英雄技能(1:攻击,2:回血,3:挖矿):'))
if user_input == "1": if user_input == "1":
player1.combat(player2) player1.combat(player2)
if player2.hp > 50: if player2.hp > 50:
player2.combat(player1) player2.combat(player1)
else: else:
player2.cure() player2.cure()
if user_input == "2": elif user_input == "2":
player2.cure()
player1.cure() player1.cure()
if random.randint(0,1) == 0:
if player2.level >= 5:
player2.wk()
else:
player2.cure()
elif user_input == "3":
player1.wk()
if random.randint(0,1) == 0:
if player2.level >= 5:
player2.wk()
else:
player2.cure()
else:
player2.combat(player1)
elif user_input == "4":
player1.sj()
if random.randint(0,1) == 0:
if player2.level >= 5:
player2.wk()
else:
player2.cure()
else:
player2.combat(player1)
else:
print('无效字符,请重新输入')
\ No newline at end of file
a = [1, 2, 3, 4, 5]
print(a)
a.append(12)
print(a)
\ 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