@color = 'Wild'
raise if value and not value == '+4'
if value
- @value = value.dup
+ @value = value.dup
@shortform = 'w'+value
else
@value = nil
# number of cards to be picked if the player can't play an appropriate card
attr_reader :picker
+ # game start time
+ attr :start_time
+
# the IRC user that created the game
attr_accessor :manager
# if play is forced, check against the only allowed cards
return false if @must_play and not @must_play.include?(card)
- # When a +something is online, you can only play a +something of same or
- # higher something, or a Reverse of the correct color, or a Reverse on
- # a Reverse
- # TODO make optional
if @picker > 0
- return true if card.picker >= @last_picker
- return true if card.value == 'Reverse' and (card.color == @color or @discard.value == card.value)
- return false
+ # During a picker run (i.e. after a +something was played and before a
+ # player is forced to pick) you can only play pickers (+2, +4) and
+ # Reverse. Reverse can be played if the previous card matches by color or
+ # value (as usual), a +4 can always be played, a +2 can be played on a +2
+ # of any color or on a Reverse of the correct color unless a +4 was
+ # played on it
+ # TODO make optional
+ case card.value
+ when 'Reverse'
+ # Reverse can be played if it matches color or value
+ return (card.color == @color) || (@discard.value == card.value)
+ when '+2'
+ return false if @last_picker > 2
+ return true if @discard.value == card.value
+ return true if @discard.value == 'Reverse' and @color == card.color
+ return false
+ when '+4'
+ return true
+ else
+ return false
+ end
else
# You can always play a Wild
return true if Wild === card
# only be possible if the first W+4 was illegal, so it wouldn't
# apply for a W+4 played on a +2 anyway.
#
- if @picker == 0 and Wild === cards.first and cards.first.value
+ if @picker == 0 and Wild === cards.first and cards.first.value
# save the previous discard in case of challenge
@last_discard = @discard.dup
# save the color too, in case it was a Wild
end
def choose_color(user, color)
+ # you can only pick a color if the current color is unset
+ if @color
+ announce _("you can't pick a color now, %{p}") % {
+ :p => get_player(user)
+ }
+ return
+ end
case color
when 'r'
@color = 'Red'
end
def has_turn?(source)
- @players.first.user == source
+ @start_time && (@players.first.user == source)
end
def show_picker
def show_user_cards(player)
p = Player === player ? player : get_player(player)
+ return unless p
notify p, _('Your cards: %{cards}') % {
:cards => p.cards.join(' ')
}
end
cards = 7
if @start_time
- cards = @players.inject(0) do |s, pl|
+ cards = (@players.inject(0) do |s, pl|
s +=pl.cards.length
- end/@players.length
+ end*1.0/@players.length).ceil
end
p = Player.new(user)
@players << p
}
end
if @picker > 0 and not halted
- p = @players[1]
+ if @discard.value == 'Reverse'
+ p = @players.last
+ else
+ p = @players[1]
+ end
announce _("%{p} has to pick %{b}%{n}%{b} cards!") % {
:p => p, :n => @picker, :b => Bold
}
_("'od' to show the playing order"),
_("'ti' to show play time"),
_("'tu' to show whose turn it is")
- ].join(" ; ")
+ ].join("; ")
when 'challenge'
_("A Wild +4 can only be played legally if you don't have normal (not special) cards of the current color. ") +
_("The next player can challenge a W+4 by using the 'ch' command. ") +
_("Wild +4 also forces the next player to take 4 cards, but it can only be played if you can't play a color card. ") +
_("you can play another +2 or +4 card on a +2 card, and a +4 on a +4, forcing the first player who can't play one to pick the cumulative sum of all cards. ") +
_("you can also play a Reverse on a +2 or +4, bouncing the effect back to the previous player (that now comes next). ")
+ when /scor(?:e|ing)/, /points?/
+ [
+ _("The points won with a game of %{uno} are totalled from the cards remaining in the hands of the other players."),
+ _("Each normal (not special) card is worth its face value (from 0 to 9 points)."),
+ _("Each colored special card (+2, Reverse, Skip) is worth 20 points."),
+ _("Each Wild and Wild +4 is worth 50 points."),
+ help(plugin, 'top'),
+ help(plugin, 'topwin'),
+ ].join(" ") % { :uno => UnoGame::UNO }
+ when 'top'
+ _("You can see the scoring table with 'uno top N' where N is the number of top scores to show.")
+ when 'topwin'
+ _("You can see the winners table with 'uno topwin N' where N is the number of top winners to show.")
+ when /cards?/
+ [
+ _("There are 108 cards in a standard %{uno} deck."),
+ _("For each color (Blue, Green, Red, Yellow) there are 19 numbered cards (from 0 to 9), with two of each number except for 0."),
+ _("There are also 6 special cards for each color, two each of +2, Reverse, Skip."),
+ _("Finally, there are 4 Wild and 4 Wild +4 cards.")
+ ].join(" ") % { :uno => UnoGame::UNO }
+ when 'admin'
+ _("The game manager (the user that started the game) can execute the following commands to manage it: ") +
+ [
+ _("'uno drop <user>' to drop a user from the game (any user can drop itself using 'uno drop')"),
+ _("'uno replace <old> [with] <new>' to replace a player with someone else (useful in case of disconnects)"),
+ _("'uno transfer [to] <nick>' to transfer game ownership to someone else"),
+ _("'uno end' to end the game before its natural completion")
+ ].join("; ")
else
- (_("%{uno} game. !uno to start a game. see help uno rules for the rules. commands: %{cmds}") % {
+ _("%{uno} game. !uno to start a game. see 'help uno rules' for the rules, 'help uno admin' for admin commands, 'help uno score' for scoring rules. In-game commands: %{cmds}.") % {
:uno => UnoGame::UNO,
:cmds => help(plugin, 'commands')
- })
+ }
end
end
def message(m)
return unless @games.key?(m.channel)
+ return unless m.plugin # skip messages such as: <someuser> botname,
g = @games[m.channel]
case m.plugin.intern
when :jo # join game
m.reply _("It's not your turn")
end
when :pa # pass turn
- return if m.params
+ return if m.params or not g.start_time
if g.has_turn?(m.source)
g.pass(m.source)
else
return if m.params
g.show_all_cards(m.source)
when :cd # show current discard
- return if m.params
+ return if m.params or not g.start_time
g.show_discard
when :ch
if g.has_turn?(m.source)
when :tu # show whose turn is it
return if m.params
if g.has_turn?(m.source)
- m.nickreply _("it's your turn, sleepyhead")
+ m.reply _("it's your turn, sleepyhead"), :nick => true
else
g.show_turn(:cards => false)
end
scores << [v.won.inject(0) { |s, w| s+=w.score }, k]
end
+ if wins.empty?
+ m.reply(_("no %{uno} games were completed here") % {
+ :uno => UnoGame::UNO
+ })
+ return
+ end
+
+
if n = p[:scorenum]
msg = _("%{uno} %{num} highest scores: ") % {
:uno => UnoGame::UNO, :num => p[:scorenum]