-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemorizeGame.swift
42 lines (32 loc) · 1.04 KB
/
MemorizeGame.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// MemorizeGame.swift
// Memorize
//
// Created by Kynji Kyle Niño A. Pepito on 9/21/23.
//
import Foundation
struct MemoryGame<CardContent> where CardContent: Equatable {
private(set) var cards: Array<Card>
init (numberOfPairs: Int, faceFactory: (Int) -> CardContent) {
cards = []
for pairIndex in 0..<max(2, numberOfPairs) {
let face: CardContent = faceFactory(pairIndex)
cards.append(Card(face: face, id: "\(pairIndex)a"))
cards.append(Card(face: face, id: "\(pairIndex)b"))
}
}
func choose(_ card: Card) {
}
mutating func shuffle() {
cards.shuffle()
}
struct Card: Equatable, Identifiable, CustomDebugStringConvertible {
var debugDescription: String {
return "\(id): \(face) \(isFaceUp ? "up" : "down") \(isMatched ? "matchete" : "")"
}
var isFaceUp: Bool = true
var isMatched: Bool = false
let face: CardContent
var id: String
}
}