Created
January 25, 2021 10:25
-
-
Save KrauserHuang/3d4d336f7d12eb823e72ca209bdea8eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func go(_ sender: UIButton) { | |
if typeTextField.text == "" { | |
let controller = UIAlertController(title: "請給我一個數字", message: "輸入數字才可以繼續喔!", preferredStyle: .alert) | |
let action = UIAlertAction(title: "了解", style: .default, handler: nil) | |
controller.addAction(action) | |
present(controller, animated: true, completion: nil) | |
} else if chanceNumber > 1 { | |
checkAnswer() | |
} else { | |
let controller = UIAlertController(title: "遊戲結束", message: "正確答案是\(questionNumber)", preferredStyle: .alert) | |
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in | |
//將剩餘結果畫面顯示在上面 | |
self.chanceLabel.text = "你已經用完所有機會了!" | |
self.typeTextField.text = "\(self.questionNumber)" | |
self.rangeLabel.text = "沒猜中!" | |
//這邊會將goButton所以起來,必須在playAgain()重新開啟他 | |
self.goButton.isUserInteractionEnabled = false | |
} | |
controller.addAction(okAction) | |
let replayAction = UIAlertAction(title: "Re-Play", style: .default) { (_) in | |
self.playAgain() | |
} | |
controller.addAction(replayAction) | |
present(controller, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment