10
10
11
11
12
12
@implementation TennisGame2 {
13
+ int P1point;
14
+ NSString *P1res;
15
+ int P2point;
16
+ NSString *P2res;
17
+ }
18
+
19
+ - (NSString *)score {
20
+ NSString *score = @" " ;
21
+ if (P1point == P2point && P1point < 4 )
22
+ {
23
+ if (P1point==0 )
24
+ score = @" Love" ;
25
+ if (P1point==1 )
26
+ score = @" Fifteen" ;
27
+ if (P1point==2 )
28
+ score = @" Thirty" ;
29
+ if (P1point==3 )
30
+ score = @" Forty" ;
31
+ score = [NSString stringWithFormat: @" %@ -All" , score];
32
+ }
33
+ if (P1point==P2point && P1point>3 )
34
+ score = @" Deuce" ;
35
+
36
+ if (P1point > 0 && P2point==0 )
37
+ {
38
+ if (P1point==1 )
39
+ P1res = @" Fifteen" ;
40
+ if (P1point==2 )
41
+ P1res = @" Thirty" ;
42
+ if (P1point==3 )
43
+ P1res = @" Forty" ;
44
+
45
+ P2res = @" Love" ;
46
+ score = [NSString stringWithFormat: @" %@ -%@ " , P1res, P2res];
47
+ }
48
+ if (P2point > 0 && P1point==0 )
49
+ {
50
+ if (P2point==1 )
51
+ P2res = @" Fifteen" ;
52
+ if (P2point==2 )
53
+ P2res = @" Thirty" ;
54
+ if (P2point==3 )
55
+ P2res = @" Forty" ;
56
+
57
+ P1res = @" Love" ;
58
+ score = [NSString stringWithFormat: @" %@ -%@ " , P1res, P2res];
59
+ }
60
+
61
+ if (P1point>P2point && P1point < 4 )
62
+ {
63
+ if (P1point==2 )
64
+ P1res=@" Thirty" ;
65
+ if (P1point==3 )
66
+ P1res=@" Forty" ;
67
+ if (P2point==1 )
68
+ P2res=@" Fifteen" ;
69
+ if (P2point==2 )
70
+ P2res=@" Thirty" ;
71
+ score = [NSString stringWithFormat: @" %@ -%@ " , P1res, P2res];
72
+ }
73
+ if (P2point>P1point && P2point < 4 )
74
+ {
75
+ if (P2point==2 )
76
+ P2res=@" Thirty" ;
77
+ if (P2point==3 )
78
+ P2res=@" Forty" ;
79
+ if (P1point==1 )
80
+ P1res=@" Fifteen" ;
81
+ if (P1point==2 )
82
+ P1res=@" Thirty" ;
83
+ score = [NSString stringWithFormat: @" %@ -%@ " , P1res, P2res];
84
+ }
85
+
86
+ if (P1point > P2point && P2point >= 3 )
87
+ {
88
+ score = @" Advantage player1" ;
89
+ }
90
+
91
+ if (P2point > P1point && P1point >= 3 )
92
+ {
93
+ score = @" Advantage player2" ;
94
+ }
95
+
96
+ if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2 )
97
+ {
98
+ score = @" Win for player1" ;
99
+ }
100
+ if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2 )
101
+ {
102
+ score = @" Win for player2" ;
103
+ }
104
+ return score;
105
+ }
106
+
107
+ -(void )setP1Score : (int )number {
108
+
109
+ for (int i = 0 ; i < number; i++)
110
+ {
111
+ [self P1Score ];
112
+ }
13
113
14
114
}
115
+
116
+ - (void )setP2Score : (int )number {
117
+
118
+ for (int i = 0 ; i < number; i++)
119
+ {
120
+ [self P2Score ];
121
+ }
122
+
123
+ }
124
+
125
+ - (void )P1Score {
126
+ P1point++;
127
+ }
128
+
129
+ - (void )P2Score {
130
+ P2point++;
131
+ }
132
+
133
+ - (void )wonPoint : (NSString *)playerName {
134
+ if ([playerName isEqualToString: @" player1" ])
135
+ [self P1Score ];
136
+ else
137
+ [self P2Score ];
138
+ }
139
+
15
140
@end
0 commit comments