Commit 4dec67de by BellCodeEditor

auto save

parent beb166ed
Showing with 55 additions and 0 deletions
import random
class Hero:
def __init__(self,name):
self.name=name
self.level=1
self.hp=250
self.attack=40
self.max_level=self.hp
def zhiliao(self):
self.hp+=60
if self.hp>self.max_level:
self.hp=self.max_level
print(self.name+'使用治疗术,血量增加了60,现在血量是',self.hp)
def gongji(self,dueifang):
y1=self.name+'对'+dueifang.name+'发起攻击,'
y2='造成'+str(self.attack)+'点伤害,'
dueifang.hp-=self.attack
if dueifang.hp>0:
y3=dueifang.name+'还剩'+str(dueifang.hp)+'点血'
print(y1+y2+y3)
else:
y3=dueifang.name+'已阵亡'
print(y1+y2+y3)
exit()
class player(Hero):
def __init__(self,name,yingxiongleixin):
super().__init__(name)
self.hp=200
self.attack=50
self.yingxiongleixin=yingxiongleixin
print(self.name+'已创建'+self.yingxiongleixin)
print(self.name+'的等级,血量,攻击分别是',str(self.level),str(self.hp),str(self.attack))
houyi=player('后羿','射手')
yase=Hero('亚瑟')
print('*'*30)
print('战斗开始')
while True:
print('*'*30)
w=input('释放技能(1攻击/2治疗):')
if w=='1':
houyi.gongji(yase)
elif w=='2':
houyi.zhiliao()
elif w=='q' or w=='p':
print('战斗结束')
exit()
else:
print('请重输')
a=random.randint(1,3)
if a==1:
yase.zhiliao()
else:
yase.gongji(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