module TabooGame
Constants
- MAX_HINTS
- PLUGIN
- STYLE_TITLE
Public Instance Methods
Source
# File lib/taboo_game.rb, line 112 def format_header(title) IrcFormat.report_header(tag: "TABOO", title: title, style: STYLE_TITLE) end
Source
# File lib/taboo_game.rb, line 116 def format_status(game) return format_header("No game") + "\nNo taboo game active." unless game lines = [format_header("#{game['clue_giver']} vs #{game['guesser']}")] lines << "Hints used: #{Array(game['hints']).length}/#{MAX_HINTS}" lines << IrcFormat.report_footer(game["stage"]) lines.join("\n") end
Source
# File lib/taboo_game.rb, line 69 def give_hint(game:, user:, text:) return { error: "No active taboo game." } unless game && game["stage"] == "active" return { error: "Only the clue giver can hint." } unless GameStore.same_nick?(user, game["clue_giver"]) hint = text.to_s.strip return { error: "Hint cannot be empty." } if hint.empty? return { error: "Hint uses a banned word." } if uses_banned?(hint, game["banned"]) return { error: "Do not say the secret word." } if hint.downcase.include?(game["secret"].downcase) game = game.dup hints = game["hints"].dup << hint game["hints"] = hints return { error: "Hint limit reached." } if hints.length > MAX_HINTS { game: game, message: "Hint ##{hints.length} recorded." } end
Source
# File lib/taboo_game.rb, line 35 def parse_command(text) base = AsyncDuel.parse_base(text, usage: usage_message) return base unless base[:action] == :unknown parts = base[:tail] case parts[0].downcase when "hint" return { error: usage_message } if parts.length < 2 { action: :hint, text: parts[1..].join(" ") } when "guess" return { error: usage_message } if parts.length < 2 { action: :guess, word: parts[1..].join(" ") } else { error: usage_message } end end
Source
# File lib/taboo_game.rb, line 54 def start_game(game, rand: ->(max) { Random.rand(0...max) }) pair = TabooWords.pick(rand: rand) game = game.dup game["stage"] = "active" game["clue_giver"] = game["challenger"] game["guesser"] = game["target"] game["secret"] = pair[:word] game["banned"] = pair[:banned] game["hints"] = [] { game: game, message: "#{format_header('Reverse Taboo')}\n#{game['clue_giver']}: give hints with !taboo hint <message>\n#{game['guesser']}: guess with !taboo guess <word>\nBanned words hidden from guesser." } end
Source
# File lib/taboo_game.rb, line 86 def submit_guess(game:, user:, word:) return { error: "No active taboo game." } unless game && game["stage"] == "active" return { error: "Only the guesser can guess." } unless GameStore.same_nick?(user, game["guesser"]) guess = word.to_s.strip.downcase secret = game["secret"].downcase game = game.dup if guess == secret game["stage"] = "done" game["winner"] = GameStore.norm_nick(user) hints = game["hints"].length { game: game, message: "#{GameStore.norm_nick(user)} guessed #{game['secret']} in #{hints} hint#{hints == 1 ? '' : 's'}!", done: true } else { game: game, message: "Not quite — try again." } end end
Source
# File lib/taboo_game.rb, line 31 def usage_message "Usage: !taboo challenge <nick> | accept | decline | hint <message> | guess <word> | status" end
Source
# File lib/taboo_game.rb, line 107 def uses_banned?(text, banned) down = text.downcase banned.any? { |word| down.match?(/\b#{Regexp.escape(word.downcase)}\b/) } end