Commit 7545591c by BellCodeEditor

save project

parent b4a6964f
Showing with 67 additions and 7 deletions
import random
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero:
def __init__(self, name): def __init__(self,name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
self.attack = 40 self.attack = 40
self.name = name self.name = name
self.max_hp=self.hp
def combat(): # 攻击 def combat(self,enemy): # 攻击
info2="造成"+str(self.attack)+"点伤害,"
info1=self.name+enemy.name+"发起进攻,"
enemy.hp=enemy.hp-self.attack
if enemy.hp>0:
info3=enemy.name+"还剩"+str(enemy.hp)+"点血"
info=info1+info2+info3
print(info)
else:
info3=enemy.name+"已阵亡"
info=info1+info2+info3
print(info)
exit()
def cure(self):
self.hp=self.hp+60
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name+"已增加",60,"点血量,"+"目前血量为:",self.hp)
class Player(Hero):
def __init__(self,name,hero_type):
super().__init__(name)
self.level = 1
self.hp = 210
self.attack = 55
self.max_hp=self.hp
self.name = name
self.hero_type=hero_type
print("角色"+self.name+"已生成,英雄类型为:",self.hero_type)
print(self.name,"的血量、等级、攻击力为:",self.hp,self.level,self.attack)
def cure(self):
blood=random.randint(30,50)
self.hp=self.hp+blood
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name+"已增加",blood,"点血量,"+"目前血量为:",self.hp)
yase = Hero("垭瑟")
houyi= Hero("后羿") houyi=Player("后羿","射手")
yase.combat(houyi) yase=Hero("亚瑟")
\ No newline at end of file print("-"*30)
print(" 战斗开始")
while True:
print("-"*30)
choice=input("请选择技能(1攻击/2治疗)")
if choice=="1":
houyi.combat(yase)
elif choice=="2":
houyi.cure()
elif choice=="q":
print("已退出游戏")
break
else:
print("请输入1或2")
continue
status=random.randint(1,3)
if status==1:
yase.cure()
else:
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