mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:47:44 +00:00
MasterWord: Display messages in a statusbar
In the "inspiration" for this game, messages are displayed on top of the game area in case an invalid guess is inputted. After a few seconds, they disappear. In a similar fashion, a statusbar is created on the game window and similar messages are outputted there.
This commit is contained in:
parent
d3588a9a2b
commit
cc5ea3aa4c
5 changed files with 94 additions and 19 deletions
|
@ -7,10 +7,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
|
||||
namespace MasterWord {
|
||||
|
||||
class WordGame : public GUI::Frame {
|
||||
C_OBJECT(WordGame);
|
||||
|
||||
|
@ -32,9 +38,13 @@ public:
|
|||
void add_guess(AK::StringView guess);
|
||||
bool is_in_dictionary(AK::StringView guess);
|
||||
|
||||
Function<void(Optional<StringView>)> on_message;
|
||||
|
||||
private:
|
||||
WordGame();
|
||||
void read_words();
|
||||
void show_message(StringView message) const;
|
||||
void clear_message() const;
|
||||
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||
|
@ -76,4 +86,8 @@ private:
|
|||
AK::DeprecatedString m_current_word;
|
||||
|
||||
HashMap<size_t, AK::Vector<DeprecatedString>> m_words;
|
||||
|
||||
NonnullRefPtr<Core::Timer> m_clear_message_timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue