summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2022-12-08 14:39:48 +0300
committerAndreas Kling <kling@serenityos.org>2022-12-11 22:10:37 +0100
commit1d687b0b31547661d3b9c9c76766690415ebbe8c (patch)
tree5ce2753fddd83a4f2e1895839b2ad9b7a263c75a
parentcc5ea3aa4c09d8e617f51f554e8f452a2bf227b9 (diff)
downloadserenity-1d687b0b31547661d3b9c9c76766690415ebbe8c.zip
MasterWord: Display the last word in a different color for short input
Previously, the word was highlighted red in case it was not found in the dictionary. That color was repurposed as a general "invalid input" color to nudge the player that something was wrong with the last input. Accordingly, the field m_last_word_not_in_dictionary was renamed to m_last_word_invalid
-rw-r--r--Userland/Games/MasterWord/WordGame.cpp11
-rw-r--r--Userland/Games/MasterWord/WordGame.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Games/MasterWord/WordGame.cpp b/Userland/Games/MasterWord/WordGame.cpp
index 681cdf638d..398fa5307d 100644
--- a/Userland/Games/MasterWord/WordGame.cpp
+++ b/Userland/Games/MasterWord/WordGame.cpp
@@ -83,22 +83,23 @@ void WordGame::keydown_event(GUI::KeyEvent& event)
// If we can still add a letter and the key was alpha
if (m_current_guess.length() < m_num_letters && is_ascii_alpha(event.code_point())) {
m_current_guess = DeprecatedString::formatted("{}{}", m_current_guess, event.text().to_uppercase());
- m_last_word_not_in_dictionary = false;
+ m_last_word_invalid = false;
}
// If backspace pressed and already have some letters entered
else if (event.key() == KeyCode::Key_Backspace && m_current_guess.length() > 0) {
m_current_guess = m_current_guess.substring(0, m_current_guess.length() - 1);
- m_last_word_not_in_dictionary = false;
+ m_last_word_invalid = false;
}
// If return pressed
else if (event.key() == KeyCode::Key_Return) {
if (m_current_guess.length() < m_num_letters) {
show_message("Not enough letters"sv);
+ m_last_word_invalid = true;
} else if (!is_in_dictionary(m_current_guess)) {
show_message("Not in dictionary"sv);
- m_last_word_not_in_dictionary = true;
+ m_last_word_invalid = true;
} else {
- m_last_word_not_in_dictionary = false;
+ m_last_word_invalid = false;
clear_message();
add_guess(m_current_guess);
@@ -147,7 +148,7 @@ void WordGame::paint_event(GUI::PaintEvent& event)
} else if (guess_index == m_guesses.size()) {
if (letter_index < m_current_guess.length())
painter.draw_text(this_rect, m_current_guess.substring_view(letter_index, 1), font(), Gfx::TextAlignment::Center, m_text_color);
- if (m_last_word_not_in_dictionary) {
+ if (m_last_word_invalid) {
painter.fill_rect(this_rect, m_word_not_in_dict_color);
}
}
diff --git a/Userland/Games/MasterWord/WordGame.h b/Userland/Games/MasterWord/WordGame.h
index 7023e21865..4b7fa90eb8 100644
--- a/Userland/Games/MasterWord/WordGame.h
+++ b/Userland/Games/MasterWord/WordGame.h
@@ -56,7 +56,7 @@ private:
size_t m_max_guesses { 6 };
size_t m_num_letters { 5 };
bool m_check_guesses { false };
- bool m_last_word_not_in_dictionary { false };
+ bool m_last_word_invalid { false };
static constexpr int m_letter_width { 40 };
static constexpr int m_letter_spacing { 5 };
static constexpr int m_outer_margin { 20 };