Assignment 5b Maze Game 2d Arrays Can Be Used To Store And Represent Information About Video Game Levels Or Boards In 1 (185.14 KiB) Viewed 37 times
Assignment 5B: Maze Game! 2D Arrays can be used to store and represent information about video game levels or boards. In this exercise, you will use this knowledge to create an interactive game where players attempt to move through a maze. You will start by creating a pre-defined 2D array with the following values: {"_","X","_","X","X"} "X"." ""X","W"} ","X","_"} _","X","X"} {"X","X" You will then set the player (represented by "O") at index 0, 0 of the array, the top-left corner of the maze. You will use a loop to repeatedly prompt the user to enter a direction ("Left", "Right", "Up", or "Down"). Based on these directions, you will try to move the player. ● ● If the location is valid (represented by "_"), you will move the player there If the location is out of bounds (e.g. index 0, -1) or the command is invalid, you will inform the player and prompt them to enter another direction If the location is a wall (represented by "X"), you will tell the user they hit a wall and the game is over. If the player did not lose, you will print out the current state of the map and ask them for a new direction. You will keep doing this until they lose or they reach the end (represented by the "W"). Sample Output #1: [Maze Game] 0.X._.X.X. _.X._.X.W. ___.X._. X.X.___. _._._.X.X. Which direction do you want to move? Up You can't move there - it's out of bounds! Which direction do you want to move? Down _.X._.X.X. 0.X._.X.W. ___.X._. X.X._._._. ___.X.X. Which direction do you want to move? Down _.X._.X.X. _.X._.X.W.
0._._.X._. X.X._._._. _._._.X.X. Which direction do you want to move? Down You hit a wall Game Over! Sample Output #2: [Maze Game] 0.X._.X.X. _.X._.X.W. _._._.X._. X.X.___. _._._.X.X. Which direction do you want to move? Eleventy That's not a valid direction! Which direction do you want to move? Down _.X._.X.X. 0.X._.X.W. ___.X._. X.X.___ ._._.X.X. Which direction do you want to move? Down _.X._.X.X. _.X._.X.W. 0._._.X._. X.X.___ __.X.X. Which direction do you want to move? Right _.X._.X.X. _.X._.X.W. _.O._.X._. X.X._._._. ___.X.X. Which direction do you want to move? Right //Skipping ahead (This line is not part of the output) _.X._.X.X. _.X._.X.W. _._._.X.O. X.X. _._._.X.X. Which direction do you want to move? Up You win!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!