From 2c4f6473ac45ff5ae2a27514ef907af68115ae9f Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 10 Apr 2008 13:36:35 +0200 Subject: uno plugin: uno end command --- data/rbot/plugins/games/uno.rb | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'data/rbot') diff --git a/data/rbot/plugins/games/uno.rb b/data/rbot/plugins/games/uno.rb index 92bf2b48..ec38b0b0 100644 --- a/data/rbot/plugins/games/uno.rb +++ b/data/rbot/plugins/games/uno.rb @@ -533,11 +533,19 @@ class UnoGame end def end_game - announce _("%{uno} game finished after %{time}! The winner is %{p}") % { - :time => Utils.secs_to_string(Time.now-@start_time), - :uno => UNO, :p => @players.first - } - if @picker > 0 + halted = @players.first.cards.length != 0 + if halted + announce _("%{uno} game halted after %{time}") % { + :time => Utils.secs_to_string(Time.now-@start_time), + :uno => UNO + } + else + announce _("%{uno} game finished after %{time}! The winner is %{p}") % { + :time => Utils.secs_to_string(Time.now-@start_time), + :uno => UNO, :p => @players.first + } + end + if @picker > 0 and not halted p = @players[1] announce _("%{p} has to pick %{b}%{n}%{b} cards!") % { :p => p, :n => @picker, :b => Bold @@ -556,10 +564,12 @@ class UnoGame end sum end - announce _("%{p} wins with %{b}%{score}%{b} points!") % { + if not halted + announce _("%{p} wins with %{b}%{score}%{b} points!") % { :p => @players.first, :score => score, :b => Bold - } - @plugin.end_game(@channel) + } + end + @plugin.do_end_game(@channel) end end @@ -677,7 +687,15 @@ class UnoPlugin < Plugin } end - def end_game(channel) + def end_game(m, p) + unless @games.key?(m.channel) + m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO } + return + end + @games[m.channel].end_game + end + + def do_end_game(channel) @games.delete(channel) end @@ -697,5 +715,8 @@ end pg = UnoPlugin.new pg.map 'uno', :private => false, :action => :create_game +pg.map 'uno end', :private => false, :action => :end_game pg.map 'uno stock', :private => false, :action => :print_stock + pg.default_auth('stock', false) +pg.default_auth('end', false) -- cgit v1.2.3