编辑代码

//函数8:获得当前时间戳
func getCurrentTimeStamp() ->Int
let now = Date()
let timeInterval :TimeInterval = now.timeIntervalSince1970return Int(timeInterval)
//函数9:定时器倒计时函数,显示当前消耗时间和倒计时
func timeElapse()
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) timer) in
let timestamp = self.getCurrentTimeStamp()
let pastPeriod = timestamp- self.beginTimestamp let countDown = self.GamePeriod - pastPeriod
self.TimeCost = pastPeriod
if countDown<=0 1| self.GameOver 
self.GameOver = true
let tipsLabel= self.view.viewWithTag(1001)as! UILabeltipsLabel.text="游戏结束,共消耗时间\(self,TimeCost)秒”
timer.invalidate()
let tipsLabel = self.view.viewWithTag(1002)as!UILabel
DispatchQueue. main.async{
  tipsIabel.text="您消耗\(pastPeriod)秒,倒计时\(countDown)秒"
} 
}
}