Skip to content

Commit 4440da9

Browse files
created logic to check user input via grab_direction
1 parent 9fecd21 commit 4440da9

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎src/adv.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@
3838
# Main
3939
#
4040

41+
# list of acceptable inputs for the game
42+
valid_inputs = ["n", "s", "e", "w", "q"]
43+
4144
def grab_direction():
42-
direction = input("\nPlease enter a direction of travel: ")
43-
return direction
45+
direction = input("\nPlease enter a direction of travel: ").lower()
46+
if direction in valid_inputs:
47+
return direction
48+
else:
49+
print("Invalid entry! Please use 'n', 's', 'e' or 'w' to navigate\n Enter 'q' to exit the game")
50+
grab_direction()
4451

4552
print("Welcome to the game!\n")
4653
username = input("Please enter your players name: ")
@@ -60,3 +67,7 @@ def grab_direction():
6067
# Print an error message if the movement isn't allowed.
6168
#
6269
# If the user enters "q", quit the game.
70+
direction = grab_direction()
71+
while (direction != "q"):
72+
print(player.current_room)
73+
direction = grab_direction()

0 commit comments

Comments
 (0)