//****************************************************************************//
//****************************************************************************//
//**** Program Name: Project1 Minesweeper ****//
//**** File: Minesweeper.cpp ****//
//**** Input Files: created by the user ****//
//**** Output Files: None; output is sent to the terminal screen ****//
//**** Modules Used: conio.h ****//
//**** iostream ****//
//**** Purpose: This program was created to make a 3-Dimensional ****//
//**** Minesweeper, that can be up-sized and down-sized ****//
//**** at anytime. ****//
//****************************************************************************// //
//****************************************************************************//
#include <iostream> //For console output
#include <conio.h> //For non-standard screen functions
#include <iostream>
#include <windows.h> // WinApi header
using namespace std;
#define EMPTY_CELL 177
#define CURSOR 1
#define TAIL 219
#define NUM 6
class Room {
private:
bool visited;
bool active;
public:
Room(); // Default Constructor
Room(bool vis, bool act); // Overloaded Constructor
Room(const Room& node); // Copy Constructor
Room& operator= (const Room& node); // Operator
~Room(); // Destructor/Destroyer
//Mutators
void setActive (); // Gets console ready to draw minesweeper grid
char draw; // Draws the grid for minesweeper
};
Room::Room () {
this->visited = false;
this->active = false;
}
Room::Room (bool visited, bool active) {
this->visited = visited;
this->active = active;
}
Room::Room (const Room& node) {
this->visited = node.visited;
this->active = node.active;
}
Room& Room (const Room& node) {
this->visited = node.visited;
this->active = node.active;
return *this;
}
void Room::setActive () {
this->visited = true;
this->active = true;
}
char Room::draw () {
char ch = char (EMPTY_CELL);
if (visited) {
ch = char (TAIL);
}
if (this-> active) {
ch = char (CURSOR);
this-> active = false;
}
return ch;
}
Room::~Room () {
}
/*******************************************************************************/
/*******************************************************************************/
#define LEFT_UPPER_CORNER 201
#define VERTICAL_LINE 186
#define HORIZONTAL_LINE 205
#define RIGHT_UPPER_CORNER 187
#define LEFT_LOWER_CORNER 200
#define RIGHT_LOWER_CORNER 188
#define INTERSECTION 206
#define VERTICAL_WITH_RIGHT_TURN 204
#define VERTICAL_WITH_LEFT_TURN 185
#define HORIZONTAL_WITH_DOWN_LINE 203
#define HORIZONTAL_WITH_UP_LINE 202
#define RROW 11;
#define RCOL 11;
class Dynamic3DArray {
protected:
int ROW;
int COL;
int DEPTH;
Room *** array;
public;
Dynamic3DArray (); // Default Consturtor
Dynamic3DArray (int row, int col, int depth); // Overloaded Con.
Dynamic3DArray (const Dynamic3DArray& dynamic3DArray);
Dynamic3DArray& operator= (const Dynamic3DArray& dynamic3DArray); //Assignment Operator
~Dynamic3DArray (); //Destroyer/Destructor
//Accessors
int getROW (); //Gets the number of rows
int getCOL (); //Gets the number of columns
int getDEPTH (); //Gets the number for the depth
//Mutators
void create (); //Will create a 3Dimentional grid
void destroy (); //Destroys the grid to free memory
void setActive (int x, int y, int z); //Will make the cells visited
bool setDimentions (); //Will set the dimentions of the grid
void resize (int x, int y, int z); //change the dimentions of the grid
void print (int depth); //prints the grid with the depth given by user
void printDimentions (intx, int y, int z); //This prints the overall grid
};
Dynamic3DArray::Dynamic3DArray () {
this-> ROW = 0;
this-> COL = 0;
this-> DEPTH = 0;
array = NULL;
}
void Dynamic3DArray::create () {
array = new Room** [ROW];
for (int r=0; r<ROW; r++) {
array[r] = new Room* [COL];
for (int c=0; c<COL; c++)
array[r][c] = new Room[DEPTH];
}
}
void Dynamic3DArray::destroy () {
for (int r=0; r<Row; r++) {
for (int c=0; c<COL; c++)
delete [] array [r][c];
delete [] array [r];
}
delete [] array;
}
Dynamic3DArray::Dynamic3DArray (int row, int col, int depth) {
this-> ROW = row;
this-> COL = col;
this-> DEPTH = depth;
create ();
}
Dynamic3DArray::Dynamic3DArray (const Dynamic3DArray& dynamic3DArray) {
this-> ROW = dynamic3DArray.ROW;
this-> COL = dynamic3DArray.COL;
this-> DEPTH = dynamic3DArray.DEPTH;
create ();
}
void Dynamic3DArray:: setActive (intx, int y, int z) {
this-> array[x-1][y-1][z-1].setActive ();
}
void Dynamic3DArray::printDimentions (int x, int y, int z) {
cout << " < " << x << "," << y << "," << z << ">" << endl << endl;
}
void Dynamic3DArray::resize (int r, int c, int d) {
Dynamic3DArray temp (*this);
temp = *this;
this-> destroy ();
this-> ROW = r;
this-> COL = c;
this-> DEPTH = d;
this-> create ();
if (temp.ROW<ROW) {
for (int r=0; r<temp.ROW; r++) {
for (int c=0; c<temp.COL; c++) {
for (int d=0; d<temp.DEPTH; d++)
this->array[r+1][c+1][d+1]=temp.array[r][c][d];
}
}
}
}
else
for (int r=0; r<ROW; r++) {
for (int c=0; c<COL; c++) {
for (int d=0; d<DEPTH; d++)
this->array[r][c][d]=temp.array[r+1][c+1][d+1];
}
}
}
int Dynamic3DArray::getROW () {
return this-> ROW;
}
int Dynamic3DArray::getCOL () {
return this-> COL;
}
int Dynamic3DArray::getDep () {
return this->DEPTH;
}
Dynamic3DArray::~Dynamic3DArray () {
destroy ();
}
Dynamic3DArray& Dynamic3DArray::operator=(const Dynamic3DArray& dynamic3DArray) {
destroy ();
this->ROW = dynamic3DArray.ROW;
this->COL = dynamic3DArray.COL;
this->DEPTH = dynamic3DArray.DEPTH;
create ();
for (int r=0; r<ROW; r++) {
for (int c=0; c<COL; c++) {
for (int d=0; d<DEPTH; d++)
array[r][c][d]=dynamic3DArray.array[r][c][d];
}
}
return *this;
}
void Dynamic3DArray::print (int depth) {
system ("cls");
cout << char (LEFT_UPPER_CORNER);
for (int r=0; r<ROW; r++) {
cout << char (HORIZONTAL_LINE) << char (HORIZONTAL_WITH_DOWN_LINE);
}
cout << "\b" << char (RIGHT_UPPER_CORNER) << endl;
for (int c=0; c<COL; c++) {
cout << char (VERTICAL_LINE);
for (int r=0; r<ROW; r++) {
cout << array[r][c][depth-1].draw() << char (VERTICAL_LINE);
}
cout << "\b" << char (VERTICAL_WITH_RIGHT_TURN);
if (c< (COL-1)) {
for (int i=0; i<ROW; i++) {
cout << char (HORIZONTAL_LINE) << char (INTERSECTION);
}
cout << "\b" << char (VERTICAL_WITH_LEFT_TURN) << "\n";
}
else {
cout << "\b" << char (LEFT_LOWER_CORNER);
for (int r=0; r<ROW; r++) {
cout << char (HORIZONTAL_LINE) << char (HORIZONTAL_WITH_UP_LINE);
}
}
}
cout << "\b" << char (RIGHT_LOWER_CORNER) << "\n";
}
/****************************************************************************************/
/****************************************************************************************/
#define MIN_COL 2 //minimum size allowed for number of columns
#define MIN_ROW 2 //minimum size allowed for number of rows
#define MIN_DEPTH 2 //minimum size allowed for the depth
#define MAX_COL 12 //maximum size allowed for number of columns
#define MAX_ROW 12 //maximum size allowed for number of rows
#define MAX_DEPTH 12//maximum size allowed for the depth
#define RROW 11;
#define RCOL 11;
class GridActive:Dynamic3DArray {
private:
int x;
int y;
int z;
public:
GridActive ();
GridActive ( int R, int C, int D);
GridActive (const GridActive & grid);
~GridActive ();
//Accessors
bool goNorth ();
bool goSouth ();
bool goWest ();
bool goEast ();
bool goUp ();
bool goDown ();
int getRow ();
int getCol ();
int getDepth ();
int getX ();
int getY ();
int getZ ();
//Mutators
void upsize ();
void downsize ();
void setActive ();
void printDimentions (int x, int y, int z);
void print (int dep);
};
GridActive::GridActive ():Dynamic3DArray () {
x=0;
y=0;
z=0;
}
GridActive::GridActive (int R, int C, int D):Dynamic3DArray (R, C, D) {
x=1;
y=1;
z=1;
}
GridActive::~GridActive () {
}
GridActive::GridActive (const GridActive & grid):Dynamic3DArray(grid) {
}
GridActive& GridActive::operator= (const GridActive & grid) {
destroy ();
this->x = grid.x;
this->y = grid.y;
this->z = grid.z;
this->ROW = grid.ROW;
this->COL = grid.COL;
this->DEPTH = grid.DEPTH;
create ();
for (int r=0; r<ROW; r++) {
for (int c=0;, c<COL; c++) {
for (int d=0; d<DEPTH; d++)
array[r][c][d]=grid.array[r][c][d];
}
}
return *this;
}
bool GridActive::goNorth () {
for (y == 1) return false;
y--;
return true;
}
bool GridActive::goSouth () {
if (y == COL) return false;
y++;
return true;
}
bool GridActive::goDown () {
if (z == 1) return false;
z--;
return true;
}
bool GridActive::goUp () {
if (z == DEPTH) return false;
z++;
return true;
}
bool GridActive::goEast () {
if (x == ROW) return false;
x++;
return true;
}
bool GridActive::goWest () {
if (x == 1) return false;
x--;
return true;
}
int GridActive::getROW () {
return ROW;
}
int GridActive::getCol () {
return COl;
}
int GridActive::getDEPTH () {
return DEPTH;
}
void GridActive::print (int dep) {
Dynamic3DArray::print (dep)
}
int GridActive::getX () {
return x;
}
int GridActive::getY () {
return y;
}
int GridActive::getZ () {
return z;
}
void GridActive::setActive (int x, int y, int z) {
Dynamic3DArray::setActive (x, y, z);
}
void GridActive::printDimentions (int x, int y, int z) {
Dynamic3DArray::printDimentions (x, y, z);
}
void GridActive::upsize() {
if ((ROW< MAX_ROW-2) && (COL<MAX_COL-2) && (DEPTH< MAX_DEPTH-2)) {
resize (this->ROW+2, this->COL+2, this->DEPTH+2);
x++;
y++;
z++;
}
}
void GridActive::downsize () {
if (ROW>MIN_ROW && COL>MIN_COL && DEPTH>MIN_DEPTH &&
this->x != this->y !=1 && this->z !=1 &&
this->x != this->ROW && this->y != this->COL && this->z !=DEPTH) {
resize (this->ROW-2, this->COL-2, this->DEPTH-2);
x--;
y--;
z--;
}
}
void printEnd() {
system ("cls");
cout << "XXXXXXXXXXX_XX_____XX_____XXX_____XXXX______XX_XXX____XXX______XXX______XXX____XXXXX_____XXX_____XXX_______" << endl;
cout << "XXXXXXXXXXX_XX_____XX____XXXXX____XXXXX_____XX_XXX___XXX_______XXX____XXX____XXX___XXX___XXX_____XXX_______" << endl;
cout << "_____XX_____XX_____XX___XXX_XXX___XX_XXX____XX_XXX__XXX________XXX__XXX____XXX______XXX__XXX_____XXX_______" << endl;
cout << "_____XX_____XXXXXXXXX__XXX___XXX__XX__XXX___XX_XXXXXXX_________XXXXX_____XXX_________XXX_XXX_____XXX_______" << endl;
cout << "_____XX_____XXXXXXXXX__XXXXXXXXX__XX___XXX__XX_XXXXXXX_________XXXX______XXX_________XXX_XXX_____XXX_______" << endl;
cout << "_____XX_____XX_____XX_XXXXXXXXXXX_XX____XXX_XX_XXX__XXX________XXX_________XXX_____XXX___XXX_____XXX_______" << endl;
cout << "_____XX_____XX_____XX_XXX_____XXX_XX_____XXXXX_XXX___XXX_______XXX__________XXX___XXX_____XXX___XXX________" << endl;
cout << "_____XX_____XX_____XX_XXX_____XXX_XX______XXXX_XXX____XXX______XXX____________XXXXX_________XXXXXX_________" << endl;
cout << "___________________________________________________________________________________________________________" << endl:
cout << "XXXXXXXXX____XXXXX______XXXXXXX_______XXXXXXX____XX__________X_____XX_____XXX_XX_XXX_______XX______XXXXXX__" << endl;
cout << "XXXXXXXXX__XXX___XXX____XXXXXXXX______XX___XXXX__XX_________XXX____XX___XXX___XX_XXXX______XX____XXXX___XX_" << endl;
cout << "XX________XXX_____XXX___XX____XXX_____XX______XX_XX________XXXXX___XX_XXX_____XX_XX_XX_____XX__XXXX________" << endl;
cout << "XXXXX___XXX_________XXX_XX XXX______XX____XXX__XX_______XX__XXX__XXXX_______XX_XX__XX____XX_XX___________" << endl;
cout << "XXXXX___XXX_________XXX_XXXXXXX_______XXXXXX_____XX_______XXXXXXX__XXX________XX_XX___XX___XX_XX______XXXXX" << endl;
cout << "XX________XXX_____XXX___XX__XXX_______XX_________XX______XXXXXXXXX_XXX________XX_XX____XX__XX__XXXX_____XXX" << endl;
cout << "XX_________XXX___XXX____XX___XXX______XX_________XXXXXXX_XX____XXX_XXX________XX_XX_____XXXXX____XXXXXXXXX_" << endl;
cout << "XX__________XXXXX_______XX____XXX_____XX_________XXXXXXX_XX____XXX_XXX________XX_XX______XXXX______XXXXX___" << endl;
}
void main () {
char keyPressed;
bool quit = false;
int dX;
int dY;
int dZ;
do {
system("cls");
cout <<endl;
cout <<endl;
cout <<"xxxx___xxxx__xx__xxx____xxx__xxxxxx___xxxxxx___xxx___________xxx__xxxxxx__xxxxxx__xxxxx_____xxxxxx__xxxxxx__" << endl;
cout <<"xxxx___xxxx__xx__xxxx___xxx__xxxxxx__xxxxxxxx__xxx___________xxx__xxxxxx__xxxxxx__xxxxxxx___xxxxxx__xxxxxxx_"<< endl;
cout <<"xxxxx_xxxxx__xx__xxxx___xxx__xx______xxx__xxx__xxx___________xxx__xx______xx______xx___xxx__xx______xx___xx_"<< endl;
cout <<"xxx_xxx_xxx__xx__xxxxx__xxx__xx______xxx________xxx_________xxx___xx______xx______xx___xxx__xx______xx___xx_"<< endl;
cout <<"xxx_xxx_xxx__xx__xxx_xx_xxx__xxxxx____xxx_______xxx____x____xxx___xxxxx___xxxxx___xxxxxxx___xxxxx___xxxxxx__"<< endl;
cout <<"xxx__x__xxx__xx__xxx__xxxxx__xxxxx______xxx______xxx___x___xxx____xxxxx___xxxxx___xxx_______xxxxx___xxxx____"<< endl;
cout <<"xxx_____xxx__xx__xxx__xxxxx__xx___________xxx____xxx__xxx__xxx____xx______xx______xx________xx______xx_xx___"<< endl;
cout <<"xxx_____xxx__xx__xxx___xxxx__xx______xxx__xxx_____xxxx___xxxx_____xx______xx______xx________xx______xx__xx__"<< endl;
cout <<"xxx_____xxx__xx__xxx____xxx__xxxxxx__xxxxxxxx_____xxx_____xxx_____xxxxxx__xxxxxx__xx________xxxxxx__xx__xx__"<< endl;
cout <<"xxx_____xxx__xx__xxx____xxx__xxxxxx___xxxxxx______xxx_____xxx_____xxxxxx__xxxxxx__xx________xxxxxx__xx__xx__"<< endl;
cout << endl << endl << endl;
system("pause");
int main() {
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(k = 1; k < 2; k++) {
SetConsoleTextAttribute(hConsole, 26);
cout <<"You may use the ESC button to quit MINESWEEPER anytime you wish" << endl;
cout <<"The arrow buttons on your keyboard will be used to move your player around" << endl;
cout <<"The buttons < and > will be used to go up and down levels" << endl;
cout <<"The buttons = or - will be used to increse or decrease the size of your game" << endl;
system("pause");
cout << "Enter the number of rows you would like to have" << endl;
cin >> dX;
while (dX > MAX_ROW) {
cout << "Please re-enter the number of rows you would like that is less than your previous entry" << endl;
cin >> dX;
}
while (dX < MIN_ROW) {
cout << "Please re-enter the number of rows you would like that is greater than your previous entry" << endl;
cin << dX;
}
cout << "Enter the number of columns you would like to have" << endl;
cin >> dY;
while (dY > MAX_COL) {
cout << "Please re-enter the number of columns you would like that is less than your previous entry" << endl;
cin >> dY;
}
while (dY < MIN_COL) {
cout << "Please re-enter the number of columns you would like that is greater than your previous entry" << endl;
cin >> dY;
}
cout << "Enter the depth you would like to have" << endl;
cin >> dZ;
while (dZ > MAX_DEPTH) {
cout << "Please re-enter the depth you would like that is less than your previous entry" << endl;
cin >> dZ;
}
while (dZ < MIN_DEPTH) {
cout << "Please re-enter the depth you would like that is greater than your previous entry" << endl;
cin >> dZ;
}
GridActive myGridActive (dX, dY, dZ);
do{
myGridActive.setActive ( myGridActive.getX(), myGridActive.getY(), myGridActive.getZ());
myGridActive.print (myGridActive.getZ());
myGridActive.printDimensions ( myGridActive.getX(), myGridActive.getY(), myGridActive.getZ() );
myGridActive.printDimensions ( myGridActive.getROW(), myGridActive.getCOL(), myGridActive.getDEPTH() );
keyPressed = toascii ( getch() );
switch (keyPressed) {
case 27 : quit = true; break;
case 44 : myGridActive.goDown (); break;
case 46 : myGridActive.goUp (); break;
case 61 : myGridActive.upsize (); break;
case 99 : system ("cls"); break;
case 45 : myGridActive.downsize (); break;
case 96 : {
keyPressed = toascii (getch() );
switch (keyPressed) {
case 72 : myGridActive.goNorth (); break;
case 80 : myGridActive.goSouth (); break;
case 75 : myGridActive.goWest (); break;
case 77 : myGridActive.goEast (); break;
default: break;
}
default: break:
}
}
}
while (!quit);
cout << "\n Would you like to start over? Press any key \n Would you like to quit? Press N ";
keyPressed = getch ();
quit = false;
if (( keyPressed == 'N' ) || (keyPressed == 'n' ))
quit = true;
}
}
cin.get(); // wait
return 0;
}
while (!quit);
printEnd();
}