我想測試我對編碼的低估,並試圖學習如何製作基於文本的遊戲。這是我的攻擊階段的文本片段,目前我已調試到第36行,其中我得到一個錯誤,說菜單=輸入(「>>>」)應縮進,我可以得到一些幫助推過去,我不明白爲什麼我收到這個錯誤。基於文本的RPG攻擊階段
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
#basic attack for an rpg text based game
from random import randint
#dice function
def die(sides):
return (randint(1, sides))
# the two object fighting created as lists, later to be used as classes
human = [2, 25, 5]
monster = [1, 20, 2]
#setting the input bar
menu = 0
#attack and defence phase for the game
def attackphase():
while menu != 2:
menu == 0
x = (human[0] + die(20)) - monster[2] #calulations for damage
y = (monster[0] + die(20)) - human[2]
print("You dealt", x, "to the monster")
monster[1] -= x
if monster[1] > 0: #monster returns attack
print("Monster dealt", y, "to you.")
human[1] -= y
else:
print("You killed the monster")
print("Congrats your game works")
menu == 2
if human[1] <= 0: #to end game state
menu == 2
#game state
while menu!= 2:
print("What would you like to do")
print('''1. Attack
2. Quit''')
menu = input(">>>")
if menu == 1:
attackphase()
else:
print("sorry, that has not yet been programed")
print("Wooot, Wooot, Wooot!!!!!!!!!!")
最初的問題解決了,我修改代碼以配合諮詢,目前該遊戲是循環的else語句對不起,還沒有被編程,閹我進入1,2,或任何其他按鍵。
我使用python2和python3都得到很多錯誤,但縮進不是其中之一。 – itdoesntwork