为了账号安全,请及时绑定邮箱和手机立即绑定

上课时如何拿走生命值?

上课时如何拿走生命值?

慕容708150 2021-10-05 16:13:29
我正在用 python 开发一个游戏,一旦攻击功能发生,我无法弄清楚如何消除健康。我可以运行程序并且攻击功能运行良好,它显示 1 到 50 之间的随机整数,但实际上并没有从castlehealth= 100 中夺走生命值在下面 print("You attacked for " + str(self.attack))我将下一行留空,因为我不知道要输入什么,我尝试了很多不同的东西,但无法从castlehealth.这是我的代码:import osimport timefrom random import randintclass GameActions:    def __init__(self):        castlehealth = 100        self.castlehealth = castlehealth    def health(self):        print("Castle health is: " + str(self.castlehealth))        print()    def attack(self):        attack = randint(0, 50)        self.attack = attack        print("You attacked for " + str(self.attack))def game():    while True:        game_actions = GameActions()        print("What do you want to do?")        print()        print("attack, view hp")        ans = input()        if ans == "hp":            game_actions.health()        if ans == "attack":            game_actions.attack()
查看完整描述

2 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

您需要以下内容:

self.castlehealth -= attack


查看完整回答
反对 回复 2021-10-05
  • 2 回答
  • 0 关注
  • 152 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号