Home > Software design >  I am trying to make a mini game. The movement is in X and Y coordinates that range between -5 and 5
I am trying to make a mini game. The movement is in X and Y coordinates that range between -5 and 5

Time:03-07

#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)
command = input("Enter a command: ")


if command == ("N"):
    y = y   1
elif command == ("E"):
    x = x   1
elif command == ("S"):
    y = y -1   
elif command == ("W"):
    x = x -1
#I want to make a loop so that these commands can be input together so that the goal or hazard is reached.

Can I get help on this? The game is similar to Zork The commands and what I want to do are already listed , and I think that the only thing that is left is trying to fit in into a loop with the ranges [-5, 5] inclusively.

CodePudding user response:

# 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.

  • Related