我正在用 python 开发一个游戏,一旦攻击功能发生,我无法弄清楚如何消除健康。我可以运行程序并且攻击功能运行良好,它显示 1 到 50 之间的随机整数,但实际上并没有从castlehealth= 100 中夺走生命值
在下面 print("You attacked for " + str(self.attack))我将下一行留空,因为我不知道要输入什么,我尝试了很多不同的东西,但无法从castlehealth.
这是我的代码:
import os
import time
from random import randint
class 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()
婷婷同学_
相关分类