Ben Chambers
2013-01-20 16:22:19 UTC
Here is my solution to creating the arrays and populating them with random mines (M):
srand(time(NULL));
char displayarray[5][5] = {{'?','?','?','?','?',}, //Declaring grid arrays
{'?','?','?','?','?',},
{'?','?','?','?','?',}, //User will see this array
{'?','?','?','?','?',},
{'?','?','?','?','?',}};
char minearray[5][5] = {{'0','0','0','0','0',},
{'0','0','0','0','0',},
{'0','0','0','0','0',}, //Hidden array for mines
{'0','0','0','0','0',},
{'0','0','0','0','0',}};
int guessedarray[5][5]; //Empty array to store guesses
for(int x=0; x
row = rand ()%5; //Rand statement to generate random numbers
column = rand()%5;
if (minearray[row][column] !='M') //Checking if array location contains a mine (M)
{
minearray[row][column] = 'M'; //If no mine, mine will be placed using random location
}
else x--; //If mine exists, counter decreases so loop can try again
} //Array now populated
or http://pastie.org/5744198
How would I replicate this with vectors or dynamic arrays. And then how do I read user defined locations to check if M exists in that location.
Thanks.