cs193p – Assignment #1 Extra Task

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

Add a UISlider to your UI which travels through the history of the currently-being- played game’s flips and display it to the user (moving the slider will modify the contents of the text label you created for Required Task #3 to show its state over the course of the game). When you are displaying past flips, you probably want the text label to be grayed out (with alpha) or something so it’s clear that it’s “the past.” Also, you probably don’t want that text label from Required Task #3 to ever be blank (except at the very start of the game, of course). And every time a new flip happens, you probably want to “jump to the present” in the slider. Implementing this extra credit item will require you to familiarize yourself with UISlider’s API and to add a data structure to your Controller to keep track of the history. It can be implemented in fewer than a dozen lines of code.

Add a new property to hold the history information and initialize it using its getter:
Continue reading “cs193p – Assignment #1 Extra Task”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #7

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

Make the back of the card be an image (UIImage) rather than an Apple logo.

Add an image to your project (e.g. cardback.png), create an UIImage from it, use it when the back of the card is shown, and remove it when it is face up:

- (void)updateUI
{
    UIImage *cardBackImage = [UIImage imageNamed:@"cardback.png"];
    
    for (UIButton *cardButton in self.cardButtons) {
        ...
        if (!card.isFaceUp) {
            [cardButton setImage:cardBackImage 
                        forState:UIControlStateNormal];            
        } else {
            [cardButton setImage:nil forState:UIControlStateNormal];
        }
    }
    ...
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #6

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

Disable the game play mode control (i.e. the UISwitch or UISegmentedControl from Required Task #5) when flipping starts and re-enable it when a re-deal happens (i.e. the Deal button is pressed).

Disable the control element in flipCard:

- (IBAction)flipCard:(UIButton *)sender
{
    self.cardModeSelector.enabled = NO;
    ...
}

… and enable it in dealButtonPressed:

- (IBAction)dealButtonPressed:(UIButton *)sender {
    ...
    self.cardModeSelector.enabled = YES;
    ...
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #5

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

Drag out a switch (UISwitch) or a segmented control (UISegmentedControl) into your View somewhere which controls whether the game matches two cards at a time or three cards at a time (i.e. it sets “2-card-match mode” vs. “3-card-match mode”). Give the user appropriate points depending on how difficult the match is to accomplish.

At the moment (end of lecture #3) the match: method PlayingCard model only supports matches with a single other card. Instead of checking if there is a single card, check if there are other cards (one or more). To adjust the score (3-card matches are more worth then 2-card matches) change the score calculation to add the bonus for each matching card (which might not be accurate concerning the actual odds, …):
Continue reading “cs193p – Assignment #1 Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #4

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

Add a button called “Deal” which will re-deal all of the cards (i.e. start a new game). It should reset the score (and anything else in the UI that makes sense). In a real game, we’d probably want to ask the user if he or she is “sure” before aborting the game in process to re-deal, but for this assignment, you can assume the user always knows what he or she is doing when they hit this button.

Create a new button in storyboard:

cs193p - assignment #1 task #4
cs193p – assignment #1 task #4

Continue reading “cs193p – Assignment #1 Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #3

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

Add a text label somewhere which desribes the results of the last flip. Examples: “Matched J♥ & J♠ for 4 points” or “6♦ and J♣ don’t match! 2 point penalty!” and simply “Flipped up 8♦” if there is no match or mismatch.

The information needed to display is already inside the model. Analogue to the score create a new property to hold the text string, and set it in flipCardAtIndex:
Continue reading “cs193p – Assignment #1 Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #2

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

Add 4 cards to the game (for a total of 16).

Start by selecting one row of cards, copy and place them on your storyboard:

cs193p - assignment #1 task #2
cs193p – assignment #1 task #2

Now connect all four new cards to the outlet connection by control dragging each of them to:

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons;

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail