Question

Can anyone help me make a simple maze using C++? Not an actual game just a...

Can anyone help me make a simple maze using C++? Not an actual game just a maze. I'm learning the basics of C++ and I'm already stumped. I basically need C++ code to create a simple 32x32 ascii portrait of a maze. Please if anyone is a C++ I need some help thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #0

We assign the maze matrix randomly by using a rand() function to generate random numbers and assign the corresponding character to the element of the maze element.

CODE:-

#include<bits/stdc++.h> //to include all the header files, so that we don't have to include each library separately

using namespace std;

int main()
{
char Maze[32][32]; //Maze is a 32x32 2D matrix that represents the state of the maze at any point in an ascii form (therefore, we use char - character data type)

//Creating the maze can be done using different characters for a way and blockage
// . -> in the matrix represents there is a way
// - -> in the matrix represents there is a blockage

//we run two loops to intialize the maze by the above characters randomly. it is upto the creator that how the maze has to be created and how the paths have to be defined in them.
for(int i=0; i<32; i++)
{
for(int j=0; j<32; j++)
{
//For randomly assigning characters, I am using a threshold, if the generated random number is less than that threshold, then we assign a . to the element else assign -.
//rand() is used to generate random numbers

int x = rand()%32; //generate random numbers from 0 to 31
//Taking threshold to be 16
if(x < 16)
{
//to access an array element, we use the [] operator and thus for two dimensions we will have 2 [] operators used.
Maze[i][j] = '.'; //there is a path
}
else{
Maze[i][j] = '-'; //no path or a blockage
}
}
}

//Printing the maze
for(int i=0; i<32; i++)
{
cout<<"\n"; //newline after every row
for(int j=0; j<32; j++)
{
cout<<setw(2)<<Maze[i][j]; //setting the width of output to be 2 and printing the maze element
}
}
  
return 0;
}

OUTPUT:-


. . . - - - . . . . - . - - . . - . - - - . . . - - . . - - . -
. - . - - - . - . - . - - . - - . - . . - - - - . . - . . - - .
- . - . . . - . - . - - . - . - . - - . . - - - - . - - . - - -
. - - . - - . - - . - . . - - - - - - . . - - - . - . - - . - -
. . - . . . - . . . . - . . . - - . - . - - . . - - - . - . - .
- - . . - - . - . - . - - - . - - . . - . . - - - . . - - - - -
. . - - - . - . - . - - - . . . - - - . - . - - - - . - - . . .
. . . . . - - . - - - - - . - - - - - . . - . - . - - . - . . .
. - - - . . - . - . - - . - . . . - - . . - . - . . . . . - . .
. . - . . - - . - - - . . . - - . . . . - - . . - . . - . - . .
- . - . - . - - - - . . - - - - - - . - - . - . - . - - - . - -
. . . . - - - . . - . - - . - . . - - - - - - - - - . . - - . .
. . . - . . - - . . - - - . - - - - . - . . . - - . . - . - - .
- . . . . - - . . . - - - - . . . - . . - . . - . . . - - . - -
. - . . - . . . . . - . - . . - - . . - - . . - - . - - . . . .
. - - . - . . . . . . - . - - . . - . - . . - - - . - . - . - -
- . . . . . . - . - . - . - . - - . . - - . - . . . . . . . . -
. . . - . - . - . - - - . - . . . - - - - - - . - . . . - . . -
. . - - . . . . - . . . - - . - . - - . . - . . - . . . - . . -
- . . - . - . - . . . - - . - . - . . . - . - - - - . . . - . -
. - - . - - . - . . - . - . . . - - - - - . - - . . . - - . . -
- - . . - - . - . - - - - - . - . . . . . . . - . . . - - - - .
- . - . . - . . . - - . - . . . . . - - - - . - . - - - . - - .
- - . - - . . . . . . - . . . . - - - . . . . . - - - . . - . .
- - . . . . . . . - . - - . - - . - . . - . - - . - - - - . - .
. . . . . - - - . . . . . . - . - . - - - - . - . . . - - . - -
. . - - - - - - - . - - . - . . . . - - - . - - - . - . . . - -
- - - . . . . - . . . - . - - . - - - - - . . . - - - - . . - .
- - . - - - . . - - . - - - - - - - . - . . . - . - - - . - - -
. . - - - . . - - . . - . . . - . . - . - - - - . - . . . . . .
. . - - . . . . - - - - . - - . . . . - . . - - - . - - . . - .
. - . . - . . . . . . . . - . . . - . . - . - . . - - - . - . .

If the answer helped, please upvote!

Add a comment
Know the answer?
Add Answer to:
Can anyone help me make a simple maze using C++? Not an actual game just a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I want to make a really simple maze game in Python. I need to use tkinter and GUI to make this ha...

    I want to make a really simple maze game in Python. I need to use tkinter and GUI to make this happened. Under you can see the description of the task, but i need help to getting startet. If there is an other easier way I'm just happy for the help!! task Description: You have to create a maze game. The goal of the game is to get out of the maze. The game should read The maze from a...

  • Can anyone help me make a simple basic review customer pages in JS? Like the user...

    Can anyone help me make a simple basic review customer pages in JS? Like the user input their name, rate A to F system and comment? I don’t need color or layout or nothing just basic Thank you!

  • Can anyone please help me with these. i've already solved for a just need help on...

    Can anyone please help me with these. i've already solved for a just need help on others In-dass 4-2-20 PE=0] KE=4974 m = 70kg a= S = 120N L a) Speed at bottom of Willis b How much work must to do to I bring sledder to rest "? a Howtar does sledder travel, along flat section, as he comes to rest ? d) Use Newtons 2nd law to find the acceleration of sledder

  • Hi I need help with this problem can anyone please help me and please make it...

    Hi I need help with this problem can anyone please help me and please make it clear with step by step solution and please make it clear to read thank you please make sure the answer is correct thankyou Three forces with magnitudes of 51 pounds, 100 pounds, and 129 pounds act on an object at angles of 30°, 45°, and 120° respectively, with the positive x-axis. Find the direction and magnitude of the resultant force. (Round your answers to...

  • Pls, I need help with these numbers, can anyone help me pls, I will like to...

    Pls, I need help with these numbers, can anyone help me pls, I will like to compare my number just to make sure I'm on the right car.  Current Asset /Current liability THIS MY NUMBER    Current Asset   Current liability 8,306,306 + 6,570,520 / 9,992,136 + 7674 670 do i add them both ? or just 8,306,306/ 9,992,136 = 0.84 which of these is the moving trian I WAS ASK TO COMPUTE        (8,306,306 + 6,570,520) =1,4876,828 / 9,992,136 =1.49

  • Thank you to the ones who have tried to help me and I apologize for having...

    Thank you to the ones who have tried to help me and I apologize for having to repost this question. I'm having a hard time trying to comprehend coding. I am supposed to code a joke and punchline. The joke is:"why did the chicken cross the road?" And the punchline is: "The hen got on its nerves." Or any answer will do actually. I have two labels and one button to make it run. If anyone can help me understand...

  • ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file...

    ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file that contains the maze. Read it into a two-dimensional array Remember you can use inputStream.get(c) to read the next character from the inputStream. This will read whitespace and non-whitespace characters Don’t forget to read the newline character at the end of each line Print the maze to the screen from your array You should include a ‘*’ in your maze to indicate where the...

  • basic stamp 2.0 please what code or what should i look for in creating a code...

    basic stamp 2.0 please what code or what should i look for in creating a code for a cocktail maker with two glasses options to serve basically a code that will allow me to put in the exact amount of drink into a customers desire glass. i already made the actual physical item with some components BUT now i need a code and we are required to use only basic stamp sofware ONLY just provide with code!!! OR what should...

  • I need help finding a curable diseses for my speech class can anyone help me amd...

    I need help finding a curable diseses for my speech class can anyone help me amd list me the disese along with the cures and any helpfull informafion please and thank you

  • i need this in C# please can any one help me out and write the full...

    i need this in C# please can any one help me out and write the full code start from using system till end i am confused and C# is getting me hard.I saw codes from old posts in Chegg but i need the ful complete code please thanks. Module 4 Programming Assignment – OO Design and implementation (50 points) Our Battleship game needs to store a set of ships. Create a new class called Ships. Ships should have the following...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT