Created
February 27, 2014 20:24
-
-
Save gberger/9258783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
attr_accessor :name, :points, :explosions | |
def initialize(name) | |
@name = name | |
@points = 0 | |
@explosions = 0 | |
end | |
def add_points(pts) | |
@points += pts | |
if @points >= 100 | |
@explosions += 1 | |
return true | |
end | |
return false | |
end | |
end | |
players = [] | |
round = 1 | |
while true | |
puts 'Digite o nome de um jogador, ou em branco para acabar: ' | |
line = gets.chomp | |
if line == '' | |
break | |
end | |
players.push Player.new(line) | |
end | |
while true | |
puts "Rodada #{round}." | |
exploded = [] | |
players.each do |p| | |
puts "Digite os pontos de #{p.name}: " | |
if p.add_points gets.chomp.to_i | |
puts "#{p.name} explodiu!" | |
exploded.push p | |
end | |
end | |
non_exploded = (players - exploded) | |
if exploded.length > 0 | |
max = (non_exploded.max_by &:points).points | |
exploded.each do |p| | |
p.points = max | |
end | |
end | |
puts "Fim da rodada #{round}." | |
players.each do |p| | |
puts "#{p.name} tem #{p.points} pontos e já explodiu #{p.explosions} vezes." | |
end | |
if non_exploded.length == 1 | |
puts "Todos explodiram menos #{non_exploded.first.name}! WINNER!" | |
break | |
end | |
round += 1 | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment