猜数字游戏开发指南
1. 功能函数编写
首先,我们要添加处理用户猜数字和生成随机数的功能函数,代码如下:
// function called from the GuessInputViewController when the user taps on the Save
// Button button
func userDidFinish(_ controller: GuessInputViewController, guess: String) {
userGuessLabel.text = "The guess was " + guess
previousGuess = guess
let numberGuess = Int(guess)
if (numberGuess! > randomNumber){
resultLabel.text = "Guess too high"
}
else if (numberGuess! < randomNumber) {
resultLabel.text = "Guess too low"
}
else {
resultLabel.text = "Guess is correct"
playAgainButton.isHidden = false //show the play again button
guessButton.isHidden = true //hide the guess again number
}
超级会员免费看
订阅专栏 解锁全文
299

被折叠的 条评论
为什么被折叠?



