Sorry for the dumb question, I was trying to write a SwiftUI game that displays an "X" when the user taps the screen during their turn, and an "O" if it's not said user's turn. This is the part of my code that's giving me problems (I already declared all the variables I'm using in another part of my code I won't send here as it would be pretty useless):
ZStack(content: {
RoundedRectangle(cornerRadius: 12.0, style: .continuous)
.aspectRatio(contentMode: .fit)
.foregroundColor(Color(UIColor.systemGroupedBackground))
.onTapGesture {
if mark == nil {
nextPlayerTwoMarkPosition = Int.random(in: 1...10)
if whoseTurnIsIt == "user" {
mark = "xmark"
whoseTurnIsIt = "device"
} else {
if nextDeviceMarkPosition == 1 {
mark = "circle"
whoseTurnIsIt = "user"
}
}
}
}
Image(systemName: mark ?? "")
})
It only seems to let the device mark the square after the player has tapped it, even if it wasn't their turn. I'm trying to find a solution to get the device to mark a random square (there are 9 in total) during its turn.
Aucun commentaire:
Enregistrer un commentaire