mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
Minesweeper: Make things a little more friendly at the start
Rather than having the first click hit a bomb, if the first click would hit a bomb, instead, reset the game board. This is a (sort of) feature of Windows minesweeper, and IMO makes playing a bit more fun :-)
This commit is contained in:
parent
5b6e66195b
commit
40a5eb4e6e
2 changed files with 15 additions and 5 deletions
|
@ -97,6 +97,7 @@ Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidg
|
||||||
, m_flag_label(flag_label)
|
, m_flag_label(flag_label)
|
||||||
, m_time_label(time_label)
|
, m_time_label(time_label)
|
||||||
{
|
{
|
||||||
|
srand(time(nullptr));
|
||||||
m_timer.on_timeout = [this] {
|
m_timer.on_timeout = [this] {
|
||||||
++m_time_elapsed;
|
++m_time_elapsed;
|
||||||
m_time_label.set_text(String::format("%u.%u", m_time_elapsed / 10, m_time_elapsed % 10));
|
m_time_label.set_text(String::format("%u.%u", m_time_elapsed / 10, m_time_elapsed % 10));
|
||||||
|
@ -167,6 +168,7 @@ void Square::for_each_neighbor(Callback callback)
|
||||||
|
|
||||||
void Field::reset()
|
void Field::reset()
|
||||||
{
|
{
|
||||||
|
m_first_click = true;
|
||||||
set_updates_enabled(false);
|
set_updates_enabled(false);
|
||||||
m_time_elapsed = 0;
|
m_time_elapsed = 0;
|
||||||
m_time_label.set_text("0");
|
m_time_label.set_text("0");
|
||||||
|
@ -175,7 +177,6 @@ void Field::reset()
|
||||||
m_timer.stop();
|
m_timer.stop();
|
||||||
set_greedy_for_hits(false);
|
set_greedy_for_hits(false);
|
||||||
set_face(Face::Default);
|
set_face(Face::Default);
|
||||||
srand(time(nullptr));
|
|
||||||
|
|
||||||
m_squares.resize(max(m_squares.size(), rows() * columns()));
|
m_squares.resize(max(m_squares.size(), rows() * columns()));
|
||||||
|
|
||||||
|
@ -292,6 +293,13 @@ void Field::paint_event(GPaintEvent& event)
|
||||||
|
|
||||||
void Field::on_square_clicked(Square& square)
|
void Field::on_square_clicked(Square& square)
|
||||||
{
|
{
|
||||||
|
if (m_first_click) {
|
||||||
|
while (square.has_mine) {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_first_click = false;
|
||||||
|
|
||||||
if (square.is_swept)
|
if (square.is_swept)
|
||||||
return;
|
return;
|
||||||
if (square.has_flag)
|
if (square.has_flag)
|
||||||
|
@ -307,12 +315,13 @@ void Field::on_square_clicked(Square& square)
|
||||||
if (square.has_mine) {
|
if (square.has_mine) {
|
||||||
square.label->set_fill_with_background_color(true);
|
square.label->set_fill_with_background_color(true);
|
||||||
game_over();
|
game_over();
|
||||||
} else {
|
return;
|
||||||
--m_unswept_empties;
|
|
||||||
if (square.number == 0)
|
|
||||||
flood_fill(square);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--m_unswept_empties;
|
||||||
|
if (square.number == 0)
|
||||||
|
flood_fill(square);
|
||||||
|
|
||||||
if (!m_unswept_empties)
|
if (!m_unswept_empties)
|
||||||
win();
|
win();
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,4 +92,5 @@ private:
|
||||||
int m_flags_left { 0 };
|
int m_flags_left { 0 };
|
||||||
Face m_face { Face::Default };
|
Face m_face { Face::Default };
|
||||||
bool m_chord_preview { false };
|
bool m_chord_preview { false };
|
||||||
|
bool m_first_click { true };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue