Skip to content

Instantly share code, notes, and snippets.

@jgilmour
Last active December 12, 2015 07:09
Show Gist options
  • Save jgilmour/4734621 to your computer and use it in GitHub Desktop.
Save jgilmour/4734621 to your computer and use it in GitHub Desktop.
CS 193P iPhone Application Development - Homework for Lecture 2 - Matchismo
//
// CardGameViewController.m
// Matchismo
//
// Created by Josh Gilmour on 2/6/13.
// Copyright (c) 2013 Josh Gilmour. All rights reserved.
//
#import "CardGameViewController.h"
// addition for lecture 2
// import in our playing card deck
#import "PlayingCardDeck.h"
@interface CardGameViewController ()
@property (weak, nonatomic) IBOutlet UILabel *flipsLabel;
@property (nonatomic) int flipCount;
// addition for lecture 2
// add a propery *cardDeck
@property (strong, nonatomic) PlayingCardDeck *cardDeck;
@end
@implementation CardGameViewController
// addition from lecture 2
// lazy instantiation for cardDeck
- (PlayingCardDeck *)cardDeck {
if (!_cardDeck) _cardDeck = [[PlayingCardDeck alloc] init];
return _cardDeck;
}
- (void)setFlipCount:(int)flipCount
{
_flipCount = flipCount;
self.flipsLabel.text = [NSString stringWithFormat:@"Flips %d", self.flipCount];
NSLog(@"flips updated to %d", self.flipCount);
}
- (IBAction)flipCard:(UIButton *)sender
{
// addition for lecture 2
// using lecture 2 slides (page 110), there is a hint about
// setTitle:(NSString *)title forState:(UIControlStateSelected).
// ... So we use it.
if (!sender.isSelected) [sender setTitle:[self.cardDeck drawRandomCard].contents
forState:UIControlStateSelected];
sender.selected = !sender.isSelected;
self.flipCount++;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment