我無法在井字遊戲中的AI響應之前繼續激活按鈕。正如你所看到的,我添加了一個延遲響應,但即使在我的AI響應之前,我仍然可以再做一次。任何人都知道如何禁用第一輪玩家回合,直到人工智能輪到?如何在AI響應之前的延遲期間阻止用戶響應
@IBOutlet var userMessage: UILabel!
struct Sender{
var tag = 1
}
var plays = Dictionary<Int,Int>()
var done = false
var aiDeciding = false
var sender: Sender = Sender()
@IBAction func UIButtonClicked(sender:UIButton) {
userMessage.hidden = true
if plays[sender.tag] == nil && !aiDeciding && !done {
setImageForSpot(sender.tag, player: 1)
}
checkForWin()
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
delay(0.4) {
self.aiTurn()
}
}
你會如何寫呢? – Pjc1992 2014-11-09 08:16:13
@ Pjc1992'當開始動畫時'self.view.userInteractionEnabled = false',完成時'self.view.userInteractionEnabled = true'。 – drewag 2014-11-09 18:30:09