Felix Pankratz пре 3 година
родитељ
комит
bf8c7f56e6
1 измењених фајлова са 13 додато и 8 уклоњено
  1. 13 8
      minesweeper.c

+ 13 - 8
minesweeper.c

@@ -311,18 +311,21 @@ static bool game_won(Minesweeper* minesweeper_state) {
   return choice == DialogMessageButtonCenter;
   return choice == DialogMessageButtonCenter;
 }
 }
 
 
+// returns false if the move loses the game - otherwise true
 static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) {
 static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) {
+  TileType tile = minesweeper_state->playfield[cursor_x][cursor_y] 
   if (minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
   if (minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
-    // we're on an flagged field, do nothing
+    // we're on a flagged field, do nothing
     return true;
     return true;
   }
   }
   if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
   if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
-    // TODO: player loses!
+    // player loses - draw mine
     minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
     minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
     return false;
     return false;
   }
   }
+
   if (minesweeper_state->playfield[cursor_x][cursor_y] >= TileType1 && minesweeper_state->playfield[cursor_x][cursor_y] <= TileType8) {
   if (minesweeper_state->playfield[cursor_x][cursor_y] >= TileType1 && minesweeper_state->playfield[cursor_x][cursor_y] <= TileType8) {
-    // click on an cleared cell with a number
+    // click on a cleared cell with a number
     // count the flags around
     // count the flags around
     int flags = 0;
     int flags = 0;
     for (int y = cursor_y-1; y <= cursor_y+1; y++) {
     for (int y = cursor_y-1; y <= cursor_y+1; y++) {
@@ -356,13 +359,15 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
             }
             }
           }
           }
         }
         }
-      }
-    }
-  }
-  if (minesweeper_state->playfield[cursor_x][cursor_y] != TileTypeUncleared) {
-      // we're on an already uncovered field
+      } 
+      // we're done without hitting a mine - so return
       return true;
       return true;
+    }
   }
   }
+  //if (minesweeper_state->playfield[cursor_x][cursor_y] != TileTypeUncleared) {
+  //    // we're on an already uncovered field
+  //    return true;
+  //}
   // get number of surrounding mines.
   // get number of surrounding mines.
   int hint = 0;
   int hint = 0;
   for (int y = cursor_y-1; y <= cursor_y+1; y++) {
   for (int y = cursor_y-1; y <= cursor_y+1; y++) {