@@ -311,18 +311,21 @@ static bool game_won(Minesweeper* minesweeper_state) {
311311 return choice == DialogMessageButtonCenter ;
312312}
313313
314+ // returns false if the move loses the game - otherwise true
314315static bool play_move (Minesweeper * minesweeper_state , int cursor_x , int cursor_y ) {
316+ TileType tile = minesweeper_state -> playfield [cursor_x ][cursor_y ]
315317 if (minesweeper_state -> playfield [cursor_x ][cursor_y ] == TileTypeFlag ) {
316- // we're on an flagged field, do nothing
318+ // we're on a flagged field, do nothing
317319 return true;
318320 }
319321 if (minesweeper_state -> minefield [cursor_x ][cursor_y ] == FieldMine ) {
320- // TODO: player loses!
322+ // player loses - draw mine
321323 minesweeper_state -> playfield [cursor_x ][cursor_y ] = TileTypeMine ;
322324 return false;
323325 }
326+
324327 if (minesweeper_state -> playfield [cursor_x ][cursor_y ] >= TileType1 && minesweeper_state -> playfield [cursor_x ][cursor_y ] <= TileType8 ) {
325- // click on an cleared cell with a number
328+ // click on a cleared cell with a number
326329 // count the flags around
327330 int flags = 0 ;
328331 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
356359 }
357360 }
358361 }
359- }
360- }
361- }
362- if (minesweeper_state -> playfield [cursor_x ][cursor_y ] != TileTypeUncleared ) {
363- // we're on an already uncovered field
362+ }
363+ // we're done without hitting a mine - so return
364364 return true;
365+ }
365366 }
367+ //if (minesweeper_state->playfield[cursor_x][cursor_y] != TileTypeUncleared) {
368+ // // we're on an already uncovered field
369+ // return true;
370+ //}
366371 // get number of surrounding mines.
367372 int hint = 0 ;
368373 for (int y = cursor_y - 1 ; y <= cursor_y + 1 ; y ++ ) {
0 commit comments