我正在制作一个“不要点击白色瓷砖”游戏作为一些人的教程,游戏工作正常,直到我开始添加分数。我无法理解什么是错的,我认为这实际上是Swift的一个问题。我有一个名为ScoreFunc()的函数,它保存了得分的所有代码(稍后我将添加更多关于高分的信息。)当按下其中一个BlackTiles时,调用此函数(如Action Outlet所示“FirstDown ()“)。我可以删除“分数+ = 1”,它可以正常工作,或者我也可以删除“ScoreLabel.text =”(分数)。“当它们都在运行时,它会计算分数,但没有任何一个瓷砖移动下来。
@IBOutlet weak var BlackTile1: UIButton!
@IBOutlet weak var BlackTile2: UIButton!
@IBOutlet weak var BlackTile3: UIButton!
@IBOutlet weak var BlackTile4: UIButton!
@IBOutlet weak var BlackTile5: UIButton!
@IBOutlet var ScoreLabel: UILabel!
var Score = Int()
override func viewDidLoad() {
super.viewDidLoad()
ScoreLabel.text = "0"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func BlackHawkDown() {
WhiteTile1.center.y = WhiteTile1.center.y + 142
WhiteTile2.center.y = WhiteTile2.center.y + 142
WhiteTile3.center.y = WhiteTile3.center.y + 142
WhiteTile4.center.y = WhiteTile4.center.y + 142
WhiteTile5.center.y = WhiteTile5.center.y + 142
WhiteTile6.center.y = WhiteTile6.center.y + 142
WhiteTile7.center.y = WhiteTile7.center.y + 142
WhiteTile8.center.y = WhiteTile8.center.y + 142
WhiteTile9.center.y = WhiteTile9.center.y + 142
WhiteTile10.center.y = WhiteTile10.center.y + 142
WhiteTile11.center.y = WhiteTile11.center.y + 142
WhiteTile12.center.y = WhiteTile12.center.y + 142
WhiteTile13.center.y = WhiteTile13.center.y + 142
WhiteTile14.center.y = WhiteTile14.center.y + 142
WhiteTile15.center.y = WhiteTile15.center.y + 142
BlackTile1.center.y = BlackTile1.center.y + 142
BlackTile2.center.y = BlackTile2.center.y + 142
BlackTile3.center.y = BlackTile3.center.y + 142
BlackTile4.center.y = BlackTile4.center.y + 142
BlackTile5.center.y = BlackTile5.center.y + 142
if (BlackTile1.center.y >= 600){
BlackTile1.center.y = -71
WhiteTile1.center.y = -71
WhiteTile2.center.y = -71
WhiteTile3.center.y = -71
RandomPlacementOne()
}
if (BlackTile2.center.y >= 600){
BlackTile2.center.y = -71
WhiteTile4.center.y = -71
WhiteTile5.center.y = -71
WhiteTile6.center.y = -71
RandomPlacementTwo()
}
if (BlackTile3.center.y >= 600){
BlackTile3.center.y = -71
WhiteTile7.center.y = -71
WhiteTile8.center.y = -71
WhiteTile9.center.y = -71
RandomPlacementThree()
}
if (BlackTile4.center.y >= 600){
BlackTile4.center.y = -71
WhiteTile10.center.y = -71
WhiteTile11.center.y = -71
WhiteTile12.center.y = -71
RandomPlacementFour()
}
if (BlackTile5.center.y >= 600){
BlackTile5.center.y = -71
WhiteTile13.center.y = -71
WhiteTile14.center.y = -71
WhiteTile15.center.y = -71
RandomPlacementFive()
}
}
func ScoreFunc() {
Score += 1
ScoreLabel.text = "\(Score)"
}
@IBAction func FirstDown(sender: AnyObject) {
BlackHawkDown()
ScoreFunc()
}
@IBAction func SecondDown(sender: AnyObject) {
BlackHawkDown()
ScoreFunc()
}