Skip to content

Commit

Permalink
refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanemat committed Jun 26, 2011
1 parent ffd01b0 commit b41fe7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions ObjCStudy/Bowling2.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
-(void)roll: (int) pins;
-(int) score;
-(BOOL)isStrike: (int) rollIndex;
-(BOOL)isSpare:(int)rollIndex;
-(int)sumOfFrame:(int)rollIndex;
-(int)strikeBonus:(int)rollIndex;
-(BOOL)isSpare: (int) rollIndex;
-(int) sumOfFrame: (int) rollIndex;
-(int) strikeBonus: (int) rollIndex;
-(int) spareBonus: (int) rollIndex;

@end
14 changes: 8 additions & 6 deletions ObjCStudy/Bowling2.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ -(int)score
{
if ([self isStrike: rollIndex])
{
result += [self sumOfFrame: rollIndex];
result += [self strikeBonus:rollIndex];
result += [self sumOfFrame: rollIndex] + [self strikeBonus: rollIndex];
rollIndex += 1;
}
else if ([self isSpare: rollIndex])
{
result += [self sumOfFrame: rollIndex];
result += [[store objectAtIndex: rollIndex + 2] intValue];
result += [self sumOfFrame: rollIndex] + [self spareBonus: rollIndex];
rollIndex += 2;
}
else
Expand Down Expand Up @@ -74,8 +72,12 @@ -(int)sumOfFrame: (int) rollIndex
return([[store objectAtIndex: rollIndex] intValue] + [[store objectAtIndex: rollIndex + 1] intValue]);
}
}
-(int)strikeBonus:(int)rollIndex
-(int)strikeBonus: (int) rollIndex
{
return([[store objectAtIndex: rollIndex + 1] intValue] + [[store objectAtIndex: rollIndex + 2] intValue]);
}
-(int)spareBonus: (int) rollIndex
{
return [[store objectAtIndex: rollIndex + 1] intValue] + [[store objectAtIndex: rollIndex + 2] intValue];
return([[store objectAtIndex: rollIndex + 2] intValue]);
}
@end

0 comments on commit b41fe7d

Please sign in to comment.