I need help...This is the class i am supposed to use...
#ifndef_MINESWEEPER_H
#define_MINESWEEPER_H
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int SIZE = 3;
class minesweeper
{
public:
minesweeper();
minesweeper(int mines);
void resetGame();
int flagCell(int x, int y);
void unflagCell(int x, int y);
int uncoverCell(int x, int y);
void displayBoard();
void revealBoard();
private:
struct cell
{
bool mine;
bool covered;
int minesAdj;
bool flagged;
};
cell board[SIZE][SIZE];
int mineCount;
int checkEndOfGame();
void clearAround(int i, int j);
};
#endif
This is my member functions still in the making....
#include"minesweeper.h"
minesweeper::minesweeper()
{
mineCount = 1;
}
minesweeper::minesweeper(int mines)
{
mineCount = mines;
}
void minesweeper::resetGame()
{
for (int i=0; i < SIZE; i++)
{
for (int j=0; j < SIZE; j++)
{
cell board[i][j] = cell myCell;
unflagCell(i,j);
}
}
//srand(time(NULL));
srand(3);
myRandom = rand()%10;
switch (myRandom)
{
case 0:
i = 0;
j = 0;
break;
case 1:
i = 0;
j = 1;
break;
case 2:
i = 0;
j = 2;
break;
case 3:
i = 1;
j = 0;
break;
case 4:
i = 1;
j = 1;
break;
case 5:
i = 1;
j = 2;
break;
case 6:
i = 2;
j = 0;
break;
case 7:
i = 2;
j = 1;
break;
case 8:
i = 2;
j = 2;
break;
}
flagCell(i,j);
}
int minesweeper::flagCell(int x, int y)
{
cell board[x][y].myCell.mine = true;
cell board[x][y].myCell.covered = true;
cell board[x][y].mycell.flagged = true;
for (int i = x - 1; i < i + 3; i++)
{
for (int j = y - 1; j < j + 3; j++)
{
if (i != x && j != y)
{
if (i < SIZE && j < SIZE)
{
cell board[i][j].myCell.minesAdj++;
}
}
}
}
}
void minesweeper::unflagCell(int x, int y)
{
cell board[x][y].myCell.mine = false;
cell board[x][y].myCell.covered = true;
cell board[x][y].myCell.minesAdj = 0;
cell board[x][y].mycell.flagged = false;
}
int minesweeper::uncoverCell(int x, int y)
{
cell board[x][y].myCell.covered = false;
}
void minesweeper::displayBoard()
{
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
{
cell board[i][j].myCell.covered = true;
cout << cell board[i][j] << " ";
}
}
}
void minesweeper::revealBoard()
{
}
My problem at the moment is with displayboard()...its not complete and im stuck....can someone help? This is my first time here and im kinda nervous...
Thanks in advance...i don't even know if i posted this correctly...