



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solution description available
Typology: Schemes and Mind Maps
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Step 1 of 3
Step 3 of 3
1 def look_around(position, grid): 2 """ 3 Function to check the surroundings and return information about nearby tiles. 4 5 Parameters: 6 - position: List [x, y] representing the current position of the player. 7 - grid: 2D list representing the dungeon map. 8 9 Returns: 10 - A string describing the nearby tiles. 11 """ 12 x, y = position 13 # Implement logic to check the surrounding tiles based on the player's position (x, y) and the grid. 14 # You can check the neighboring tiles and return information about them. 15 # For example, you might check if the next position is valid for movement. 16 pass 17 18 def move(direction, position, grid): 19 """ 20 Function to move the player in the specified direction. 21 22 Parameters: 23 - direction: String representing the direction to move ('north', 'south', 'west', 'east'). 24 - position: List [x, y] representing the current position of the player. 25 - grid: 2D list representing the dungeon map. 26 27 Returns: 28 - True if the move is successful, False otherwise. 29 """ 30 # Call look_around function to check if the move is valid. 31 surroundings = look_around(position, grid) 32 33 # Check if the desired direction is allowed based on surroundings. 34 if direction in surroundings: 35 # Update the player's position based on the direction. 36 if direction == 'north': 37 position[1] -= 1 38 elif direction == 'south': 39 position[1] += 1 40 elif direction == 'west': 41 position[0] -= 1 42 elif direction == 'east': 43 position[0] += 1 44 return True 45 else: 46 return False 47 48 def main(): 49 """ 50 Main entry point for the game. 51 """ 52 # Initialize grid and player position 53 grid = [ 54 ["", "", "e", "-"], 55 ["", ".", ".", "+", "."], 56 ["", "", "", "-"], 57 [".", ".", ".", "", ""] 58 ] 59 player_position = [0, 2] 60 61 while True: 62 command = input("> ").lower() 63 64 if command == 'escape': 65 print("Game over. Goodbye!") 66 break 67 elif command == 'show map': 68 display_map(grid) 69 elif command.startswith('go '): 70 direction = command[3:] 71 success = move(direction, player_position, grid) 72 if success: 73 print("You moved.") 74 display_map(grid) # Optional: Display the map after moving. 75 else: 76 print("There is no way there.") 77 else: 78 print("Invalid command. Try again.") 79 80 def display_map(grid): 81 """ 82 Displays the current state of the map. 83 84 Parameters: 85 - grid: 2D list representing the dungeon map. 86 """ 87 for row in grid: 88 print(' '.join(row)) 89 90 if name == "main": 91 main()