SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ViewController: UIViewController {
  2.  
  3.     @IBOutlet weak var flipCountLabel: UILabel!
  4.     @IBOutlet var cardButtons: [UIButton]!
  5.  
  6.     var game = Concentration(numberOfPairsOfCards: cardButtons.count / 2)
  7.  
  8.     var emojiChoices = ["🎃", "👻", "🎃", "👻"]
  9.  
  10.     var flipCount = 0 {
  11.         didSet {
  12.             flipCountLabel.text = "Flips: (flipCount)"
  13.         }
  14.     }
  15.  
  16.     //MARK: - IBActions
  17.     @IBAction func touchCard(_ sender: UIButton) {
  18.         flipCount += 1
  19.         if let cardNumber = cardButtons.index(of: sender) {
  20.             flipCard(withEmoji: emojiChoices[cardNumber], on: sender)
  21.         }
  22.     }
  23.  
  24.  
  25.     //MARK: - Methods
  26.     func flipCard(withEmoji emoji: String, on button: UIButton) {
  27.         if button.currentTitle == emoji {
  28.             button.setTitle("", for: .normal)
  29.             button.backgroundColor = #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)
  30.         } else {
  31.             button.setTitle(emoji, for: .normal)
  32.             button.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  33.         }
  34.     }
  35.  
  36. }
  37.      
  38. class Concentration {
  39.     var cards = [Card]()
  40.  
  41.     func chooseCard(at index: Int) {
  42.  
  43.     }
  44.  
  45.     init(numberOfPairsOfCards: Int) {
  46.         for _ in 1...numberOfPairsOfCards {
  47.             let card = Card()
  48.             cards += [card, card]
  49.         }
  50.         //TODO: - Shuffle the cards
  51.  
  52.     }
  53.  
  54.  
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top