cs193p – Assignment #2 Task #2

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

Don’t violate any of the Required Tasks from Assignment 1 in the playing card game tab (in other words, don’t break any non-extra-credit features from last week). The only exception is that your playing card game is required to be a 2-card-match-only game this week, so you can remove the switch or segmented control you added for Required Task #5 in Assignment 1. Your Set game is a 3-card matching game.

Start by moving “everything” which is not matching-card specific to common game view controller. Note that all property declarations need to be in the .h file as well as those methods you need to access from your subclasses and from storyboard (e.g. action methods).

The only method which stays (or is actually overwritten) in the card-game view controller is the getter for game with the lazy instantiation which uses the playing-card deck. Note, that to be able the instance variable in the sub class it is necessary to synthesize it. To make sure that the matching-card game uses the 2-card mode remove the selector in story board and set it explicitly (even if the default value would be 2):

@synthesize game = _game;
- (CardMatchingGame *)game
{
    if (!_game) {
        _game = [[CardMatchingGame alloc] initWithCardCount:[self.cardButtons count]
                                                  usingDeck:[[PlayingCardDeck alloc] init]];
        self.game.numberOfMatchingCards = 2;
    }
    return _game;
}

For the new set game create new models for SetCard as sub class of Card and SetCardDeck as sub class of Deck, which both will stay empty for now but are used for the set-game view controller. At the same time the match mode is set to 3 cards:

@synthesize game = _game;
- (CardMatchingGame *)game
{
    if (!_game) {
        _game = [[CardMatchingGame alloc] initWithCardCount:[self.cardButtons count]
                                                  usingDeck:[[SetCardDeck alloc] init]];
        self.game.numberOfMatchingCards = 3;
    }
    return _game;
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.