quhluh icon

Python code snippet that simulates walking in a grid-like environment

quhluh | 12/04/24 02:12:16 AM UTC | 0 ⭐ | 412 👁️ | Never ⏰ | []
Python |

940 B

|

None

|

0 👍

/

0 👎

# Simple Walking Simulation
def display_position(x, y):
    print(f"Current Position: ({x}, {y})")
 
def main():
    print("Welcome to the Walking Simulator!")
    print("Use W (up), A (left), S (down), D (right) to move. Type 'quit' to exit.")
    
    # Starting position
    x, y = 0, 0
    display_position(x, y)
    
    while True:
        # Get user input
        move = input("Move (W/A/S/D): ").lower()
        
        if move == "w":
            y += 1
        elif move == "a":
            x -= 1
        elif move == "s":
            y -= 1
        elif move == "d":
            x += 1
        elif move == "quit":
            print("Exiting Walking Simulator. Goodbye!")
            break
        else:
            print("Invalid input! Use W, A, S, D to move or 'quit' to exit.")
            continue
        
        # Display new position
        display_position(x, y)
 
if __name__ == "__main__":
    main()

Comments