// // singleMode.swift // juego // // Created by Mobile Roshka on 3/4/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // import UIKit class SingleModeViewController: UIViewController { var points = 0 var initGame = false var initTimer = false var timer = Timer() var timeRest = 10 @IBOutlet weak var pointsLbl: UILabel! @IBOutlet weak var timeRestLbl: UILabel! @IBAction func playGame(_ sender: Any) { initGame = true initTimer = true timeRest = 10 timeRestLbl.text = "\(timeRest)" if initTimer{ timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(timeRestMethod), userInfo :nil, repeats: true) } } @objc func timeRestMethod() { timeRest -= 1 timeRestLbl.text = "\(timeRest)" if timeRest == 0 { timer.invalidate() initGame = false } } @IBAction func touchBtn(_ sender: Any) { if initGame{ points += 1 pointsLbl.text = "\(points)" } } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } }