-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentView.swift
More file actions
88 lines (74 loc) · 2.66 KB
/
ContentView.swift
File metadata and controls
88 lines (74 loc) · 2.66 KB
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
import SwiftUI
struct ContentView: View {
@State private var playerCard = "card6"
@State private var cpuCard = "card7"
@State private var playerScore = 0
@State private var cpuScore = 0
var body: some View {
ZStack {
Image("background-cloth")
.ignoresSafeArea()
VStack {
Spacer()
Image("logo")
Spacer()
HStack {
Spacer()
Image(playerCard)
Spacer()
Image(cpuCard)
Spacer()
}
Spacer()
Button(action: {
// Generate a random number between 2 and 14
let playerRand = Int.random(in: 2...14)
let cpuRand = Int.random(in: 2...14)
// Update the cards
playerCard = "card" + String(playerRand)
cpuCard = "card" + String(cpuRand)
// Update the score
if playerRand > cpuRand {
playerScore += 1
}
else if cpuRand > playerRand {
cpuScore += 1
}
}, label: {
Image("button")
})
Spacer()
HStack {
Spacer()
VStack {
Text("Player")
.font(.headline)
.foregroundColor(Color.white)
.padding(.bottom, 10.0)
Text(String(playerScore))
.font(.largeTitle)
.foregroundColor(Color.white)
}
Spacer()
VStack {
Text("CPU")
.font(.headline)
.fontWeight(.bold)
.foregroundColor(Color.white)
.padding(.bottom, 10.0)
Text(String(cpuScore))
.font(.largeTitle)
.foregroundColor(Color.white)
}
Spacer()
}
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}