cs193p – Assignment #4 Task #3

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

When a Set match is successfully chosen, the matching cards should now be removed from the game (not just blanked out or grayed out, but removed from the UI entirely).

When looping of the cards check if it matches, if it does remove it from the super view and form the view array. Before creating a new view check, if the cared has already matched earlier, to avoid recreating its view:

- (void)updateUI
{
        ...
        if (viewIndex == NSNotFound) {
            if (!card.matched) {
                ...
            }
        } else {
            cardView = self.cardViews[viewIndex];
            if (!card.matched) {
                [self updateView:cardView forCard:card];
            } else {
                [cardView removeFromSuperview];
                [self.cardViews removeObject:cardView];
            }
        }
        ...
}

The complete code is available on github.

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

6 thoughts on “cs193p – Assignment #4 Task #3”

  1. I am wondering when the view redraws everything just after two cards are matched?

    – (void)updateView:(UIView *)view forCard:(Card *)card
    method would not be triggered after two cards are matched, I think.

    1. When a card is matched and removed, I remove the card from the super view. Why should I want to redraw the card when I do that? Concerning the other cards, they are redrawn, when changing their size.

      1. Why should I want to redraw the card when I do that?

        ah, you don’t need to. I was wondering when runtime remove these two matched card. because [cardView removeFromSuperview]; will not remove the card immediately from our sight.

        I mean it remove these two cards after the updateUI method finished.

  2. Only Set cards should disappear from the view according to the task, the playing cards not. So this code should be placed in the updateView of the SetCardGameViewController right? Along with moving the “view.alpha = card.matched ? 0.6 : 1.0;” to the PlayingCardGameViewController?

Leave a Reply

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