Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size = int(input())
- matrix = []
- player_row, player_col = None, None
- total_coins = 0
- path = []
- for row in range(size):
- matrix.append(input().split())
- for col in range(size):
- if matrix[row][col] == 'P':
- player_row, player_col = row, col
- path.append([player_row, player_col])
- while total_coins < 100:
- command = input()
- if command == 'up':
- player_row -= 1
- elif command == 'down':
- player_row += 1
- elif command == 'right':
- player_col += 1
- elif command == 'left':
- player_col -= 1
- if player_col < 0:
- player_col = size - 1
- elif player_col >= size:
- player_col = 0
- if player_row < 0:
- player_row = size - 1
- elif player_row >= size:
- player_row = 0
- path.append([player_row, player_col])
- if matrix[player_row][player_col] == 'X':
- total_coins //= 2
- break
- elif matrix[player_row][player_col].isdigit():
- total_coins += int(matrix[player_row][player_col])
- matrix[player_row][player_col] = '0'
- if total_coins >= 100:
- print(f"""You won! You've collected {total_coins} coins.
- Your path:""")
- print(*path, sep='\n')
- else:
- print(f"""Game over! You've collected {total_coins} coins.
- Your path:""")
- print(*path, sep='\n')
Advertisement
Add Comment
Please, Sign In to add comment