The following function counts down a red to green light then counts the reaction time for the user to hit a button after the green light is displayed.
func updateCounter(){
timerInt -= 1
if timerInt == 2{
light.image = UIImage(named: "r.png")
} else if timerInt == 1 {
light.image = UIImage(named: "yellow.png")
} else if timerInt == 0 {
light.image = UIImage(named: arc4random_uniform(2) == 0 ? "no.png" : "g.png")
timer.invalidate()
startStop.isEnabled = true
scoreTimer = Timer.scheduledTimer(timeInterval: 0.0001, target: self, selector: #selector(ViewController.updateScoreTime), userInfo: nil, repeats: true)
}}
where it states "else if timerInt == 0" the user is given a random function. A image will either turn green or a x is displayed. If the x is displayed I would like the user to to have to hit a button that states game over to restart the red light sequence. If a green light is displayed i would like the user to have to test their reaction time. Which is how the function already runs now but it does not change if the x is displayed. I guess I would like the function to run as followed.
if timeInt == 0 and green light is chosen then run test reaction time
else if timeInt == 0 and x is chosen then end reaction time and run game over button
Aucun commentaire:
Enregistrer un commentaire