编辑代码

//函数10:不同点的Button被单击后调用,支持音效、计时、游戏结束
@objc func buttonCheckMusicTimer( sender : UIButton)
if GameOver (return)
let tipsLabel= self.view.viewWithTag(1001) as! UILabel var tag - sender.tag
if tag >= 5000(
tag -= 5000
elseif tag >= 4000 (
tag -= 4000let row = Int (tag / cols)
let col = tag - cols★row
let result = errorCords.filterf
50==(row,col)
!
letreserved = errorcords.filter(
$0!=(row,Co1)
)
errorCords = reserved
if result.count>=1
sender.backgroundColor =.red
let path = Bundle.main.path(forResource:"birdsound", ofType:"m4a")let url = URL(fileURLWithPath: path!)
soundPlayer=try? AVAudioPlayer(contentsof:url)
soundPlayer.play()
tipsLabel.text="不同找到:(\(row),\(col)),还剩\(errorCords.count)个"
if errorCords.count <=0 {
GameOver = true
tipsLabel.text="任务完成,共花费时间\(self.TimeCost)秒"
}
}
else {
sender.backgroundColor=.brown
let path = Bundle.main.path(forResource: "error",ofType:"m4a")
let url =URL(fileURLWithPath: path!)
soundPlayer=try? AVAudioPlayer(contentsOf: url)
soundPlayer.play()
tipsLabel.text="找错啦: (\(row),\(col))"
}
}