Please note, this blog entry is from a previous course. You might want to check out the current one.
Knowing how to find Sets in the remaining cards also would allow you to let the user cheat. Have a button that will show them a Set (if available). It’s up to you how you want to show it, but maybe some little indicator (a star or something) on each of the 3 cards?
Add a new button to storyboard:
… and link to an action which stores a possible combination in a new property:
- (IBAction)touchCheatButton:(UIButton *)sender { self.cheatCards = [self.game findCombination]; [self updateUI]; }
Define that property as array:
@property (strong, nonatomic) NSArray *cheatCards;
Reset the array, when a new deck is dealt:
- (IBAction)touchDealButton:(UIButton *)sender { ... self.cheatCards = nil; ... }
When updating a card first remove all image subviews (previously added star images). If the card is one of the current “cheat”, add a small star in the top left corner of the card:
#define CHEATSTARSIZE 0.2 #define CHEETSTAROFFSET 0.1 - (void)updateUI { ... } else { cardView = self.cardViews[viewIndex]; if (!card.matched) { [self updateView:cardView forCard:card]; for (UIView *subView in cardView.subviews) { if ([subView isKindOfClass:[UIImageView class]]) { [subView removeFromSuperview]; } } if ([self.cheatCards containsObject:card]) { UIImage *image = [UIImage imageNamed:@"star.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; CGFloat min = cardView.bounds.size.width; if (cardView.bounds.size.height < min) min = cardView.bounds.size.height; imageView.frame = CGRectMake(min * CHEETSTAROFFSET, min * CHEETSTAROFFSET, min * CHEATSTARSIZE, min * CHEATSTARSIZE); [cardView addSubview:imageView]; } } else { ... }
Using an image like above is a quick solution, but might add unwanted aliasing effects. Creating the star “by hand” using bezier curves might produce a nicer looking result. If you go for the image solution, don’t forget to add that image to your image assets.
The complete code is available on github.