Outlets Lab

From Learn.co

The task: finish building a Simon Says clone app.

The Code

@IBAction func redButton(_ sender: UIButton) {
simonSaysGame.guessRed()
gameResult()
}
@IBAction func greenButton(_ sender: UIButton) {
simonSaysGame.guessGreen()
gameResult()
}
@IBAction func yellowButton(_ sender: UIButton) {
simonSaysGame.guessYellow()
gameResult()
}
@IBAction func blueButton(_ sender: UIButton) {
simonSaysGame.guessBlue()
gameResult()
func gameResult() {
  let numberColorsChosen = simonSaysGame.chosenColors.count
  let hasWonGame = simonSaysGame.wonGame()
    if numberColorsChosen == 5 {
    if hasWonGame {
      winLabel.text = "You won!"
      winLabel.isHidden = false
    } else {
      winLabel.text = "You lose"
      winLabel.isHidden = false
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
//Brendt game play.  Show the "You won" if a player wins.
winLabel.isHidden = true
}
}

I have a couple questions about this project.

  1. I found that I couldn’t write the func gameResult() inside the override fund viewDidLoad() block without an error. I guess the @IBaction didn’t have access to it. I wonder if it’s OK to write the IBaction and gameResult() both inside the viewDidLoad().
  2. The simonSaysGame.chosenColors.count command seems to count the number of total clicks. That’s why I wrote the if clause to execute at 6 clicks, since there are 5 color choice clicks + one start game click.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.