私信  •  关注

Carl_M

Carl_M 最近回复了
# The Commands are going North and South in the Y - variable and East and West in the X - variable and X - to exit the game
x = 0
y = 0
print("Welcome to sloth quest!")
print("________________________________________")
print()

print("You're currently at position (0, 0) in the world.")
print(
    "Available commands: N - go north, S - go south, E - go east, W - go west, X - exit game")
while True: # run untill the user enters X
    # limit play area to -5 x 5
    command = input("Enter a command: ")
    command = command.upper() # Ensure user input is upper case
    if command == ("N"):
        y = y + 1
    elif command == ("E"):
        x = x + 1
    elif command == ("S"):
        y = y - 1
    elif command == ("W"):
        x = x - 1
    elif command == 'X': # Exit the loop
         break
    if x < -5 or x > 5 or y < -5 or y > 5:
        # What should happen?
        print("error you have left the play area")
print('Thanks for playing') # Exit the game.
# I want to make a loop so that these commands can be input together so that the goal or hazard is reached.