I created my first easy card recreation.
https://codewithchris.com/first-swiftui-app-tutorial/
now I wish to add pop up window which can pop up with message “You win” if participant get 15 factors and “you lose” if CPU get 15 level first.
Can somebody please assist me methods to do it?
I’d be glade if there’s some tutorial, so I can do it myself, not simply copy and paste it.
`
import SwiftUI
struct ContentView: View {
@State non-public var playCard = "card5"
@State non-public var cpuCard = "card9"
@State non-public var playerScore = 0
@State non-public var cpuScore = 0
var physique: some View {
ZStack {
Picture("background-plain")
.resizable()
.ignoresSafeArea()
VStack{
Spacer()
Picture("emblem")
HStack{
Spacer()
Picture(playCard)
Spacer()
Picture(cpuCard)
Spacer()
}
Button(motion: {
//reset
playerScore = 0
cpuScore = 0
}, label: {
Picture(systemName: "clock.arrow.circlepath")
.font(.system(dimension: 60))
.foregroundColor(Coloration(.systemRed)) })
Button(motion: {
//gen. random betw. 2 and 14
let playerRand = Int.random(in: 2...14)
let cpuRand = Int.random(in: 2...14)
//Replace the playing cards
playCard = "card" + String(playerRand)
cpuCard = "card" + String(cpuRand)
//Replace the rating
if playerRand > cpuRand {
playerScore += 1
}
else if cpuRand > playerRand {
cpuScore += 1
}
}, label: {
Picture("button")
})
HStack{
Spacer()
VStack{
Textual content("Participant")
.font(.headline)
.padding(.backside, 10.0)
Textual content(String(playerScore))
.font(.largeTitle)
}
Spacer()
VStack{
Textual content("CPU")
.font(.headline)
.padding(.backside, 10.0)
Textual content(String(cpuScore))
.font(.largeTitle)
}
Spacer()
}
.foregroundColor(.white)
Spacer()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
`