我的迷宫游戏的另一个问题,它有时运行良好,但似乎在一些输入之后游戏停止了?不太清楚这里发生了什么。
import random
from random import randint
print("Welcome to Brandon's Maze Game",
"You have to get 10 shields or find the exit to win",
"Good Luck :D")
counter = 0
shields = 3
fate = randint(1,2)
direction = input("You have come to a stop, do you want to turn Left(L) or Right(R)? ")
if direction == "L":
if fate == 1:
fate = randint(1,2)
shields += 3
counter += 1
direction = input("You came across a chest, you now have " + str(shields) + " shields! What way do you want to go next? Left(L) or Right(R)? ")
if fate == 2:
fate = randint(1,2)
shields -= 1
counter += 1
direction = input("Uh oh, you got attacked and lost a shield, you now have " + str(shields) + " shields. Do you want to go Left(L) or Right(R)? ")
if direction == "R":
if fate == 1:
fate = randint(1,2)
shields += 3
counter += 1
direction = input("You came across a chest, you now have " + str(shields) + "! What way do you want to go next? Left(L) or Right(R)? ")
if fate == 2:
fate = randint(1,2)
shields -= 1
counter += 1
direction = input("Uh oh, you got attacked and lost a shield, you now have " + str(shields) + " shields. Do you want to go Left(L) or Right(R)? ")
if counter >= 5:
print("Congratulations, you made it to the end with " + str(shields) + " shields.")
if shields == 0:
print("You lost all your shields, Game over.")
请尽可能简单地解释一下,我对python来说还是个新手。如果可以,请告诉我正确的代码,但也要解释原因。