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 101
|
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
const int ROWS = 5; // a constant of row
const int COLS = 5; // a constant of column. I don't want the board to be more than 5 X 5
//enum to represent every possible value in the board.
enum Symbols {STAR = 42, AT = 64, X = 88, ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
//Function to cout basic info (Rules, names etc..)
void info();
void initPosition(Symbols symbolArr[][COLS], int size);
bool checkMine(Symbols symbolArr[][COLS], int size);
/*
display the initial board showing the initial values (i.e., ‘*’ (STAR)) and
randomly placed mines (i.e., ‘@’(AT)) using a function, passing in the two-dimensional array
and the size. This function will display the row and column headers for the board as well
as the board itself. Note that since this two-dimensional array is an
enumerated data type, I will have to map the enum value to the representative
character that is to be displayed on the board.
*/void displayBoard(Symbols symbolArr[][COLS], int size);
int main()
{
int mines;
Symbols symbolArr[][COLS] = {STAR, AT, X, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
do
{
cout << "Enter The Numbers of Mines Between 5 and 10: ";
cin >> mines;
}while(mines <= 4 || mines >=11);
initPosition(symbolArr, ROWS);
checkMine(symbolArr, mines);
displayBoard(symbolArr, ROWS);
return 0;
}
void initPosition(Symbols symbolArr[][COLS], int size)
// This function will simply initialize each position on the board to the enumerated type representing the initial value, which is the character ‘*’ (or STAR)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < COLS; j++)
{
//I need help here. I want to initalize this function to fill this array with enum star.
}
cout << endl;
}
}
bool checkMine(Symbols symbolArr[][COLS], int size) // This function randomly selects arrays to place mines
{
srand(time(NULL)); //Random Number generator
for (int mines_placed = 0; mines_placed < size;)
{
int row = rand() % size;
int col = rand() % size;
if (symbolArr[row][col] != AT)
{
symbolArr[row][col] = AT;
mines_placed++;
}
else
{
return false;
}
}
return true;
}
void displayBoard(Symbols symbolArr[][COLS], int size) // This function displays the board.
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < COLS; j++)
{
cout <<(symbolArr[i][j]) << ""; // I need help here too (I think)
}
cout << endl;
}
return;
}
| |