Resetting the game
We want to give the user the opportunity to start a new game, and we can do that by adding a reset
function to the file. This function will reset the sliders to 0 and generate another random target color for the middle target circle.
Add the following function underneath the calculateScore
function:
//MARK: - RESET THE GAME func reset() { redTarget = Double.random(in: 0..<1) greenTarget = Double.random(in: 0..<1) blueTarget = Double.random(in: 0..<1) redGuess = 0.0 greenGuess = 0.0 blueGuess = 0.0 }
This function creates new random colors and stores them in the Target
variables. It also resets the Guess
variables back...