mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Successfully implemented TennisGame2
This commit is contained in:
parent
1ec82a56eb
commit
ea3e95e55f
@ -2,10 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3432493f-5b19-44ab-868c-f539ff9f9548" name="Default" comment="">
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Tennis/TennisGame.h" afterPath="$PROJECT_DIR$/Tennis/TennisGame.h" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Tennis/TennisGame.m" afterPath="$PROJECT_DIR$/Tennis/TennisGame.m" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Tennis/TennisGame1.m" afterPath="$PROJECT_DIR$/Tennis/TennisGame1.m" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/TennisTests/TennisTests.m" afterPath="$PROJECT_DIR$/TennisTests/TennisTests.m" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Tennis/TennisGame2.m" afterPath="$PROJECT_DIR$/Tennis/TennisGame2.m" />
|
||||
</list>
|
||||
<ignored path="Tennis.iws" />
|
||||
<ignored path=".idea/workspace.xml" />
|
||||
@ -21,6 +18,7 @@
|
||||
<file path="/TennisGame.m" changelist="3432493f-5b19-44ab-868c-f539ff9f9548" time="1370020624289" ignored="false" />
|
||||
<file path="/TennisGame1.m" changelist="3432493f-5b19-44ab-868c-f539ff9f9548" time="1370020207784" ignored="false" />
|
||||
<file path="/TennisGame.h" changelist="3432493f-5b19-44ab-868c-f539ff9f9548" time="1370019947680" ignored="false" />
|
||||
<file path="/TennisGame2.m" changelist="3432493f-5b19-44ab-868c-f539ff9f9548" time="1370021340497" ignored="false" />
|
||||
<option name="TRACKING_ENABLED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -58,10 +56,10 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="TennisTests.m" pinned="false" current="true" current-in-tab="true">
|
||||
<file leaf-file-name="TennisTests.m" pinned="false" current="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/TennisTests/TennisTests.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="85" column="30" selection-start="2316" selection-end="2316" vertical-scroll-proportion="0.3321859">
|
||||
<state line="85" column="30" selection-start="2316" selection-end="2316" vertical-scroll-proportion="0.0">
|
||||
<folding>
|
||||
<element signature="e#144#183#0" expanded="true" />
|
||||
</folding>
|
||||
@ -69,10 +67,10 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="TennisGame2.m" pinned="false" current="false" current-in-tab="false">
|
||||
<file leaf-file-name="TennisGame2.m" pinned="false" current="true" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame2.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
|
||||
<state line="136" column="22" selection-start="2901" selection-end="2901" vertical-scroll-proportion="0.8450947">
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
@ -159,6 +157,7 @@
|
||||
<option value="$PROJECT_DIR$/Tennis/TennisGame.h" />
|
||||
<option value="$PROJECT_DIR$/Tennis/TennisGame.m" />
|
||||
<option value="$PROJECT_DIR$/TennisTests/TennisTests.m" />
|
||||
<option value="$PROJECT_DIR$/Tennis/TennisGame2.m" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@ -406,13 +405,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame2.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame2.h">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="12" column="35" selection-start="272" selection-end="272" vertical-scroll-proportion="0.0">
|
||||
@ -420,13 +412,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame3.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="13" column="0" selection-start="233" selection-end="233" vertical-scroll-proportion="0.0">
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame1.h">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="12" column="28" selection-start="265" selection-end="265" vertical-scroll-proportion="0.0">
|
||||
@ -457,13 +442,27 @@
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/TennisTests/TennisTests.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="85" column="30" selection-start="2316" selection-end="2316" vertical-scroll-proportion="0.3321859">
|
||||
<state line="85" column="30" selection-start="2316" selection-end="2316" vertical-scroll-proportion="0.0">
|
||||
<folding>
|
||||
<element signature="e#144#183#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame3.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="13" column="0" selection-start="233" selection-end="233" vertical-scroll-proportion="0.0">
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Tennis/TennisGame2.m">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state line="136" column="22" selection-start="2901" selection-end="2901" vertical-scroll-proportion="0.8450947">
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
||||
@ -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
|
||||
Loading…
Reference in New Issue
Block a user