我正在用 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()
添加回答
舉報
0/150
提交
取消