这句用错了
应该拆开写
if a == 1 or a == 2 or a == 3:
或者
if a in [1,2,3]:
import time
import random
class Role:
def __init__(self,name,hp):
self.name=name
self.hp=hp
def tong(self,enemy):
enemy.hp-=10
print('【%s】捅了【%s】一刀'%(self.name,enemy.name))
def kanren(self,enemy):
enemy.hp-=15
print('【%s】砍了【%s】一刀'%(self.name,enemy.name))
def dazhao(self,enemy):
enemy.hp-=30
print('【%s】对【%s】使用天外飞仙,眩晕【%s】一回合'%(self.name,enemy.name,enemy.name))
def chiyao(self):
self.hp+=10
print('【%s】吃了一口药'%(self.name))
def __str__(self):
return '%s还剩下%s的血量'%(self.name,self.hp)
xmcx=Role('西门吹雪',300)
ygc=Role('叶孤城',300)
time.sleep(3)
print('决战紫禁之巅')
print('对战双方:')
print(xmcx.name,'生命:%s'%(xmcx.hp))
print(ygc.name,'生命:%s'%(ygc.hp))
print('战斗开始!')
time.sleep(3)
while True:
if xmcx.hp<=0 or ygc.hp<=0:
break
a=random.randint(1,9)
if a in [1,2,3]:
ygc.dazhao(xmcx)
print(ygc)
print(xmcx)
print('**************************************')
continue
else:
ygc.kanren(xmcx)
print(ygc)
print(xmcx)
print('**************************************')
xmcx.tong(ygc)
print(ygc)
print(xmcx)
print('**************************************')
xmcx.chiyao()
print(ygc)
print(xmcx)
print('**************************************')
time.sleep(1)
print('游戏结束....')
print('西门吹雪获胜')
|