鱼C论坛

 找回密码
 立即注册
查看: 2583|回复: 1

[已解决]双人对战游戏(不知道问题出在哪里 )

[复制链接]
发表于 2021-7-5 16:44:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题以下代码不知道哪里有问题,求修改
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)

最佳答案
2021-7-5 16:53:34
%s用小写,大写没有意义

  1. import time
  2. class Role:
  3.     def __init__(self,name,hp):
  4.         self.name=name
  5.         self.hp=hp
  6.     def tong(self,enemy):
  7.         enemy.hp-=10
  8.         info='【%s】捅了【%s】一刀'%(self.name,enemy.name)
  9.     def kanren(self,enemy):
  10.         ememy.hp-=15
  11.         info='【%s】砍了【%s】一刀'%(self.name,enemy.name)
  12.     def chiyao(self):
  13.         self.hp+=10
  14.         info='【%s】吃了一口药'%(self.name)
  15.     def __str__(self):
  16.         return '%s还剩下%s的血量'%(self.name,self.hp)
  17. xmcx=Role('西门吹雪',100)
  18. ygc=Role('叶孤城',100)
  19. while True:
  20.     if xmcx.hp<0 or ygc.hp<0:
  21.         break
  22.     xmcx.tong(ygc)
  23.     print(ygc)
  24.     print(xmcx)
  25.     print('**************************************')
  26.     ygc.tong(xmcx)
  27.     print(ygc)
  28.     print(xmcx)
  29.     print('**************************************')
  30.     xmcx.chiyao()
  31.     print(ygc)
  32.     print(xmcx)
  33.     time.sleep(1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-7-5 16:53:34 | 显示全部楼层    本楼为最佳答案   
%s用小写,大写没有意义

  1. import time
  2. class Role:
  3.     def __init__(self,name,hp):
  4.         self.name=name
  5.         self.hp=hp
  6.     def tong(self,enemy):
  7.         enemy.hp-=10
  8.         info='【%s】捅了【%s】一刀'%(self.name,enemy.name)
  9.     def kanren(self,enemy):
  10.         ememy.hp-=15
  11.         info='【%s】砍了【%s】一刀'%(self.name,enemy.name)
  12.     def chiyao(self):
  13.         self.hp+=10
  14.         info='【%s】吃了一口药'%(self.name)
  15.     def __str__(self):
  16.         return '%s还剩下%s的血量'%(self.name,self.hp)
  17. xmcx=Role('西门吹雪',100)
  18. ygc=Role('叶孤城',100)
  19. while True:
  20.     if xmcx.hp<0 or ygc.hp<0:
  21.         break
  22.     xmcx.tong(ygc)
  23.     print(ygc)
  24.     print(xmcx)
  25.     print('**************************************')
  26.     ygc.tong(xmcx)
  27.     print(ygc)
  28.     print(xmcx)
  29.     print('**************************************')
  30.     xmcx.chiyao()
  31.     print(ygc)
  32.     print(xmcx)
  33.     time.sleep(1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 14:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表