Right I have managed to get it to show a board with the help from AbR, the only problem is that the board is filled in with loads of random numbers. |
Supposedly these aren't random numbers, but the number of columns and rows (ie column 4, row 3 is displayed as '32' (because the first position og both columns and rows is 0 (zero)))
How do I go about changing all these numbers to say all X's? |
My suggestion (and there may be smarter ways to do this) is to make two two-dimensional arrays:
gameboard[width][height] (which shows what the player can see) and
masterboard[width][height] (which holds the actual positions of the bombs. I use width and height instead of specific values, so you can use the same code, no matter what difficulty the game is played at (width, height and number of mines can be passed from the menu to the game function as parameters). I'm making some example code for you, but it is at home on my computer and right now I'm at work.
Using a slightly modified version of the double loop I posted earlier, you can fill the arrays with dots or something:
1 2 3 4 5 6
|
for (rows=0; rows<height; rows++) {
for (columns=0; columns<width; columns++) {
gameboard[colums][rows]=(char)0xFA; //fills gameboard with '·'
masterboard[colums][rows]=(char)0xFA; //fills masterboard with '·'
}
}
|
How do I get mines on the board? |
You can do this:
1 2 3 4 5 6 7 8 9
|
int minecounter = 0;
do {
coordx = rand()%width;
coordy = rand()%height;
if (masterboard[coordx][coordy]==0xFA; { //if coordinates is empty (equals a dot)
masterboard[coordx][coordy]='b'; //place a bomb
minecounter++;
}
} while (minecounter < mines); //do this loop until all mines are placed
|
How do I get it to allow a move to be played? |
You'll need to check the users input (two coordinates) against the masterboard to see what the player finds. Each time the user makes a move, you'll need to update the gameboard.
Before you start implementing these snippets, you might want to consider if your program has the most beneficial layout. Much of this code could go into small functions, which could be called from the main game loop, otherwise you may end up with a really long code.