Commit 040fe162 by BellCodeEditor

save project

parent 194638e4
Showing with 25 additions and 23 deletions
import random import random
import tkinter.messagebox
lantiao = 0 lantiao = 0
hit = [7000,8000,9000,10000] hit = [7000,8000,9000,10000]
cint = random.choice(hit) cint = random.choice(hit)
...@@ -15,7 +16,7 @@ class Hero(object): ...@@ -15,7 +16,7 @@ class Hero(object):
self.hp+=cint self.hp+=cint
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+"服用了一枚治疗丹,血量增加:", cint,",目前的血量为:",self.hp) tkinter.messagebox.showerror(self.name+"服用了一枚治疗丹,血量增加:", cint,",目前的血量为:",self.hp)
lantiao = lantiao+1 lantiao = lantiao+1
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
global lantiao global lantiao
...@@ -28,15 +29,15 @@ class Hero(object): ...@@ -28,15 +29,15 @@ class Hero(object):
if enemy.hp > 0: if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量" info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3 info = info1+info2+info3
print(info) tkinter.messagebox.showerror(info)
else: else:
info3 = enemy.name+"阵亡,游戏结束" info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3 info = info1+info2+info3
print(info) tkinter.messagebox.showerror(info)
if enemy.hp <= 0: if enemy.hp <= 0:
print("胜利") tkinter.messagebox.showerror("胜利")
if self.hp <= 0: if self.hp <= 0:
print("失败") tkinter.messagebox.showerror("失败")
exit() exit()
def qiang(self,enemy): def qiang(self,enemy):
...@@ -50,18 +51,18 @@ class Hero(object): ...@@ -50,18 +51,18 @@ class Hero(object):
if enemy.hp > 0: if enemy.hp > 0:
infu3 = enemy.name+"还剩下"+str(enemy.hp)+"血量" infu3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
infu = infu1+infu2+infu3 infu = infu1+infu2+infu3
print(infu) tkinter.messagebox.showerror(infu)
else: else:
infu3 = enemy.name+"阵亡,游戏结束" infu3 = enemy.name+"阵亡,游戏结束"
infu = infu1+infu2+infu3 infu = infu1+infu2+infu3
print(infu) tkinter.messagebox.showerror(infu)
if enemy.hp <= 0: if enemy.hp <= 0:
print("胜利") tkinter.messagebox.showerror("胜利")
if self.hp <= 0: if self.hp <= 0:
print("失败") tkinter.messagebox.showerror("失败")
exit() exit()
if lantiao < 8: if lantiao < 8:
print("蓝条不够,不能使用") tkinter.messagebox.showerror("蓝条不够,不能使用")
class Player(Hero): class Player(Hero):
def __init__(self,hero_type,name): def __init__(self,hero_type,name):
...@@ -70,33 +71,34 @@ class Player(Hero): ...@@ -70,33 +71,34 @@ class Player(Hero):
self.attack = 8688 self.attack = 8688
self.max_hp = self.hp self.max_hp = self.hp
self.hero_type = hero_type self.hero_type = hero_type
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type) tkinter.messagebox.showerror("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack) tkinter.messagebox.showerror("当前等级、血量、攻击力分别为:","self.level,self.hp,self.attack")
print('-'*30) tkinter.messagebox.showerror("提示","'-'*30")
print(' 战斗开始') tkinter.messagebox.showerror("提示","' 战斗开始'")
def cure(self): def cure(self):
c=random.randint(35,50) c=random.randint(35,50)
self.hp+=c self.hp+=c
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+"使用了治疗,血量增加:",str(c),",目前的血量为:",self.hp) tkinter.messagebox.showerror(self.name+"使用了治疗,血量增加:",str(c),",目前的血量为:",self.hp)
houyi = Player("初级战将", "血影战神") houyi = Player("初级战将", "血影战神")
yase = Hero("只因少将") yase = Hero("只因少将")
while True: while True:
print('-'*30) a=tkinter.messagebox.askquestion("请选择技能:yes攻击/no治疗")
a=input("请选择技能:1攻击/2治疗/3强化") if a=="yes":
if int(a)==1: c = tkinter.messagebox.askquestion("请选择技能:yes伤害/no强化")
if c=="yes":
houyi.combat(yase) houyi.combat(yase)
elif int(a)==2: else:
houyi.cure()
elif int(a)==3:
houyi.qiang(yase) houyi.qiang(yase)
elif a=="no":
houyi.cure()
elif a=="q": elif a=="q":
print('游戏结束') tkinter.messagebox.showerror('游戏结束')
break break
else: else:
print('重输!') tkinter.messagebox.showerror('重输!')
continue continue
b=random.randint(1,3) b=random.randint(1,3)
if b==3: if b==3:
......
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