cs193p – Assignment #2 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add third tab to track the user’s scores. It should be clear which scores were playing card match games and which scores were Set card match games.

The tab has already been implemented during lecture #5.

To be able to separate the scores of the different games, it is necessary to another property which can provide this information:

@property (strong, nonatomic) NSString *gameType;


… which needs to be set at the appropriate places:

#define GAME_KEY @"Game"
- (id)initFromPropertyList:(id)plist
{
            ...
            _gameType = resultDictionary[GAME_KEY];
            ...
}
- (id)asPropertyList
{
    return @{ ..., GAME_KEY : self.gameType };
}

The property is set during initialization of the the game-results property in the view controllers:

//  SetGameViewController.m
@synthesize gameResult = _gameResult;
- (GameResult *)gameResult
{
    if (!_gameResult) _gameResult = [[GameResult alloc] init];
    _gameResult.gameType = @"Set Game";
    return _gameResult;
}

//  CardGameViewController.m
- (GameResult *)gameResult
{
    if (!_gameResult) _gameResult = [[GameResult alloc] init];
    _gameResult.gameType = @"Card Matching";
    return _gameResult;
}

The new property is used in the game-results view controller. Note that previously stored scores do not know yet which game type they belong to:

- (void)updateUI
{
        ...
        displayText = [displayText stringByAppendingFormat:@"%@: %d, (%@, %gs)\n",
                       result.gameType ? result.gameType : @"Card Matching",
                       result.score,
                       [NSDateFormatter localizedStringFromDate:result.end
                                                      dateStyle:NSDateFormatterShortStyle
                                                      timeStyle:NSDateFormatterShortStyle],
                       round(result.duration)];
        ...
}

The complete code is available on github.

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!