Last active
July 6, 2017 02:04
-
-
Save staycreativedesign/221263f34d8799620476e851a85a579c to your computer and use it in GitHub Desktop.
first swift app attempt - major noobage!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is in Model directory | |
| // | |
| // Deck.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 7/5/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import Foundation | |
| let questions = ["cachorro", "gato", "galinha", "pomba", "bicicleta", "motoboy", "Skank", "Jaspion", "Jiraya", "Xuxa", "Angelica", "Mara Maravilha", "Gugu", "Silvio Santos", "Panico", "Ayrton Senna", "Guga", "Pica Pau Amarelo", "Kid Abelha", "Barão Vermelho", "Titás", "Biquíno Cavadão", "Capital Inicial", "Hortençia", "Paralamas do Sucesso", "Gasparzinho", "Chaves", "Scooby Doo", "Piu Piu e Frajola", "Tico e Teco", "Pantera Cor-de-Rosa", "Manda Chuva", "Zé Colmeia", "Gil Gomes", "Os Jetsons", "Cidade Alerta", "Traço Mágico", "Os Caça-Fantasmas", "Roberto Carlos", "Ki Suco"] | |
| enum Outcome { | |
| case right | |
| case wrong | |
| case none | |
| } | |
| struct Deck { | |
| var name = String() | |
| var cards = [Card]() | |
| } | |
| struct Card { | |
| var name: String | |
| var outcome = Outcome.none | |
| } | |
| func createDeck(withName name: String, withCards cards: [String]) -> Deck{ | |
| var deck = Deck(name: name, cards: [Card]()) | |
| for name in cards { | |
| deck.cards.append(Card(name: name, outcome: .none)) | |
| } | |
| return deck | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 6/29/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class ViewController: UIViewController { | |
| var deck = createDeck(withName: "foo", withCards: questions) | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .portrait | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view, typically from a nib. | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| let destination = segue.destination as! InformationController | |
| destination.selectedDeck = self.deck | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Info.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 6/29/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| import CoreMotion | |
| class InformationController: UIViewController { | |
| @IBOutlet weak var timerCountdown: UILabel! | |
| @IBOutlet weak var questionArea: UILabel! | |
| var selectedCards = [Card]() | |
| var selectedDeck = Deck() | |
| var motionManager = CMMotionManager() | |
| var timer = Timer() | |
| var seconds = 10 | |
| var points = Int() | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .landscape | |
| } | |
| override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { | |
| return .landscapeLeft | |
| } | |
| override func viewWillAppear(_ animated: Bool) { | |
| super.viewWillAppear(animated) | |
| timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(InformationController.counter), userInfo: nil, repeats: true) | |
| questionArea.textColor = .white | |
| let infoLayer = self.view.layer | |
| infoLayer.cornerRadius = 20.0 | |
| infoLayer.borderWidth = 20.0 | |
| infoLayer.borderColor = UIColor.white.cgColor | |
| let card = randomize(deck: selectedDeck) | |
| questionArea.text = card.name | |
| motionManager.gyroUpdateInterval = 0.1 | |
| motionManager.startGyroUpdates(to: OperationQueue.current!) { (data, error) in | |
| if let myData = data { | |
| let coordinates = myData.rotationRate.y | |
| switch coordinates { | |
| case let y where y < -5: | |
| print("up") | |
| print(coordinates) | |
| self.motionManager.stopGyroUpdates() | |
| self.timer.invalidate() | |
| self.performSegue(withIdentifier: "Orange", sender: nil) | |
| self.selectedCards.append(Card(name: card.name, outcome: .right)) | |
| case let y where y > 5: | |
| print("down") | |
| print(coordinates) | |
| self.motionManager.stopGyroUpdates() | |
| self.performSegue(withIdentifier: "Green", sender: nil) | |
| self.timer.invalidate() | |
| self.selectedCards.append(Card(name: card.name, outcome: .wrong)) | |
| default: | |
| print(coordinates) | |
| } | |
| } | |
| } | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| } | |
| override func viewDidAppear(_ animated: Bool) { | |
| } | |
| func counter() { | |
| seconds -= 1 | |
| timerCountdown.text = String(seconds) | |
| if (seconds == 0) { | |
| timer.invalidate() | |
| self.motionManager.stopGyroUpdates() | |
| self.performSegue(withIdentifier: "tempoFinal", sender: nil) | |
| } | |
| } | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| if let destination = segue.destination as? TimeFinishedController { | |
| destination.finalPoints = self.selectedCards | |
| } | |
| } | |
| func randomize(deck: Deck) -> Card { | |
| let totalCards = deck.cards.count | |
| let randomNumber = Int(arc4random_uniform(UInt32(totalCards))) | |
| let card = (deck.cards[randomNumber]) | |
| return card | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // OrangeController.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 7/2/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class OrangeController: UIViewController { | |
| @IBOutlet weak var responseLabel: UILabel! | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .landscape | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let infoLayer = self.view.layer | |
| infoLayer.cornerRadius = 20.0 | |
| infoLayer.borderWidth = 20.0 | |
| infoLayer.borderColor = UIColor.white.cgColor | |
| let when = DispatchTime.now() + .seconds(1) | |
| DispatchQueue.main.asyncAfter(deadline: when) { | |
| print("finished") | |
| self.presentingViewController?.dismiss(animated: true, completion: nil) | |
| } | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // GreenController.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 7/2/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class GreenController: UIViewController { | |
| @IBOutlet weak var responseLabel: UILabel! | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .landscape | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let infoLayer = self.view.layer | |
| infoLayer.cornerRadius = 20.0 | |
| infoLayer.borderWidth = 20.0 | |
| infoLayer.borderColor = UIColor.white.cgColor | |
| let when = DispatchTime.now() + .seconds(1) | |
| DispatchQueue.main.asyncAfter(deadline: when) { | |
| print("finished") | |
| self.presentingViewController?.dismiss(animated: true, completion: nil) | |
| } | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // TimeFinishedController.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 7/3/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class TimeFinishedController: UIViewController { | |
| var finalPoints = [Card]() | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .landscape | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let infoLayer = self.view.layer | |
| infoLayer.cornerRadius = 20.0 | |
| infoLayer.borderWidth = 20.0 | |
| infoLayer.borderColor = UIColor.white.cgColor | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| } | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| let destination = segue.destination as! PointsController | |
| destination.finalPoints = finalPoints | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // PointsController.swift | |
| // PassingInfoToSegue | |
| // | |
| // Created by Gustavo Pares on 7/5/17. | |
| // Copyright © 2017 Gustavo Pares. All rights reserved. | |
| // | |
| import UIKit | |
| class PointsController: UIViewController { | |
| var finalPoints = [Card]() | |
| override open var shouldAutorotate: Bool { | |
| return false | |
| } | |
| override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
| return .portrait | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let infoLayer = self.view.layer | |
| infoLayer.cornerRadius = 20.0 | |
| infoLayer.borderWidth = 20.0 | |
| infoLayer.borderColor = UIColor.white.cgColor | |
| for card in finalPoints { | |
| switch card.outcome { | |
| case .wrong: | |
| print("wrong") | |
| case .right: | |
| print("right") | |
| default: | |
| print("default") | |
| } | |
| } | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment