Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- coins = 0
- matrix = []
- step_history = []
- for row in range(n):
- matrix.append([el for el in input().split()])
- for row in range(n):
- for col in range(n):
- if matrix[row][col] == "P":
- start_row = row
- start_col = col
- commands = input()
- while commands:
- if commands == "up":
- row = start_row - 1
- col = start_col
- next_point = matrix[row][col]
- if next_point != "X" or row not in range(n) or col not in range(n):
- coins += int(next_point)
- step_history.append([row, col])
- if coins >= 100:
- print(f"You won! You've collected {coins} coins.")
- break
- break
- else:
- print(f"Game over! You've collected {(coins // 2)} coins.")
- break
- elif commands == "down":
- row = start_row + 1
- col = start_col
- next_point = matrix[row][col]
- if next_point != "X" or row not in range(n) or col not in range(n):
- coins += int(next_point)
- step_history.append([row, col])
- if coins >= 100:
- print(f"You won! You've collected {coins} coins.")
- break
- break
- else:
- print(f"Game over! You've collected {coins // 2} coins.")
- break
- elif commands == "left":
- row = start_row
- col = start_col - 1
- next_point = matrix[row][col]
- if next_point != "X" or row not in range(n) or col not in range(n):
- coins += int(next_point)
- step_history.append([row, col])
- if coins >= 100:
- print(f"You won! You've collected {coins} coins.")
- break
- break
- else:
- print(f"Game over! You've collected {coins // 2} coins.")
- break
- elif commands == "right":
- row = start_row
- col = start_col + 1
- next_point = matrix[row][col]
- if next_point != "X" or row not in range(n) or col not in range(n):
- coins += int(next_point)
- step_history.append([row, col])
- if coins >= 100:
- print(f"You won! You've collected {coins} coins.")
- break
- break
- else:
- print(f"Game over! You've collected {coins // 2} coins.")
- break
- else:
- continue
- start_row = row
- start_col = col
- commands = input()
- print("Your path:")
- for el in step_history:
- print(el)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement