cs193p-memorize/Memorize/MemoryGame.swift
Ching 87b6465e68 feat(view, viewmodel): 新增model 和对应的 viewmodel
新增model 和对应的 viewmodel

Signed-off-by: Ching <loooching@gmail.com>
2023-02-12 18:28:14 +08:00

32 lines
692 B
Swift

//
// MemoryGame.swift
// Memorize
//
// Created by ching on 2023/2/12.
//
import Foundation
// model
struct MemoryGame<CardContent> {
private(set) var cards: [Card]
func choose(_ card: Card) {}
init(numberOfPairsOfCards: Int, createCardContent: (Int) -> CardContent) {
cards = [Card]()
//
for pairIndex in 0 ..< numberOfPairsOfCards {
let content: CardContent = createCardContent(pairIndex)
cards.append(Card(content: content))
cards.append(Card(content: content))
}
}
struct Card {
var isFaceUp: Bool = false
var isMatched: Bool = false
var content: CardContent
}
}