Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. N = '(N)orth'
  2. S = '(S)outh'
  3. E = '(E)ast'
  4. W = '(W)est'
  5.  
  6.  
  7. def moving(col: int, row: int, direction: str)->int:
  8. ''' Take in current position and return a new position'''
  9.  
  10. if direction.lower() == 'n':
  11. row += 1
  12. elif direction.lower() == 's':
  13. row -= 1
  14. elif direction.lower() == 'e':
  15. col += 1
  16. elif direction.lower() == 'w':
  17. col -= 1
  18. return col, row
  19.  
  20.  
  21. def play(victory, direction, acceptable_moves, col, row):
  22. ''' Main game '''
  23. while not victory: # main loop
  24. if direction in acceptable_moves:
  25. if ((col == 1) and (row == 1)) or ((col == 2) and (row == 1)): # (1,1) / (2,1)
  26. print(f"You can travel: {N}.")
  27. acceptable_moves = ('n')
  28. elif (col == 1) and (row == 2): # (1,2)
  29. print(f"You can travel: {N} or {E} or {S}.")
  30. acceptable_moves = ('n', 'e', 's')
  31. elif (col == 1) and (row == 3): # (1,3)
  32. print(f"You can travel: {E} or {S}.")
  33. acceptable_moves = ('e', 's')
  34. elif (col == 2) and (row == 2): # (2,2)
  35. print(f"You can travel: {S} or {W}.")
  36. acceptable_moves = ('s', 'w')
  37. elif (col == 3) and (row == 3): # (3,3)
  38. print(f"You can travel: {S} or {W}.")
  39. acceptable_moves = ('s', 'w')
  40. elif (col == 2) and (row == 3): # (2,3 )
  41. print(f"You can travel: {E} or {W}.")
  42. acceptable_moves = ('e', 'w')
  43. elif (col == 3) and (row == 2): # (3,2)
  44. print(f"You can travel: {N} or {S}.")
  45. acceptable_moves = ('n', 's')
  46. elif col == 3 and row == 1: # (3,1) - Win condition
  47. print('Victory!')
  48. break
  49. direction = str(input("Direction: "))
  50. direction = direction.lower()
  51. if direction in acceptable_moves:
  52. col, row = moving(col, row, direction) # Function call
  53. else:
  54. print('Not a valid direction!')
  55.  
  56.  
  57. col, row = 1, 1
  58. acceptable_moves = ('')
  59. direction = ''
  60. victory = False
  61.  
  62.  
  63. play(victory, direction, acceptable_moves, col, row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement