Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This lab is due in 2 days, and I am lost, please help. Creating a 2D array Maze

ID: 3826662 • Letter: T

Question

This lab is due in 2 days, and I am lost, please help.

Creating a 2D array Maze

In this lab, you are going to create a graphical maze based on a file that is read in and stored in a 2D array. First, you must create at least two files that are at least 10x5 of ones and zeros. When your program first starts, it should randomly choose between the two files and then display the maze. Based on the ones and zeros, they should show a block or space. (You should use an image to show a block (e.g. trees, bricks, stones.. your choice!). Then, you should create a character that you can move through the maze. If they run into a block, they should not be able to move. If it is empty, they should be able to move freely.

Specifics: 1. Create a GUI program that has a background of your choice. 2. You should create a 10x5 maze on the background (by using a 2-dimensional array). 3. Generate the maze from a randomly chosen file (You need at least two files). 4. The blocks should be an image. 5. You are to create player image that can be moved based on the keyboard 6. Once they get to the end, they should see a message that says they won.

Extra Credit: Create items that can be collected and increment the score if the player gathers the item (i.e. collides with them). Do not forget to display their score.

Explanation / Answer

This is the whole program for your query. Hope it helps you to cover up all your programming queries and it would get easy for you to complete it by 2 days #include //for output and input: cout #include //for output manipulators #include //for getch() #include //for string using namespace std; //include our own libraries #include "ConsoleUtils.h" //for Clrscr, Gotoxy, etc. //--------------------------------------------------------------------------- //----- define constants //--------------------------------------------------------------------------- //defining the size of the grid const int SIZEY(6); //vertical dimension const int SIZEX(10); //horizontal dimension //defining symbols used for display of the grid & content const char MOUSE('@'); //mouse const char TUNNEL(' '); //tunnel const char WALL('#'); //border //defining the command letters to move the mouse on the maze const int UP(72); //up arrow const int DOWN(80); //down arrow const int RIGHT(77); //right arrow const int LEFT(75); //left arrow //defining the other command letters const char QUIT('Q'); //to end the game struct Item { int x, y; const char symbol; }; //--------------------------------------------------------------------------- //----- run game //--------------------------------------------------------------------------- int main() { //function declarations (prototypes) void initialiseGame(char g[][SIZEX + 1], char m[][SIZEX + 1], Item& mouse); void paintGame(const char g[][SIZEX + 1], string& mess); bool wantsToQuit(int key); bool isArrowKey(int k); int getKeyPress(); void moveMouse(const char g[][SIZEX + 1], Item& mouse, int key, string& mess); void updateGrid(char g[][SIZEX + 1], const char m[][SIZEX + 1], Item mouse); void endProgram(); //local variable declarations char grid[SIZEY + 1][SIZEX + 1]; //grid for display char maze[SIZEY + 1][SIZEX + 1]; //structure of the maze Item mouse = { (SIZEX / 2) + 1, (SIZEY / 2) + 1, MOUSE }; //mouse's position and symbol string message("LET'S START..."); //current message to player //action... Clrscr(); initialiseGame(grid, maze, mouse); //initialise grid (incl. walls & mouse) paintGame(grid, message); //display game info, modified grid & messages int key(getKeyPress()); //read in selected key: arrow or letter command while (!wantsToQuit(key)) //while user does not want to quit { if (isArrowKey(key)) { int dx(0), dy(0); moveMouse(grid, mouse, key, message); //move mouse in that direction updateGrid(grid, maze, mouse); //update grid information } else message = "INVALID KEY!"; //set 'Invalid key' message paintGame(grid, message); //display game info, modified grid & messages key = getKeyPress(); //display menu & read in next option } endProgram(); //display final message return 0; } //--------------------------------------------------------------------------- //----- initialise game state //--------------------------------------------------------------------------- void initialiseGame(char grid[][SIZEX + 1], char maze[][SIZEX + 1], Item& mouse) { //initialise grid & place mouse in middle void setInitialMazeStructure(char g[][SIZEX + 1]); void setInitialMouseCoordinates(Item& mouse); void updateGrid(char g[][SIZEX + 1], const char m[][SIZEX + 1], Item mouse); setInitialMazeStructure(maze); //initialise maze setInitialMouseCoordinates(mouse); //initialise mouse's position updateGrid(grid, maze, mouse); //prepare grid } void setInitialMazeStructure(char maze[][SIZEX + 1]) { //set the position of the walls in the maze //initialise maze configuration char initialMaze[SIZEY + 1][SIZEX + 1] //local array to store the maze structure = { { 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' }, { 'X', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }, { 'X', '#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#' }, { 'X', '#', ' ', ' ', '#', ' ', ' ', '#', ' ', ' ', '#' }, { 'X', '#', ' ', ' ', '#', '#', ' ', '#', ' ', '#', '#' }, { 'X', '#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#' }, { 'X', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' } }; // with '#' for wall, ' ' for tunnel and 'X' for unused part of array //copy into maze structure for (int row(1); row
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote