import UIKit class ViewController: UIViewController { var whosTurn = "X" // these variables will hold the text on each of the // 9 buttons that hold an "X", "O", or " " // row 1 var b11Text = "" var b12Text = "" var b13Text = "" // FINISH ME // row 2 var b21Text = ?? var b22Text = ?? var b23Text = ?? // FINISH ME // row 3 // create variables b31Text, b32Text, b33Text // and assign "" // FINISH ME // labels reference variables // connect the labels @IBOutlet weak var resultsLabel: UILabel! @IBOutlet weak var whosTurnLabel: UILabel! // FINISH ME // button reference variables // connect all the X O buttons // buttons on row 1 @IBOutlet weak var button11: UIButton! @IBOutlet weak var button12: UIButton! @IBOutlet weak var button13: UIButton! // buttons on row 2 @IBOutlet weak var button21: UIButton! @IBOutlet weak var button22: UIButton! @IBOutlet weak var button23: UIButton! // buttons on row 3 @IBOutlet weak var button31: UIButton! @IBOutlet weak var button32: UIButton! @IBOutlet weak var button33: UIButton! // this buttonEvent function gets called when // you click on 1 of the 9 buttons @IBAction func buttonEvent(_ sender: UIButton) { // sender is the name of the button that // got clicked // this gets the text on the button that // got clicked let textOnButton = sender.title(for: .normal)! // here we check to see if a player has // already played on this button if textOnButton != " " { return } // check to see if whosTurn is equal to "X" ???? { sender.setTitle("X", for: .normal) if isWinner(whosTurn) { // FINISH ME // Set the text field on the resultsLabel to say // "X Wins!!!" resultsLabel.???? = ???? return } else { // FINISH ME // Set whosTurn to "O" ????? // FINISH ME // Set the text field on the whosTurnLabel to "O" ????? } } else { sender.setTitle("O", for: .normal) if isWinner(whosTurn) { // FINISH ME // Set the text field on the resultsLabel to say // "O Wins!!!" resultsLabel.???? = ??????? return } else { // FINISH ME // Set whosTurn to "X" ???? // FINISH ME // Set the text field on the whosTurnLabel to "X" ?????? } } } func isWinner(_ whosTurn:String) -> Bool { // FINISH ME // run the method (call the method) // getTheTextOnAllNineButtons() ????? // check for a winner on row 1 if b11Text == whosTurn && b12Text == whosTurn && b13Text == whosTurn { return true } // FINISH ME // check for a winner on row 2 // FINISH ME // check for a winner on row 3 // check for a winner on col 1 if b11Text == whosTurn && b21Text == whosTurn && b31Text == whosTurn { return true } // FINISH ME // check for a winner on col 2 // FINISH ME // check for a winner on col 3 // FINISH ME // check for a winner on diagonal 1 (upper left to lower right) // FINISH ME // check for a winner on diagonal 2 (upper right to lower left) return false } func getTheTextOnAllNineButtons() { // get the text for all 9 buttons // row 1 b11Text = button11.title(for: .normal)! b12Text = button12.title(for: .normal)! b13Text = button13.title(for: .normal)! // FINISH ME // row 2 b21Text = ????! b22Text = ????! b23Text = ????! // FINISH ME // row 3 } func setAllButtonsToEmpty() { // set row 1 buttons to " " button11.setTitle(" ", for: .normal) button12.setTitle(" ", for: .normal) button13.setTitle(" ", for: .normal) // FINISH ME // set row 2 buttons to " " // FINISH ME // set row 3 buttons to " " } @IBAction func newGameButton(_ sender: UIButton) { // FINISH ME // set whosTurn to "X" ????? // FINISH ME // run (call) the method setAllButtonsToEmpty() ?????? // FINISH ME // Set the text field on the resultsLabel to say "" resultsLabel.???? = ???? } 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. } }