From ea3e95e55fe2ca806dcb15e8bd4a5895e7e18232 Mon Sep 17 00:00:00 2001 From: Stefan van den Oord Date: Fri, 31 May 2013 19:29:25 +0200 Subject: [PATCH] Successfully implemented TennisGame2 --- Tennis/objc/.idea/workspace.xml | 45 ++++++----- Tennis/objc/Tennis/TennisGame2.m | 125 +++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 23 deletions(-) diff --git a/Tennis/objc/.idea/workspace.xml b/Tennis/objc/.idea/workspace.xml index 6619f3c3..597337eb 100644 --- a/Tennis/objc/.idea/workspace.xml +++ b/Tennis/objc/.idea/workspace.xml @@ -2,10 +2,7 @@ - - - - + @@ -21,6 +18,7 @@ + - + - + @@ -69,10 +67,10 @@ - + - + @@ -159,6 +157,7 @@ @@ -406,13 +405,6 @@ - - - - - - - @@ -420,13 +412,6 @@ - - - - - - - @@ -457,13 +442,27 @@ - + + + + + + + + + + + + + + + diff --git a/Tennis/objc/Tennis/TennisGame2.m b/Tennis/objc/Tennis/TennisGame2.m index cd99b536..e08b02ef 100644 --- a/Tennis/objc/Tennis/TennisGame2.m +++ b/Tennis/objc/Tennis/TennisGame2.m @@ -10,6 +10,131 @@ @implementation TennisGame2 { + int P1point; + NSString *P1res; + int P2point; + NSString *P2res; +} + +- (NSString *)score { + NSString *score = @""; + if (P1point == P2point && P1point < 4) + { + if (P1point==0) + score = @"Love"; + if (P1point==1) + score = @"Fifteen"; + if (P1point==2) + score = @"Thirty"; + if (P1point==3) + score = @"Forty"; + score = [NSString stringWithFormat:@"%@-All", score]; + } + if (P1point==P2point && P1point>3) + score = @"Deuce"; + + if (P1point > 0 && P2point==0) + { + if (P1point==1) + P1res = @"Fifteen"; + if (P1point==2) + P1res = @"Thirty"; + if (P1point==3) + P1res = @"Forty"; + + P2res = @"Love"; + score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; + } + if (P2point > 0 && P1point==0) + { + if (P2point==1) + P2res = @"Fifteen"; + if (P2point==2) + P2res = @"Thirty"; + if (P2point==3) + P2res = @"Forty"; + + P1res = @"Love"; + score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; + } + + if (P1point>P2point && P1point < 4) + { + if (P1point==2) + P1res=@"Thirty"; + if (P1point==3) + P1res=@"Forty"; + if (P2point==1) + P2res=@"Fifteen"; + if (P2point==2) + P2res=@"Thirty"; + score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; + } + if (P2point>P1point && P2point < 4) + { + if (P2point==2) + P2res=@"Thirty"; + if (P2point==3) + P2res=@"Forty"; + if (P1point==1) + P1res=@"Fifteen"; + if (P1point==2) + P1res=@"Thirty"; + score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; + } + + if (P1point > P2point && P2point >= 3) + { + score = @"Advantage player1"; + } + + if (P2point > P1point && P1point >= 3) + { + score = @"Advantage player2"; + } + + if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2) + { + score = @"Win for player1"; + } + if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2) + { + score = @"Win for player2"; + } + return score; +} + +-(void)setP1Score:(int)number { + + for (int i = 0; i < number; i++) + { + [self P1Score]; + } } + +- (void)setP2Score:(int)number { + + for (int i = 0; i < number; i++) + { + [self P2Score]; + } + +} + +- (void)P1Score { + P1point++; +} + +- (void)P2Score { + P2point++; +} + +- (void)wonPoint:(NSString *)playerName { + if ([playerName isEqualToString:@"player1"]) + [self P1Score]; + else + [self P2Score]; +} + @end \ No newline at end of file