diff --git a/Tennis/objc/.idea/workspace.xml b/Tennis/objc/.idea/workspace.xml
index 748a7d90..6619f3c3 100644
--- a/Tennis/objc/.idea/workspace.xml
+++ b/Tennis/objc/.idea/workspace.xml
@@ -4,10 +4,8 @@
-
+
-
-
@@ -20,7 +18,9 @@
-
+
+
+
@@ -61,9 +61,9 @@
-
+
-
+
@@ -99,7 +99,7 @@
-
+
@@ -108,7 +108,7 @@
-
+
@@ -117,7 +117,7 @@
-
+
@@ -126,7 +126,7 @@
-
+
@@ -154,10 +154,11 @@
-
-
+
+
+
@@ -309,20 +310,20 @@
+
-
+
-
+
-
@@ -386,7 +387,9 @@
-
+
+
+
@@ -403,13 +406,6 @@
-
-
-
-
-
-
-
@@ -424,13 +420,6 @@
-
-
-
-
-
-
-
@@ -438,25 +427,39 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
diff --git a/Tennis/objc/Tennis/TennisGame.h b/Tennis/objc/Tennis/TennisGame.h
index 4634840d..38a5ceed 100644
--- a/Tennis/objc/Tennis/TennisGame.h
+++ b/Tennis/objc/Tennis/TennisGame.h
@@ -9,13 +9,16 @@
#import
-@interface TennisGame : NSObject
+@interface TennisGame : NSObject {
+ int score1;
+ int score2;
+}
+
@property(nonatomic, copy) NSString *player1;
@property(nonatomic, copy) NSString *player2;
- (id)initWithPlayer1:(NSString *)player1 player2:(NSString *)player2;
-
-- (void)wonPoint:(NSString *)player;
-
+- (void)wonPoint:(NSString *)playerName;
- (NSString *)score;
+
@end
\ No newline at end of file
diff --git a/Tennis/objc/Tennis/TennisGame.m b/Tennis/objc/Tennis/TennisGame.m
index e4fc9664..64d1e82a 100644
--- a/Tennis/objc/Tennis/TennisGame.m
+++ b/Tennis/objc/Tennis/TennisGame.m
@@ -18,11 +18,14 @@
if (self) {
self.player1 = player1;
self.player2 = player2;
+ score1 = 0;
+ score2 = 0;
}
return self;
}
-- (void)wonPoint:(NSString *)player {}
+- (void)wonPoint:(NSString *)playerName {}
- (NSString *)score { return nil; }
+
@end
\ No newline at end of file
diff --git a/Tennis/objc/Tennis/TennisGame1.m b/Tennis/objc/Tennis/TennisGame1.m
index b08fda8a..5f53e117 100644
--- a/Tennis/objc/Tennis/TennisGame1.m
+++ b/Tennis/objc/Tennis/TennisGame1.m
@@ -9,7 +9,73 @@
#import "TennisGame1.h"
-@implementation TennisGame1 {
+@implementation TennisGame1
+- (void)wonPoint:(NSString *)playerName {
+ if ([playerName isEqualToString:@"player1"])
+ score1 += 1;
+ else
+ score2 += 1;
}
+
+- (NSString *)score {
+ NSString *score = @"";
+ int tempScore=0;
+ if (score1 == score2)
+ {
+ switch (score1)
+ {
+ case 0:
+ score = @"Love-All";
+ break;
+ case 1:
+ score = @"Fifteen-All";
+ break;
+ case 2:
+ score = @"Thirty-All";
+ break;
+ case 3:
+ score = @"Forty-All";
+ break;
+ default:
+ score = @"Deuce";
+ break;
+
+ }
+ }
+ else if (score1>=4 || score2>=4)
+ {
+ int minusResult = score1-score2;
+ if (minusResult==1) score = @"Advantage player1";
+ else if (minusResult ==-1) score = @"Advantage player2";
+ else if (minusResult>=2) score = @"Win for player1";
+ else score = @"Win for player2";
+ }
+ else
+ {
+ for (int i=1; i<3; i++)
+ {
+ if (i==1) tempScore = score1;
+ else { score = [NSString stringWithFormat:@"%@-", score]; tempScore = score2; }
+ switch(tempScore)
+ {
+ case 0:
+ score = [NSString stringWithFormat:@"%@Love", score];
+ break;
+ case 1:
+ score = [NSString stringWithFormat:@"%@Fifteen", score];
+ break;
+ case 2:
+ score = [NSString stringWithFormat:@"%@Thirty", score];
+ break;
+ case 3:
+ score = [NSString stringWithFormat:@"%@Forty", score];
+ break;
+ }
+ }
+ }
+ return score;
+}
+
+
@end
\ No newline at end of file
diff --git a/Tennis/objc/TennisTests/TennisTests.m b/Tennis/objc/TennisTests/TennisTests.m
index 8a21ca6e..0f616d5b 100644
--- a/Tennis/objc/TennisTests/TennisTests.m
+++ b/Tennis/objc/TennisTests/TennisTests.m
@@ -6,6 +6,7 @@
// Copyright (c) 2013 Stefan van den Oord. All rights reserved.
//
+#import
#import "TennisTests.h"
#import "TennisGame1.h"
#import "TennisGame2.h"
@@ -75,18 +76,6 @@
}
- (void)checkAllScoresForGame:(TennisGame *)game {
-
- for (NSArray * score in [TennisTests allScores]) {
-
- player1Score = [score[0] intValue];
- player2Score = [score[1] intValue];
- expectedScore = score[2];
-
- [self checkScoreForGame:game];
- }
-}
-
-- (void)checkScoreForGame:(TennisGame *)game {
int highestScore = MAX(player1Score, player2Score);
for (int i = 0; i < highestScore; i++) {
if (i < player1Score)
@@ -98,18 +87,39 @@
}
- (void)testAllScoresTennisGame1 {
- TennisGame1 * game = [[TennisGame1 alloc] initWithPlayer1:@"player1" player2:@"player2"];
- [self checkAllScoresForGame:game];
+ for (NSArray * score in [TennisTests allScores]) {
+
+ player1Score = [score[0] intValue];
+ player2Score = [score[1] intValue];
+ expectedScore = score[2];
+
+ TennisGame1 * game = [[TennisGame1 alloc] initWithPlayer1:@"player1" player2:@"player2"];
+ [self checkAllScoresForGame:game];
+ }
}
- (void)testAllScoresTennisGame2 {
- TennisGame2 * game = [[TennisGame2 alloc] initWithPlayer1:@"player1" player2:@"player2"];
- [self checkAllScoresForGame:game];
+ for (NSArray * score in [TennisTests allScores]) {
+
+ player1Score = [score[0] intValue];
+ player2Score = [score[1] intValue];
+ expectedScore = score[2];
+
+ TennisGame2 * game = [[TennisGame2 alloc] initWithPlayer1:@"player1" player2:@"player2"];
+ [self checkAllScoresForGame:game];
+ }
}
- (void)testAllScoresTennisGame3 {
- TennisGame3 * game = [[TennisGame3 alloc] initWithPlayer1:@"player1" player2:@"player2"];
- [self checkAllScoresForGame:game];
+ for (NSArray * score in [TennisTests allScores]) {
+
+ player1Score = [score[0] intValue];
+ player2Score = [score[1] intValue];
+ expectedScore = score[2];
+
+ TennisGame3 * game = [[TennisGame3 alloc] initWithPlayer1:@"player1" player2:@"player2"];
+ [self checkAllScoresForGame:game];
+ }
}
@end