summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/games
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-01-12 22:15:12 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-01-12 22:15:12 +0100
commit12a508e1a75bc1de501f36ca9e4767f2349fe12e (patch)
tree8ec4db236d70c064742b87c79feb86e783312e1c /data/rbot/plugins/games
parentcafa66beb3392f30ba8f11e6763f690518512471 (diff)
Ruby 1.9 cleanup: variables warnings
Fix most ruby 1.9 warnings about shadowed variables (still one remaining in keywords.rb). The only significant changes are in the quiz game plugin. Also fix an issue in dictclient where the block parameter of a method was not correctly isolated from the previous parameter.
Diffstat (limited to 'data/rbot/plugins/games')
-rw-r--r--data/rbot/plugins/games/quiz.rb44
-rw-r--r--data/rbot/plugins/games/uno.rb12
2 files changed, 27 insertions, 29 deletions
diff --git a/data/rbot/plugins/games/quiz.rb b/data/rbot/plugins/games/quiz.rb
index 63a5dde4..d2e4ab97 100644
--- a/data/rbot/plugins/games/quiz.rb
+++ b/data/rbot/plugins/games/quiz.rb
@@ -285,8 +285,10 @@ class QuizPlugin < Plugin
jokers = q.registry[nick].jokers
rank = 0
- q.rank_table.each_index { |rank| break if nick.downcase == q.rank_table[rank][0].downcase }
- rank += 1
+ q.rank_table.each do |place|
+ rank += 1
+ break if nick.downcase == place[0].downcase
+ end
m.reply "#{nick}'s score is: #{score} Rank: #{rank} Jokers: #{jokers}"
else
@@ -313,45 +315,41 @@ class QuizPlugin < Plugin
stats = q.registry[nick]
# Find player in table
- found_player = false
- i = 0
- q.rank_table.each_index do |i|
- if nick.downcase == q.rank_table[i][0].downcase
- found_player = true
+ old_rank = nil
+ q.rank_table.each_with_index do |place, i|
+ if nick.downcase == place[0].downcase
+ old_rank = i
break
end
end
# Remove player from old position
- if found_player
- old_rank = i
- q.rank_table.delete_at( i )
- else
- old_rank = nil
+ if old_rank
+ q.rank_table.delete_at( old_rank )
end
# Insert player at new position
- inserted = false
- q.rank_table.each_index do |i|
- if stats.score > q.rank_table[i][1].score
+ new_rank = nil
+ q.rank_table.each_with_index do |place, i|
+ if stats.score > place[1].score
q.rank_table[i,0] = [[nick, stats]]
- inserted = true
+ new_rank = i
break
end
end
# If less than all other players' scores, append to table
- unless inserted
- i += 1 unless q.rank_table.empty?
+ unless new_rank
+ new_rank = q.rank_table.length
q.rank_table << [nick, stats]
end
# Print congratulations/condolences if the player's rank has changed
- unless old_rank.nil?
- if i < old_rank
- m.reply "#{nick} ascends to rank #{i + 1}. Congratulations :)"
- elsif i > old_rank
- m.reply "#{nick} slides down to rank #{i + 1}. So Sorry! NOT. :p"
+ if old_rank
+ if new_rank < old_rank
+ m.reply "#{nick} ascends to rank #{new_rank + 1}. Congratulations :)"
+ elsif new_rank > old_rank
+ m.reply "#{nick} slides down to rank #{new_rank + 1}. So Sorry! NOT. :p"
end
end
else
diff --git a/data/rbot/plugins/games/uno.rb b/data/rbot/plugins/games/uno.rb
index 75154362..ab0ea161 100644
--- a/data/rbot/plugins/games/uno.rb
+++ b/data/rbot/plugins/games/uno.rb
@@ -772,9 +772,9 @@ class UnoGame
}
return false
end
- if p = get_player(user)
+ if pl = get_player(user)
announce _("%{p} is already playing %{uno} here") % {
- :p => p, :uno => UNO
+ :p => pl, :uno => UNO
}
return false
end
@@ -831,12 +831,12 @@ class UnoGame
deal(p, @picker)
@picker = 0
end
- score = @players.inject(0) do |sum, p|
- if p.cards.length > 0
+ score = @players.inject(0) do |sum, pl|
+ if pl.cards.length > 0
announce _("%{p} still had %{cards}") % {
- :p => p, :cards => p.cards.join(' ')
+ :p => pl, :cards => pl.cards.join(' ')
}
- sum += p.cards.inject(0) do |cs, c|
+ sum += pl.cards.inject(0) do |cs, c|
cs += c.score
end
end