-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtennis_match.rb
48 lines (42 loc) · 1.06 KB
/
tennis_match.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class TennisMatch
def TranslateScore(score)
case
when score == 0; 'love'
when score == 1; 'fifteen'
when score == 2; 'thirty'
else 'forty'
end
end
def ScoreOne
return TranslateScore(@ScoreOne)
end
def ScoreTwo
return TranslateScore(@ScoreTwo)
end
def initialize()
@ScoreOne = 0
@ScoreTwo = 0
end
def Score()
case
when (@ScoreOne >= 4 and @ScoreOne - 2 >= @ScoreTwo)
return "player one wins"
when (@ScoreTwo >= 4 and @ScoreTwo - 2 >= @ScoreOne)
return "player two wins"
when (@ScoreOne >= 3 and @ScoreTwo >= 3 and @ScoreOne == @ScoreTwo)
return "deuce"
when (@ScoreOne >= 3 and @ScoreTwo >= 3 and @ScoreOne > @ScoreTwo)
return "advantage player one"
when (@ScoreOne >= 3 and @ScoreTwo >=3 and @ScoreOne < @ScoreTwo)
return "advantage player two"
else
"#{ScoreOne()}-#{ScoreTwo()}"
end
end
def PlayerOneScores()
@ScoreOne = @ScoreOne + 1
end
def PlayerTwoScores()
@ScoreTwo = @ScoreTwo + 1
end
end