From 71537f4903d1369552424db0fc819fd5ef325a79 Mon Sep 17 00:00:00 2001 From: Arda Cinar Date: Fri, 9 Dec 2022 17:20:57 +0300 Subject: [PATCH] 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. --- Userland/Games/Minesweeper/Field.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Games/Minesweeper/Field.cpp b/Userland/Games/Minesweeper/Field.cpp index d56dd5a938..0cfc0785e6 100644 --- a/Userland/Games/Minesweeper/Field.cpp +++ b/Userland/Games/Minesweeper/Field.cpp @@ -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(); 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]); } }