Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <cstdio>
- using namespace std;
- #define SIZE 12
- class maze{
- private:
- int t;
- char a[SIZE][SIZE];
- public:
- maze();
- void printMaze();
- void mazegen();
- };
- maze::maze()
- {
- int t=0;
- }
- void maze::mazegen(){
- srand (time(NULL));
- // initialize '#' to all positions of left-hand wall
- for ( int i = 0; i < SIZE; ++i )
- {
- a[i][0] = '#';
- }
- // initialize '#' to all positions of left-hand wall
- for ( int i = 0; i < SIZE; ++i )
- {
- a[i][SIZE - 1] = '#';
- }
- // initialize '.' to left-hand wall random positions from 1 -> 10
- t = rand() % 11 + 1;
- a[t][0] = '.';
- // initialize '.' to right-hand wall random positions from 1 -> 10
- t = rand() % 11 + 1;
- a[t][SIZE - 1] = '.';
- // intialize '#' to all positions of top maze
- for (int i = 1; i < SIZE - 1; ++i)
- {
- a[0][i] = '#';
- }
- // intialize '#' to all positions of bottom maze
- for (int i = 1; i < SIZE - 1; ++i)
- {
- a[SIZE - 1][i] = '#';
- }
- }
- void maze::printMaze(){
- cout<<"";
- for (int i = 0; i < SIZE; ++i)
- {
- for (int j = 0; j< SIZE; ++j)
- {
- cout<<a[i][j];
- }
- cout<<"";
- }
- cout<<""<<endl;
- }
- int main(void)
- {
- maze m;
- m.mazegen();
- m.printMaze();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement