|
|
|
@ -313,6 +313,15 @@ static bool game_won(Minesweeper* minesweeper_state) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) {
|
|
|
|
|
if (minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
|
|
|
|
|
// we're on an flagged field, do nothing
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
|
|
|
|
|
// TODO: player loses!
|
|
|
|
|
minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
// count the flags around
|
|
|
|
@ -341,7 +350,10 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
|
|
|
|
}
|
|
|
|
|
if ( auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 && auto_y < PLAYFIELD_HEIGHT) {
|
|
|
|
|
if (minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
|
|
|
|
|
play_move(minesweeper_state, auto_x, auto_y);
|
|
|
|
|
if(!play_move(minesweeper_state, auto_x, auto_y)) {
|
|
|
|
|
// flags were wrong, we got a mine!
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -352,11 +364,6 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
|
|
|
|
// we're on an already uncovered field
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
|
|
|
|
|
// TODO: player loses!
|
|
|
|
|
minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// get number of surrounding mines.
|
|
|
|
|
int hint = 0;
|
|
|
|
|
for (int y = cursor_y-1; y <= cursor_y+1; y++) {
|
|
|
|
@ -394,7 +401,6 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void minesweeper_state_init(Minesweeper* const minesweeper_state) {
|
|
|
|
|
minesweeper_state->cursor_x = minesweeper_state->cursor_y = 0;
|
|
|
|
|