Skip to content

Instantly share code, notes, and snippets.

@ewoudtm
Created March 17, 2017 16:29
Show Gist options
  • Save ewoudtm/208ed2f0fbbad4cefe4325d43927a020 to your computer and use it in GitHub Desktop.
Save ewoudtm/208ed2f0fbbad4cefe4325d43927a020 to your computer and use it in GitHub Desktop.
refactoring TennisGame practice with Vanessa Ho
class TennisGame1
def initialize(name_player_1, name_player_2)
@name_1 = name_player_1
@name_2 = name_player_2
@points_1 = 0
@points_2 = 0
end
def won_point(name_player)
name_player == @name_1 ? @points_1 += 1 : @points_2 += 1
end
def score
if (@points_1 < 4 and @points_2 < 4) and (@points_1 + @points_2 < 6)
score_name = ["Love", "Fifteen", "Thirty", "Forty"]
@points_1 == @points_2 ? score_name[@points_1] + "-All" : score_name[@points_1] + "-" + score_name[@points_2]
elsif (@points_1 == @points_2)
"Deuce"
else
charlie = @points_1 > @points_2 ? @name_1 : @name_2
(@points_1-@points_2).abs == 1 ? "Advantage " + charlie : "Win for " + charlie
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment