This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
100 lines (68 loc) · 2.54 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <time.h>
#include <fstream>
#include "stdafx.h"
#include "maze.h"
const int PRODUCT_LIMIT = 1600;
int main() {
rlutil::setColor(15);//Sets color to white
std::ofstream myMaze("Maze.txt");
StreambufDoubler doubler(std::cout.rdbuf(), myMaze.rdbuf());
std::cout.rdbuf(&doubler);
srand(clock());
int sizeX, sizeY;
cout << "Dimensions of the maze (width x height): \n"
<< "Quick note: For higher values for 'width' the maze will not appear as it should on the cmd"
<< "(ex.: 80 x 20).\n";
cout << "THE PRODUCT OF THE WIDTH AND HEIGHT OF THE MAZE SHOULD NOT BE 1600 OR MORE!!!!\n";
cout << "Enter the dimensions of the maze (width & height):\t";
cin >> sizeX >> sizeY;
//The PRODUCT_LIMIT should NOT be equal or more than 1600!!!
if (sizeX * sizeY < PRODUCT_LIMIT) {
cout << "\n\n";
cout << "A maze with dimensions: " <<
"width = " << sizeX << " and height = " << sizeY << endl;
Maze maze(sizeX, sizeY);
maze.generateMaze();
maze.printMaze(false);
cout << "\n\n";
cout << "THE MAZE WAS SAVED IN A .TXT FILE.\nEven if the maze is 80 x 20 you should not have problem"
<<" with zooming out on Notepad.\n\n";
myMaze.close();
int entranceX, entranceY, exitX, exitY;
cout << endl << "Enter the entrance coordinates (X: 0-" << sizeX - 1
<< " & Y: 0-" << sizeY - 1 << "): ";
cin >> entranceX >> entranceY;
maze.setEntrance(entranceX, entranceY);
cout << "Enter the exit coordinates (X: 0-" << sizeX - 1
<< " & Y: 0-" << sizeY - 1 << "): ";
cin >> exitX >> exitY;
maze.setExit(exitX, exitY);
cout << "\n\n";
myMaze.open("Maze.txt", std::ios_base::app); // append instead of overwrite
myMaze << "Starting point: (" << entranceX << ", " << entranceY << ")\n";
myMaze << "Exit point: (" << exitX << ", " << exitY << ")\n\n\n";
myMaze.close();
myMaze << "Starting point: (" << entranceX << ", " << entranceY << ")\n";
myMaze << "Exit point: (" << exitX << ", " << exitY << ")\n\n\n";
cout << "Do you want the program to solve it for you? ('Y', 'y', 'N' or 'n')\n";
char input;
cin >> input;
if (input == 'Y' || input == 'y') {
rlutil::setColor(8);//Sets color to dark grey
std::ofstream solutionFile("Solution.txt");
StreambufDoubler doublerS(std::cout.rdbuf(), solutionFile.rdbuf());
std::cout.rdbuf(&doublerS);
maze.solveMaze();
maze.printMaze(true);
solutionFile.close();
rlutil::setColor(15);//Sets color back to normal
solutionFile.close();
cout << "\n\n";
cout << "THE SOLUTION WAS SAVED IN A .TXT FILE.\n\n";
}
}
else{
return -1;
}
return 0;
}