mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
Minesweeper: Make sure icons of cells are set after generating field
In reset() function, the icons of labels in the game area were initially set as mine icon or null. And then, after generation, only the number icon was set. In the old field generation algorithm, this did not cause a very visible issue (The displayed mine icons in the game over screen were from a previously generated game field, which was only slightly wrong). However, the newer field generation caused a "no mine icons are shown in the game over screen" issue. To fix that, the label icon is set to null initially, and then it is set to a mine or number bitmap.
This commit is contained in:
parent
5562ef6cc5
commit
71537f4903
1 changed files with 4 additions and 4 deletions
|
@ -239,7 +239,7 @@ void Field::reset()
|
|||
square.label->set_fill_with_background_color(false);
|
||||
square.label->set_relative_rect(rect);
|
||||
square.label->set_visible(false);
|
||||
square.label->set_icon(square.has_mine ? m_mine_bitmap : nullptr);
|
||||
square.label->set_icon(nullptr);
|
||||
if (!square.button) {
|
||||
square.button = add<SquareButton>();
|
||||
square.button->on_click = [this, &square](auto) {
|
||||
|
@ -313,9 +313,9 @@ void Field::generate_field(size_t start_row, size_t start_column)
|
|||
number += neighbor.has_mine;
|
||||
});
|
||||
square.number = number;
|
||||
if (square.has_mine)
|
||||
continue;
|
||||
if (square.number) {
|
||||
if (square.has_mine) {
|
||||
square.label->set_icon(m_mine_bitmap);
|
||||
} else if (square.number) {
|
||||
square.label->set_icon(m_number_bitmap[square.number - 1]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue