// Mr. Rosier import UIKit class ViewController: UIViewController { var timer = Timer() // FINISH ME // define a variable called count and set it to 0 let die1 = UIImage(named:"die-1") let die2 = UIImage(named:"die-2") let die3 = UIImage(named:"die-3") let die4 = UIImage(named:"die-4") let die5 = UIImage(named:"die-5") let die6 = UIImage(named:"die-6") // FINISH ME // Control + Drag from your UIImageView object that // shows a die to this variable @IBOutlet weak var firstDie: UIImageView! var firstDieValue = 1 @IBOutlet weak var secondDie: UIImageView! var secondDieValue = 1 // this label should show: // You tossed: 2 6 or 1 4 or ... @IBOutlet weak var tossedLabel: UILabel! // this label should show either: // You Win!!! (if you tossed a 7 or 11) // else You Lose!! @IBOutlet weak var winLossLabel: UILabel! // FINISH ME // Control + Drag from your Button toss object that // shows a pic to this function @IBAction func tossButtonEvent(_ sender: UIButton) { timer.invalidate() // just in case this button is tapped multiple times // FINISH ME // set your count to 0 // (i.e. assign a value of 0 to your count) // DO NOT CREATE THE VARIABLE, THAT IS DONE AT THE TOP // FINISH ME // set the winLossLabel to "" (use the .text field) // DO NOT CREATE THE VARIABLE, THAT IS DONE AT THE TOP // FINISH ME // set the tossedLabel to "" (use the .text field) // DO NOT CREATE THE VARIABLE, THAT IS DONE AT THE TOP // start the timer // and call timerAction() every .2 seconds timer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true) } @objc func timerAction() { // FINISH ME // add 1 to your count // this controls how many times you change the dice // DO NOT CREATE THE VARIABLE, THAT IS DONE AT THE TOP // we find a random integer between // 1 and 6 inclusive var x = Int(arc4random()%6) + 1 firstDieValue = x if x == 1 { firstDie.image = die1 } else if x == 2 { firstDie.image = die2 } // FINISH ME // handle the other 4 else if statements // for die's 3 - 6 // FINISH ME // handle the other die x = Int(arc4random()%6) + 1 secondDieValue = x // handle the second die (as you did above only for secondDie) if x == 1 { secondDie.image = die1 } // etc. // FINISH ME // FINISH ME // check to see if the count is // greater than or equal to 18 ????? { // FINISH ME // update the tossedLabel // You will need to display the firstDieValue and secondDieValue // use interpolation tossedLabel.???? = "You tossed: ???? ????" // FINISH ME // find the sum of the tossed die (firstDieValue and secondDieValue) let sum = ???? + ????? // FINISH ME // if the sum is 7 or the sum // is 11, display on the // winLossLabel "You Win!!!" // else display "You Lose!!!" if sum == 7 || sum == 11 { winLossLabel.text = "You Win!!!" } else { winLossLabel.text = "You Lose!!!" } // stop the timer timer.invalidate() } } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }