summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Game.cpp55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/Game.cpp b/src/Game.cpp
index 988c467..ad29029 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -29,12 +29,26 @@ void Game::initDiff(int diff) {
}
void Game::initBoard() {
+ // Bomb map (boolean): 0 or false is no bomb, 1 or true is bomb;
+ // clearing bomb map
for (int i = 0; i < boardHeight; i++) {
for (int j = 0; j < boardWidth; j++) {
- bombMap[i][j] = rand() % 2;
+ for(int k = 0; k < mines; k++){
+ bombMap[i][j] = 0;
+ }
}
}
+ // initializing bomb map
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++) {
+ for(int k = 0; k < mines; k++){
+ bombMap[i][j] = rand() % 2;
+ }
+ }
+ }
+
+ // initializing tile map for display
for (int i = 0; i < boardHeight; i++) {
for (int j = 0; j < boardWidth; j++) {
tileMap[i][j] = 0;
@@ -55,10 +69,45 @@ int Game::editDiff(){
return 0;
}
+/* Tile map:
+
+0 - unrevealed tile
+1 - revealed tile
+2 - revealed tile with 1 bomb around
+3 - revealed tile with 2 bomb around
+4 - revealed tile with 3 bomb around
+5 - revealed tile with 4 bomb around
+6 - revealed tile with 5 bomb around
+7 - revealed tile with 6 bomb around
+8 - revealed tile with 7 bomb around
+9 - revealed tile with 8 bomb around
+
+*/
void Game::displayBoard() {
for (int i = 0; i < boardHeight; i++) {
- for (int j = 0; j < boardWidth; j++)
- putchar(tileMap[i][j]);
+ for (int j = 0; j < boardWidth; j++) {
+ if (tileMap[i][j] == 0) {
+ putchar('#');
+ } else if (tileMap[i][j] == 1) {
+ putchar('.');
+ } else if (tileMap[i][j] == 2) {
+ putchar('1');
+ } else if (tileMap[i][j] == 3) {
+ putchar('2');
+ } else if (tileMap[i][j] == 4) {
+ putchar('3');
+ } else if (tileMap[i][j] == 5) {
+ putchar('4');
+ } else if (tileMap[i][j] == 6) {
+ putchar('5');
+ } else if (tileMap[i][j] == 7) {
+ putchar('6');
+ } else if (tileMap[i][j] == 8) {
+ putchar('7');
+ } else if (tileMap[i][j] == 9) {
+ putchar('8');
+ }
+ }
putchar('\n');
}
} \ No newline at end of file