双人对战游戏(不知道问题出在哪里 )
如题以下代码不知道哪里有问题,求修改import time
class Role:
def __init__(self,name,hp):
self.name=name
self.hp=hp
def tong(self,enemy):
enemy.hp-=10
info='【%S】捅了【%s】一刀'%(self.name,enemy.name)
def kanren(self,enemy):
ememy.hp-=15
info='【%S】砍了【%s】一刀'%(self.name,enemy.name)
def chiyao(self):
self.hp+=10
info='【%S】吃了一口药'%(self.name)
def __str__(self):
return '%S还剩下%s的血量'%(self.name,self.hp)
xmcx=Role('西门吹雪',100)
ygc=Role('叶孤城',100)
while True:
if xmcx.hp<0 or ygc.hp<0:
break
xmcx.tong(ygc)
print(ygc)
print(xmcx)
print('**************************************')
ygc.tong(xmcx)
print(ygc)
print(xmcx)
print('**************************************')
xmcx.chiyao()
print(ygc)
print(xmcx)
time.sleep(1)
%s用小写,大写没有意义
import time
class Role:
def __init__(self,name,hp):
self.name=name
self.hp=hp
def tong(self,enemy):
enemy.hp-=10
info='【%s】捅了【%s】一刀'%(self.name,enemy.name)
def kanren(self,enemy):
ememy.hp-=15
info='【%s】砍了【%s】一刀'%(self.name,enemy.name)
def chiyao(self):
self.hp+=10
info='【%s】吃了一口药'%(self.name)
def __str__(self):
return '%s还剩下%s的血量'%(self.name,self.hp)
xmcx=Role('西门吹雪',100)
ygc=Role('叶孤城',100)
while True:
if xmcx.hp<0 or ygc.hp<0:
break
xmcx.tong(ygc)
print(ygc)
print(xmcx)
print('**************************************')
ygc.tong(xmcx)
print(ygc)
print(xmcx)
print('**************************************')
xmcx.chiyao()
print(ygc)
print(xmcx)
time.sleep(1)
页:
[1]