// // ConfermaController.swift // spotTheSpy // // Created by Paolo Alberti on 14/05/18. // Copyright © 2018 Paolo. All rights reserved. // import UIKit class ConfermaController: UIViewController { @IBOutlet var sfondoView: UIImageView! @IBOutlet var viewDescrizione: UIView! @IBOutlet var descLabel: UILabel! @IBOutlet var OkBtn: UIButton! @IBOutlet var mainView: UIView! var seconds = 3 var timer = Timer() override func viewDidLoad() { super.viewDidLoad() DataManager.shared.ConfermaC = self DataManager.shared.cambiaStile(stile: DataManager.shared.stileGrafica) viewDescrizione.cornerRadius = 5 viewDescrizione.applyGradient(colours: [grigio, UIColor.white]) viewDescrizione.borderWidth = 2 viewDescrizione.borderColor = grigioscuro2 OkBtn.cornerRadius = 5; OkBtn.applyGradient(colours: [bluscuro, blu]) OkBtn.borderWidth = 2 OkBtn.borderColor = grigio OkBtn.setTitle(NSLocalizedString("Fatto", comment: ""), for: .normal) descLabel.text = NSLocalizedString("Desc_conferma", comment: "") // Ridimensiono la schermata delle Opzioni per i diversi Device (NON uso l'Auto Layout) var scale = self.view.frame.size.width/414 if (UIDevice.current.userInterfaceIdiom == .pad) { scale = self.view.frame.size.height/736 } mainView.transform = CGAffineTransform(scaleX: scale, y: scale) } @IBAction func runTimer(_ sender: UIButton) { DataManager.shared.lightGen.impactOccurred() let myNormalAttributedTitle = NSAttributedString(string: "\(seconds)...", attributes: [NSAttributedStringKey.foregroundColor : UIColor.white]) OkBtn.setAttributedTitle(myNormalAttributedTitle, for: .normal) sender.isEnabled = false // Se ci sono altri giocatori a cui passare il dispositivo if (DataManager.shared.nGiocatori - 1) > DataManager.shared.curPlayer { DataManager.shared.curPlayer += 1 //Sound.play(file: "click.mp3") timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true) } // Se i giocatori sono ultimati, inizia il conto alla rovescia else { performSegue(withIdentifier: "startTimer", sender: nil) } } @objc func updateTimer() { if seconds < 2 { timer.invalidate() performSegue(withIdentifier: "nuovoTurno", sender: nil) } else { Sound.play(file: "tick.wav") seconds -= 1 let myNormalAttributedTitle = NSAttributedString(string: "\(seconds)...", attributes: [NSAttributedStringKey.foregroundColor : UIColor.white]) OkBtn.setAttributedTitle(myNormalAttributedTitle, for: .normal) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }