-1
我想在某人獲勝後重置井字棋遊戲。當有人獲勝時,我設置了一個警報控制器。我是這樣的,當按下特定的按鈕時,它會將視圖控制器重置爲原始狀態,以便玩家可以玩另一個遊戲。這裏是我有一個特定的勝利代碼:如何以編程方式重置視圖控制器
if (positionOne == 1000001 && positionTwo == 1000002 && positionThree == 1000003)
{
var alert = UIAlertController(title: "Player One Wins!!", message: nil, preferredStyle: .alert)
var okButton = UIAlertAction(title: "Aww man, that sucks. I demand a rematch!", style: .destructive)
{ (action) in
self.topLeftLabel.text = "-"
self.topMiddleLabel.text = "-"
self.topRightLabel.text = "-"
self.middleLeftLabel.text = "-"
self.middleMiddleLabel.text = "-"
self.middleRightLabel.text = "-"
self.bottomLeftLabel.text = "-"
self.bottomMiddleLabel.text = "-"
self.bottomRightLabel.text = "-"
var positionOne = 1
var positionTwo = 2
var positionThree = 3
var positionFour = 4
var positionFive = 5
var positionSix = 6
var positionSeven = 7
var positionEight = 8
var positionNine = 9
}
var deathButton = UIAlertAction(title: "I'd like to see the board", style: .default)
alert.addAction(deathButton)
alert.addAction(okButton)
present(alert, animated: true, completion: nil)
}
我是這樣,當按下「死亡按鈕」時,重置遊戲。然而,當我這樣做是清除董事會和一切,但每當我點擊任何對話框只是立即彈出備份。我該如何解決?
你有一個變量來表示一名球員是否贏了? – koropok
此代碼位於哪個函數中? – TheValyreanGroup