mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:37:44 +00:00
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
This commit is contained in:
parent
cc5ea3aa4c
commit
1d687b0b31
2 changed files with 7 additions and 6 deletions
|
@ -83,22 +83,23 @@ void WordGame::keydown_event(GUI::KeyEvent& event)
|
||||||
// If we can still add a letter and the key was alpha
|
// 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())) {
|
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_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
|
// If backspace pressed and already have some letters entered
|
||||||
else if (event.key() == KeyCode::Key_Backspace && m_current_guess.length() > 0) {
|
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_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
|
// If return pressed
|
||||||
else if (event.key() == KeyCode::Key_Return) {
|
else if (event.key() == KeyCode::Key_Return) {
|
||||||
if (m_current_guess.length() < m_num_letters) {
|
if (m_current_guess.length() < m_num_letters) {
|
||||||
show_message("Not enough letters"sv);
|
show_message("Not enough letters"sv);
|
||||||
|
m_last_word_invalid = true;
|
||||||
} else if (!is_in_dictionary(m_current_guess)) {
|
} else if (!is_in_dictionary(m_current_guess)) {
|
||||||
show_message("Not in dictionary"sv);
|
show_message("Not in dictionary"sv);
|
||||||
m_last_word_not_in_dictionary = true;
|
m_last_word_invalid = true;
|
||||||
} else {
|
} else {
|
||||||
m_last_word_not_in_dictionary = false;
|
m_last_word_invalid = false;
|
||||||
clear_message();
|
clear_message();
|
||||||
|
|
||||||
add_guess(m_current_guess);
|
add_guess(m_current_guess);
|
||||||
|
@ -147,7 +148,7 @@ void WordGame::paint_event(GUI::PaintEvent& event)
|
||||||
} else if (guess_index == m_guesses.size()) {
|
} else if (guess_index == m_guesses.size()) {
|
||||||
if (letter_index < m_current_guess.length())
|
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);
|
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);
|
painter.fill_rect(this_rect, m_word_not_in_dict_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
size_t m_max_guesses { 6 };
|
size_t m_max_guesses { 6 };
|
||||||
size_t m_num_letters { 5 };
|
size_t m_num_letters { 5 };
|
||||||
bool m_check_guesses { false };
|
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_width { 40 };
|
||||||
static constexpr int m_letter_spacing { 5 };
|
static constexpr int m_letter_spacing { 5 };
|
||||||
static constexpr int m_outer_margin { 20 };
|
static constexpr int m_outer_margin { 20 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue