cs193p – Assignment #3 Task #1 & #2

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

Create an application that plays both the Set game (single player) in one tab and the Playing Card matching game in another.

… the current version does already do that, just make sure not to break anything in the following tasks

You must use polymorphism to design your Controllers for the two games (i.e. you must have a (probably abstract) base card game Controller class and your Set game and Playing Card game Controllers must be subclasses thereof).

… which we actually have done already in the last assignment. But we can still clean up a little bit, e.g by removing the access to the direct access of game and gameResult by adding additional abstract properties:

//  GameViewController.h
@property (nonatomic) NSUInteger numberOfMatchingCards;
@property (strong, nonatomic) NSString *gameType;

//  GameViewController.m
- (CardMatchingGame *)game
{
        ...
        _game.numberOfMatchingCards = self.numberOfMatchingCards;
        ...
}

- (GameResult *)gameResult
{
    ...
    _gameResult.gameType = self.gameType;
    ...
}

… and use them in the other controllers:

//  CardGameViewController.m
- (NSUInteger)numberOfMatchingCards
{
    return 2;
}

- (NSString *)gameType
{
    return @"Card Matching";
}

//  SetGameViewController.m
- (NSUInteger)numberOfMatchingCards
{
    return 3;
}

- (NSString *)gameType
{
    return @"Set Game";
}

Note that because we actually did this before the controllers are now named slightly different then the ones from the demo during the lecture.

The complete code is available on github.

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *