When all images are the same = random: 3x smiles
When images are different = random: one’s smiles or text or nothing
When the score < 100 = this is the one smile
But I don’t know how to stop a code and to say “Game is over” when the score is 0 =(.
The Code is here CODE
What do you say about my version?
Translate:
Везунчик! = You are lucky!
А ну-ка попробуй повторить! = Come on, try to repeat
Чет не = Something is wrong
Oй = Oh
2 Likes
Great job!
An if statement surrounding the button code requiring that the credits > 0 to execute is how I got around that. Though we haven’t learned how to execute a popup yet I assume that will come.
if credits > 0 {
// execute button code
} else {
print("no credits") // this only prints to the debug area and not to your screen.
}
Ok, so you got me curious on how to create an alert which I assume we will cover later but I was able to find an example here
Here are the steps.
- Add a @State modifier under all your other @State modifiers
@State private var showingAlert = false
- Create the if statement as I described in my previous message
if (creditAmount >= 10) {
// this is where your button code would go.
let imageNameArray = ["apple","cherry","star"]
imageName1 = imageNameArray[Int.random(in: 0...2)]
imageName2 = imageNameArray[Int.random(in: 0...2)]
imageName3 = imageNameArray[Int.random(in: 0...2)]
creditAmount -= 10
} else {
// set the showingAlert which is now tracked via the @State modifier
self.showingAlert = true
}
- After your button code add the .alert modifier like below
Button(
// all of your button code here
).alert(isPresented: $showingAlert) {
Alert(title: Text("You are Out of money"), message: Text("click ok to dismiss"), dismissButton: .default(Text("OK")))
}
Thanks a lot! I will try to do it!