-
Notifications
You must be signed in to change notification settings - Fork 9
/
tennis_game_2.rb
129 lines (120 loc) · 2.54 KB
/
tennis_game_2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class TennisGame2
def initialize(player1_name, player2_name)
@player1_name = player1_name
@player2_name = player2_name
@p1points = 0
@p2points = 0
end
def won_point(player_name)
if player_name == @player1_name
p1Score()
else
p2Score()
end
end
def score
result = ""
if (@p1points == @p2points and @p1points < 3)
if (@p1points==0)
result = "Love"
end
if (@p1points==1)
result = "Fifteen"
end
if (@p1points==2)
result = "Thirty"
end
result += "-All"
end
if (@p1points==@p2points and @p1points>2)
result = "Deuce"
end
p1res = ""
p2res = ""
if (@p1points > 0 and @p2points==0)
if (@p1points==1)
p1res = "Fifteen"
end
if (@p1points==2)
p1res = "Thirty"
end
if (@p1points==3)
p1res = "Forty"
end
p2res = "Love"
result = p1res + "-" + p2res
end
if (@p2points > 0 and @p1points==0)
if (@p2points==1)
p2res = "Fifteen"
end
if (@p2points==2)
p2res = "Thirty"
end
if (@p2points==3)
p2res = "Forty"
end
p1res = "Love"
result = p1res + "-" + p2res
end
if (@p1points>@p2points and @p1points < 4)
if (@p1points==2)
p1res="Thirty"
end
if (@p1points==3)
p1res="Forty"
end
if (@p2points==1)
p2res="Fifteen"
end
if (@p2points==2)
p2res="Thirty"
end
result = p1res + "-" + p2res
end
if (@p2points>@p1points and @p2points < 4)
if (@p2points==2)
p2res="Thirty"
end
if (@p2points==3)
p2res="Forty"
end
if (@p1points==1)
p1res="Fifteen"
end
if (@p1points==2)
p1res="Thirty"
end
result = p1res + "-" + p2res
end
if (@p1points > @p2points and @p2points >= 3)
result = "Advantage " + @player1_name
end
if (@p2points > @p1points and @p1points >= 3)
result = "Advantage " + @player2_name
end
if (@p1points>=4 and @p2points>=0 and (@p1points-@p2points)>=2)
result = "Win for " + @player1_name
end
if (@p2points>=4 and @p1points>=0 and (@p2points-@p1points)>=2)
result = "Win for " + @player2_name
end
result
end
def setp1Score(number)
(0..number).each do |i|
p1Score()
end
end
def setp2Score(number)
(0..number).each do |i|
p2Score()
end
end
def p1Score
@p1points +=1
end
def p2Score
@p2points +=1
end
end