I created my first easy card recreation.
https://codewithchris.com/first-swiftui-app-tutorial/
now I need 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 tips on how to do it?
I might be glade if there may be some tutorial, so I can do it myself, not simply copy and paste it.
`
import SwiftUI
struct ContentView: View {
@State personal var playCard = "card5"
@State personal var cpuCard = "card9"
@State personal var playerScore = 0
@State personal var cpuScore = 0
var physique: some View {
ZStack {
Picture("background-plain")
.resizable()
.ignoresSafeArea()
VStack{
Spacer()
Picture("brand")
HStack{
Spacer()
Picture(playCard)
Spacer()
Picture(cpuCard)
Spacer()
}
Button(motion: {
//reset
playerScore = 0
cpuScore = 0
}, label: {
Picture(systemName: "clock.arrow.circlepath")
.font(.system(measurement: 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()
}
}
`