// // ViewController.swift // NuevoProyecto // // Created by Pablo Perez on 2021-08-02. // import UIKit class ViewController: UIViewController { @IBOutlet weak var boton: UIButton! @IBOutlet weak var tiempo: UILabel! @IBOutlet weak var veces: UILabel! var cont = 0 @IBAction func botonAction(_ sender: Any) { cont = cont + 1 veces.text = String (cont) } var timer = Timer() var requestTimer = 10 @objc func timeMethod(){ requestTimer -= 1 tiempo.text = String (requestTimer) if requestTimer == 5 { timer.invalidate() let alert = UIAlertController(title: "Juego Terminado", message: "Total de puntos: \(String(describing: veces.text!))", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: { (alert:UIAlertAction!) in self.startGame() })) self.present(alert, animated: true) cont = 0 veces.text = String (cont) } } override func viewDidLoad() { super.viewDidLoad() startGame() // boton.center.x = view.frame.width / 2 // boton.center.y = view.frame.height / 4 // boton.addTarget(self, action: #selector(aleatorio), for: .touchUpInside) } func startGame(){ requestTimer = 10 tiempo.text = String (requestTimer) timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(timeMethod), userInfo :nil, repeats: true) } // @objc func aleatorio(){ // boton.center.x = boton.frame.width / 2 // boton.center.y = boton.frame.height / 2 // } }