Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewController: UIViewController {
- @IBOutlet weak var flipCountLabel: UILabel!
- @IBOutlet var cardButtons: [UIButton]!
- var game = Concentration(numberOfPairsOfCards: cardButtons.count / 2)
- var emojiChoices = ["🎃", "👻", "🎃", "👻"]
- var flipCount = 0 {
- didSet {
- flipCountLabel.text = "Flips: (flipCount)"
- }
- }
- //MARK: - IBActions
- @IBAction func touchCard(_ sender: UIButton) {
- flipCount += 1
- if let cardNumber = cardButtons.index(of: sender) {
- flipCard(withEmoji: emojiChoices[cardNumber], on: sender)
- }
- }
- //MARK: - Methods
- func flipCard(withEmoji emoji: String, on button: UIButton) {
- if button.currentTitle == emoji {
- button.setTitle("", for: .normal)
- button.backgroundColor = #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)
- } else {
- button.setTitle(emoji, for: .normal)
- button.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
- }
- }
- }
- class Concentration {
- var cards = [Card]()
- func chooseCard(at index: Int) {
- }
- init(numberOfPairsOfCards: Int) {
- for _ in 1...numberOfPairsOfCards {
- let card = Card()
- cards += [card, card]
- }
- //TODO: - Shuffle the cards
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement