Created
June 9, 2015 14:28
-
-
Save anonymous/62290a8f68b9569bcda0 to your computer and use it in GitHub Desktop.
This file contains 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 Game | |
attr_reader :point, :set | |
def initialize | |
@point = {J1:0, J2:0} | |
@set = {J1:0, J2:0} | |
end | |
def point!(player) | |
return "message" if @set.values.max >= 2 | |
@point[player] += 1 | |
if set_win?(player) | |
@point = {J1:0, J2:0} | |
@set[player] += 1 | |
end | |
end | |
def current_match | |
return "message" if @set.values.max >= 2 | |
end | |
def other_player(player) | |
player == :J2 ? :J1 : :J2 | |
end | |
private | |
def set_win?(player) | |
@point[player] == 30 || | |
@point[player] >= 21 && | |
@point[player] - @point[other_player(player)] >= 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment