viligen

game_of_words

Feb 1st, 2022
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. text = input()
  2. size = int(input())
  3.  
  4. matrix = []
  5. player_row, player_col = None, None
  6. for row in range(size):
  7.     matrix.append(list(input()))
  8.     for col in range(size):
  9.         if matrix[row][col] == "P":
  10.             player_row, player_col = row, col
  11.             break
  12. m = int(input())
  13. for _ in range(m):
  14.     next_row, next_col = player_row, player_col
  15.     command = input()
  16.     if command == 'up':
  17.         next_row -= 1
  18.     elif command == 'down':
  19.         next_row += 1
  20.     elif command == 'left':
  21.         next_col -= 1
  22.     elif command == 'right':
  23.         next_col += 1
  24.     if next_row < 0 or next_col < 0 or next_row >= size or next_col >= size:
  25.         text = text[:-1]
  26.         continue
  27.  
  28.     if matrix[next_row][next_col] != '-':
  29.         text = text + str(matrix[next_row][next_col])
  30.     matrix[player_row][player_col] = '-'
  31.     matrix[next_row][next_col] = 'P'
  32.     player_row, player_col = next_row, next_col
  33.  
  34. print(text)
  35. for row in matrix:
  36.     print(*row, sep='')
  37.  
Advertisement
Add Comment
Please, Sign In to add comment