add missing return?

flagsbased-uncover
Felix Pankratz 2 years ago
parent 1839389e43
commit bf8c7f56e6

@ -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++) {
@ -357,12 +360,14 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
} }
} }
} }
} // we're done without hitting a mine - so return
}
if (minesweeper_state->playfield[cursor_x][cursor_y] != TileTypeUncleared) {
// we're on an already uncovered field
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++) {

Loading…
Cancel
Save