summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-06-07 02:21:42 -0700
committerAndreas Kling <kling@serenityos.org>2021-06-07 21:52:16 +0200
commit06ea31d0d5c0bc4e7b6f07b26bd8163697e22eb7 (patch)
treecdea5730d9b858cb265ceb31a05d366ffcee9f35 /Userland
parentc3a60a5dcd8f4275520229df482ce7e43eefdde7 (diff)
downloadserenity-06ea31d0d5c0bc4e7b6f07b26bd8163697e22eb7.zip
CatDog: Enhance the speech bubble artificial intelligence
Enable cat dog to greet you, and help you with yak shave sessions.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Demos/CatDog/SpeechBubble.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Demos/CatDog/SpeechBubble.cpp b/Userland/Demos/CatDog/SpeechBubble.cpp
index 4ce092d22e..dbe87372b6 100644
--- a/Userland/Demos/CatDog/SpeechBubble.cpp
+++ b/Userland/Demos/CatDog/SpeechBubble.cpp
@@ -5,9 +5,18 @@
*/
#include "SpeechBubble.h"
+#include <AK/Array.h>
+#include <AK/Random.h>
+#include <AK/StringView.h>
#include <LibGUI/Painter.h>
#include <LibGfx/Palette.h>
+static Array<StringView, 3> messages = {
+ "It looks like you're trying to debug\na program. Would you like some help?"sv,
+ "It looks like you're trying to shave\na yak. Would you like some help?"sv,
+ "Well Hello Friend!"sv,
+};
+
void SpeechBubble::paint_event(GUI::PaintEvent&)
{
GUI::Painter painter(*this);
@@ -28,7 +37,8 @@ void SpeechBubble::paint_event(GUI::PaintEvent&)
painter.draw_line(connector_top_left, Gfx::IntPoint { connector_bottom.x() - 1, connector_bottom.y() }, palette().active_window_border1());
painter.draw_line(connector_top_right, connector_bottom, palette().active_window_border1());
- painter.draw_text(text_area, "It looks like you're trying to debug\na program. Would you like some help?", Gfx::TextAlignment::Center);
+ auto message = messages[get_random<u8>() % messages.size()];
+ painter.draw_text(text_area, message, Gfx::TextAlignment::Center);
}
void SpeechBubble::mousedown_event(GUI::MouseEvent& event)