cs193p – Assignment #2 Task #4

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

Choose reasonable amounts to award the user for successfully finding a set (or incorrectly picking cards which are not a set).

Create three new properties for CardMatchingGame to replace the previously used constants:

@property (nonatomic) int matchBonus;
@property (nonatomic) int mismatchPenalty;
@property (nonatomic) int flipCost;


In order to do not have to change the previous code for the matching card game, use their getters to initialize them with the values of the constants:

- (int)matchBonus
{
    if (!_matchBonus) _matchBonus = 4;
    return _matchBonus;
}

- (int)mismatchPenalty
{
    if (!_mismatchPenalty) _mismatchPenalty = 2;
    return _mismatchPenalty;
}

- (int)flipCost
{
    if (!_flipCost) _flipCost = 1;
    return _flipCost;
}

… and use the new properties instead of the constants:

- (void)flipCardAtIndex:(NSUInteger)index
{
                    ...
                    self.score += matchScore * self.matchBonus;
                         ...
                         matchScore * self.matchBonus];
                    ...                    
                    self.score -= self.mismatchPenalty;
                         ...
                         self.mismatchPenalty];
            ...
            self.score -= self.flipCost;
            ...
}

Because the matching method uses a score of 4 which might provide a quite high end score if you use a match bonus of 4, you can reduce the bonus in the getter of game:

- (CardMatchingGame *)game
{
        ...
        self.game.matchBonus = 2;
        ...
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.