-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
115 lines (101 loc) Β· 3.24 KB
/
ContentView.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// ContentView.swift
// Memorize
//
// Created by Joe Burdge on 12/26/21.
//
import SwiftUI
struct ContentView: View {
/*
@State var emojis=["π","π","π","π","π","π","π","π","π","π","π","π¬","π΅","π²","π΄","ππΌ","π","π
"]
@State var emojiCount = 18
@State var themePick = 1
*/
@ObservedObject var viewModel: EmojiMemoryGame //this is the "game" model. the syntax here is just to remind us that its generic is "view model". Load the game data.
var body: some View {
ScrollView {
LazyVGrid(columns:
[GridItem(.adaptive(minimum: 68))]) {
ForEach(viewModel.cards) { card in
CardView(card: card)
.aspectRatio(2/3, contentMode: .fit)
.onTapGesture {
viewModel.choose(card)
}
}
}
}
.foregroundColor(.red)
.padding(.horizontal)
.font(.largeTitle)
.padding(.horizontal)
}
/*
var T1: some View {
Button {
themePick=1
emojis=["π","π","π","π","π","π","π","π","π","π","π","π¬","π΅","π²","π΄","ππΌ","π","π
"].shuffled()
emojiCount=emojis.count
} label: {
VStack {
Text("Autos").font(.body)
Image(systemName: "car")
}
}
}
var T2: some View {
Button {
themePick=2
emojis=["β½οΈ","π","π","βΎοΈ","π₯","π","π₯","π±"].shuffled()
emojiCount=emojis.count
} label: {
VStack {
Text("Sports").font(.body)
Image(systemName: "flag")
}
}
}
var T3: some View {
Button {
themePick=3
emojis=["π","π","π","π","π","π","π","π","π«","π","π","π","π₯","π","π₯₯","π₯","π","π₯","π₯¦","πΆ","π₯","π₯","π§","π "].shuffled()
emojiCount=emojis.count
} label: {
VStack {
Text("Foods").font(.body)
//Text("π")
Image(systemName: "scissors")
}
}
}
*/
}
struct CardView: View {
//var content: String
//@State var isFaceUp: Bool = true
let card: MemoryGame<String>.Card
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if card.isFaceUp {
shape.fill(.white)
shape.strokeBorder(lineWidth: 3)
Text(card.content).font(.largeTitle)
} else if card.isMatched {
shape.opacity(0) //0 is fully transparent, 1 is fully opaque
}
else {
shape.fill()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
let game = EmojiMemoryGame()
ContentView(viewModel: game)
.preferredColorScheme(.dark)
ContentView(viewModel: game)
.preferredColorScheme(.light)
}
}