changeset 437:722f2bbd654a

Plugin hangman: show current word on command, closes #643
author David Demelier <markand@malikania.fr>
date Sun, 16 Apr 2017 09:56:34 +0200
parents 18574b79e422
children 65c7aecc9773
files plugins/hangman/hangman.js plugins/hangman/hangman.md tests/plugin-hangman/main.cpp
diffstat 3 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/hangman/hangman.js	Tue Mar 07 12:20:52 2017 +0100
+++ b/plugins/hangman/hangman.js	Sun Apr 16 09:56:34 2017 +0200
@@ -40,7 +40,7 @@
     "asked":        "#{nickname}, '#{letter}' was already asked.",
     "dead":         "#{nickname}, fail the word was: #{word}.",
     "found":        "#{nickname}, nice! the word is now #{word}",
-    "running":      "#{nickname}, the game is already running.",
+    "running":      "#{nickname}, the game is already running and the word is: #{word}",
     "start":        "#{nickname}, the game is started, the word to find is: #{word}",
     "win":          "#{nickname}, congratulations, the word is #{word}.",
     "wrong-word":   "#{nickname}, this is not the word.",
@@ -342,9 +342,10 @@
     if (game) {
         var list = message.split(" \t");
 
-        if (list.length === 0 || String(list[0]).length === 0)
+        if (list.length === 0 || String(list[0]).length === 0) {
+            kw.word = game.formatWord();
             server.message(channel, Util.format(Plugin.format["running"], kw));
-        else {
+        } else {
             var word = String(list[0]);
 
             if (Hangman.isWord(word))
--- a/plugins/hangman/hangman.md	Tue Mar 07 12:20:52 2017 +0100
+++ b/plugins/hangman/hangman.md	Sun Apr 16 09:56:34 2017 +0200
@@ -17,13 +17,21 @@
 
 ## Usage
 
-The **hangman** plugin starts when a user execute its special command with no arguments.
+The **hangman** plugin starts when a user execute its special command with no
+arguments.
 
 ````nohighlight
 markand: !hangman
 irccd: markand, the game is started, the word to find is: _ _ _ _ _ _ _ _ _ _ _
 ````
 
+If a game is already running, the same command shows the current word.
+
+````nohighlight
+markand: !hangman
+irccd: markand, the game is already running and the word is: s _ _,
+````
+
 ### Proposal
 
 There are two ways for proposing a response to the game. You can either just ask for a letter or for a whole word.
@@ -92,6 +100,7 @@
 | **dead**                | word                                               | the word to find                |
 | **found**               | word                                               | the hidden word                 |
 | **start**               | word                                               | the hidden word                 |
+| **running**             | word                                               | the hidden word                 |
 | **win**                 | word                                               | the word to find                |
 | **wrong-word**          | word                                               | the invalid word proposal       |
 | **wrong-letter**        | letter                                             | the letter proposal             |
--- a/tests/plugin-hangman/main.cpp	Tue Mar 07 12:20:52 2017 +0100
+++ b/tests/plugin-hangman/main.cpp	Sun Apr 16 09:56:34 2017 +0200
@@ -62,6 +62,7 @@
             { "dead", "dead=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{word}" },
             { "found", "found=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{word}" },
             { "start", "start=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{word}" },
+            { "running", "running=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{word}" },
             { "win", "win=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{word}" },
             { "wrong-letter", "wrong-letter=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{letter}" },
             { "wrong-player", "wrong-player=#{plugin}:#{command}:#{server}:#{channel}:#{origin}:#{nickname}:#{letter}" },
@@ -213,6 +214,16 @@
     ASSERT_EQ("jean:win=hangman:!hangman:test:jean:jean!jean@localhost:jean:sky", m_server->last());
 }
 
+TEST_F(HangmanTest, running)
+{
+    load();
+
+    m_plugin->onCommand(m_irccd, MessageEvent{m_server, "jean!jean@localhost", "#hangman", ""});
+    m_plugin->onMessage(m_irccd, MessageEvent{m_server, "jean!jean@localhost", "#hangman", "y"});
+    m_plugin->onCommand(m_irccd, MessageEvent{m_server, "jean!jean@localhost", "#hangman", ""});
+    ASSERT_EQ("#hangman:running=hangman:!hangman:test:#hangman:jean!jean@localhost:jean:_ _ y", m_server->last());
+}
+
 int main(int argc, char **argv)
 {
     path::setApplicationPath(argv[0]);