mirror of
https://github.com/danbee/scoreboard
synced 2025-03-04 08:59:11 +00:00
44 lines
759 B
Ruby
44 lines
759 B
Ruby
class Match
|
|
def initialize
|
|
@one, @two = Player.new('Player One'), Player.new('Player Two')
|
|
end
|
|
|
|
def add_point(colour)
|
|
players[colour].score.increment
|
|
if @one.has_beaten(@two)
|
|
reset_scores
|
|
@one.games.increment
|
|
elsif @two.has_beaten(@one)
|
|
reset_scores
|
|
@two.games.increment
|
|
end
|
|
end
|
|
|
|
def reset_scores
|
|
@one.score.reset
|
|
@two.score.reset
|
|
end
|
|
|
|
def reset_games
|
|
@one.games.reset
|
|
@two.games.reset
|
|
end
|
|
|
|
def total_games
|
|
@one.games.value + @two.games.value
|
|
end
|
|
|
|
def players
|
|
if total_games.even?
|
|
{ red: @one, blue: @two }
|
|
else
|
|
{ red: @two, blue: @one }
|
|
end
|
|
end
|
|
|
|
def scores
|
|
{ red: players[:red].attributes,
|
|
blue: players[:blue].attributes }
|
|
end
|
|
end
|