# Wheel-of-Fortune Question/Answer
class WoFQA
- attr_accessor :cat, :clue, :answer, :hint
+ attr_accessor :cat, :clue, :hint
+ attr_reader :answer
+ attr_accessor :guessed
def initialize(cat, clue, ans=nil)
@cat = cat # category
@clue = clue # clue phrase
self.answer = ans
+ @guessed = false
+ end
+
+ def guessed?
+ @guessed
end
def catclue
end
end
+ def mark_guessed(qa)
+ qa.guessed = true
+ end
+
def mark_winner(user)
@running = false
k = user.botuser
def help(plugin, topic="")
case topic
when 'play'
- _("wof [<channel>] play [<name>] for <single> to <max> => starts a wheel-of-fortune game on channel <channel> (default: current channel), named <name> (default: wheelfortune.game_name config setting, or the last game name used by the user), with <single> points per round. the game is won when a player reachers <max> points. vowerls cost <single>*<single>/<max> points. The user that starts the game is the game manager and must set up the clues and answers in private. All the other users have to learn the answer to each clue by saying single consonants or the whole sentence. Every time a consonant is guessed, the bot will reveal the partial answer, showing the missing letters as * (asterisks).")
+ _("wof [<channel>] play [<name>] for <single> to <max> => starts a wheel-of-fortune game on channel <channel> (default: current channel), named <name> (default: wheelfortune.game_name config setting, or the last game name used by the user), with <single> points per round. the game is won when a player reachers <max> points. vowels cost <single>*<single>/<max> points. The user that starts the game is the game manager and must set up the clues and answers in private. All the other users have to learn the answer to each clue by saying single consonants or the whole sentence. Every time a consonant is guessed, the bot will reveal the partial answer, showing the missing letters as * (asterisks).")
when 'category', 'clue', 'answer'
_("wof <channel> [category: <cat>,] clue: <clue>, answer: <ans> => set up a new question for the wheel-of-fortune game being played on channel <channel>. This command must be sent in private by the game manager. The category <cat> can be omitted. If you make mistakes, you can use 'wof replace' (see help) before the question gets asked")
when 'replace'
end
name = p[:name].to_s
if name.empty?
- name = m.source.get_botdata("wheelfortune.game_name") || @bot.config['wheelfortune.game_name']
+ name = @registry["game_name_#{m.source.to_s}"] || @bot.config['wheelfortune.game_name']
else
- m.source.set_botdata("wheelfortune.game_name", name.dup)
+ @registry["game_name_#{m.source.to_s}"] = name
end
@games[ch] = game = WoFGame.new(name, m.botuser, p[:single], p[:max])
@bot.say chan, _("%{who} just created a new %{name} game to %{max} points (%{single} per question, %{price} per vowel)") % {
:name => game.name,
:count => game.length
}
- announce(m, p.merge({ :next => true }) ) unless game.running?
+ announce(m, p) unless game.running?
else
m.reply _("something went wrong, I can't seem to understand what you're trying to set up") if clue.empty?
end
:chan => p[:chan]
}
end
+ return
end
cat = p[:cat].to_s
return
end
game = @games[ch]
- qa = p[:next] ? game.next : game.current
+ qa = game.current
+ if !qa or qa.guessed?
+ qa = game.next
+ end
if !qa
m.reply _("there are no %{name} questions for %{chan}, I'm waiting for %{who} to add them") % {
:name => game.name,
# m.reply "STUPID! YOU SO STUPID!"
return
when *game.must_buy
- m.nickreply _("You must buy the %{vowel}") % {
- :vowel => check
- }
+ m.reply _("You must buy the %{vowel}") % {:vowel => check}, :nick => true
when :wrong
return
when Numeric, :missing
# TODO what happens when the last hint reveals the whole answer?
announce(m)
when :gotit
+ game.mark_guessed(game.current)
want_more = game.mark_winner(m.source)
m.reply _("%{who} got it! The answer was: %{ans}") % {
:who => m.sourcenick,
}
score_table(m.channel, game)
@games.delete(ch)
- else :more
+ else
m.reply _("%{bold}%{color}%{name}%{bold}, round %{count}%{nocolor} -- score so far:") % {
:bold => Bold,
:color => Irc.color(:green),
:nocolor => Irc.color()
}
score_table(m.channel, game)
- announce(m, :next => true)
+ announce(m)
end
else
# can this happen?
end
end
- def listen(m)
- return unless m.kind_of?(PrivMessage) and not m.address?
+ def message(m)
+ return if m.address?
ch = m.channel.irc_downcase(m.server.casemap).intern
return unless game = @games[ch]
return unless game.running?
+ return unless game.current and not game.current.guessed?
check = game.check(m.message, :buy => false)
react_on_check(m, ch, game, check)
end