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...

Your biggest problem here is that you (a) are trying to do evergthing at once, (b) cell broad....

You seem to have overlooked that if you have a cell board; in your class definition, then you don't put cell in front of broad to used it. That is because your have already said it is a double array of cells.

e.g.

void minesweeper::displayBoard() 
{
for (int i = 0; i < SIZE; i++)
  for (int j = 0; j < SIZE; j++)
    {
      if (board[i][j].covered == true)
        cout << " ";
      else
        // You need to print something if the cell is NOT covered : 
        cout<<board[i][j].minesAdj;
    }
}

You HAVE to start with something simpler than this because basically, I don't think you understand what a definition is and what a declaration is. Please do something with say a simple class with one integer, and one method, get that to work, and understand how to have 5 different versions.

class A
{  
   int x;
   A();
   void doSomething();
};

int main()
{
   A XX;
   X.doSomething();
   A array[5];
   for(int i=0;i<5;i++)
      array[i].doSomething();
}

Until you are happy with that code, can write a simple constructor and a meaningful doSomething (hopeful, one that writes something out, maybe changes x etc. you are going to struggle.

All coding is about taking small steps to the goal, in your case you have taken one huge step, it is MUCH better to take a step of small steps so that you get one error at a time.

Edited 6 Years Ago by StuXYZ: n/a

Thank you so much for the help and yes i have a lot to learn...im trying and will continue....

Hope to have your help again in the future....have a good night...

This question has already been answered. Start a new discussion instead.