]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/uno.rb
uno plugin: sort players' cards
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
index e4ee2ae2b72c373567979b5ddc0de6e7c32f044f..1d49642ceae554c748798986c5b983e120bb1207 100644 (file)
@@ -86,6 +86,16 @@ class UnoGame
     def special?
       SPECIALS.include?(@value)
     end
+
+    def <=>(other)
+      cc = self.color <=> other.color
+      if cc == 0
+        return self.value.to_s <=> other.value.to_s
+      else
+        return cc
+      end
+    end
+    include Comparable
   end
 
   # Wild, Wild +4 cards
@@ -467,6 +477,7 @@ class UnoGame
     end
     notify player, _("You picked %{picked}") % { :picked => picked.join(' ') }
     player.cards += picked
+    player.cards.sort!
   end
 
   def add_player(user)
@@ -565,7 +576,7 @@ class UnoPlugin < Plugin
       end
     when :pl # play card
       if g.has_turn?(m.source)
-        g.play_card(m.source, m.params)
+        g.play_card(m.source, m.params.downcase)
       else
         m.reply _("It's not your turn")
       end