diff --git a/Quizzler-iOS13.xcodeproj/project.pbxproj b/Quizzler-iOS13.xcodeproj/project.pbxproj index 498a95ff..47f5c76f 100644 --- a/Quizzler-iOS13.xcodeproj/project.pbxproj +++ b/Quizzler-iOS13.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 6E56B9AE28D3F963005C4BC2 /* QuizBrain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E56B9AD28D3F963005C4BC2 /* QuizBrain.swift */; }; + 6E6D3A7728D274D100B7D080 /* Pregunta.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E6D3A7628D274D100B7D080 /* Pregunta.swift */; }; AD4BDE4A22D878BA005BA4CC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4BDE4922D878BA005BA4CC /* AppDelegate.swift */; }; AD4BDE4C22D878BA005BA4CC /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4BDE4B22D878BA005BA4CC /* SceneDelegate.swift */; }; AD4BDE4E22D878BA005BA4CC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD4BDE4D22D878BA005BA4CC /* ViewController.swift */; }; @@ -17,6 +19,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6E56B9AD28D3F963005C4BC2 /* QuizBrain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizBrain.swift; sourceTree = ""; }; + 6E6D3A7628D274D100B7D080 /* Pregunta.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pregunta.swift; sourceTree = ""; }; AD4BDE4622D878BA005BA4CC /* Quizzler-iOS13.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Quizzler-iOS13.app"; sourceTree = BUILT_PRODUCTS_DIR; }; AD4BDE4922D878BA005BA4CC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; AD4BDE4B22D878BA005BA4CC /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -39,6 +43,31 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 6E56B9AA28D3F84D005C4BC2 /* Model */ = { + isa = PBXGroup; + children = ( + 6E6D3A7628D274D100B7D080 /* Pregunta.swift */, + 6E56B9AD28D3F963005C4BC2 /* QuizBrain.swift */, + ); + path = Model; + sourceTree = ""; + }; + 6E56B9AB28D3F85D005C4BC2 /* View */ = { + isa = PBXGroup; + children = ( + AD4BDE4F22D878BA005BA4CC /* Main.storyboard */, + ); + path = View; + sourceTree = ""; + }; + 6E56B9AC28D3F864005C4BC2 /* Controller */ = { + isa = PBXGroup; + children = ( + AD4BDE4D22D878BA005BA4CC /* ViewController.swift */, + ); + path = Controller; + sourceTree = ""; + }; AD4BDE3D22D878BA005BA4CC = { isa = PBXGroup; children = ( @@ -61,8 +90,9 @@ children = ( AD4BDE4922D878BA005BA4CC /* AppDelegate.swift */, AD4BDE4B22D878BA005BA4CC /* SceneDelegate.swift */, - AD4BDE4F22D878BA005BA4CC /* Main.storyboard */, - AD4BDE4D22D878BA005BA4CC /* ViewController.swift */, + 6E56B9AA28D3F84D005C4BC2 /* Model */, + 6E56B9AB28D3F85D005C4BC2 /* View */, + 6E56B9AC28D3F864005C4BC2 /* Controller */, AD4BDE5222D878BC005BA4CC /* Assets.xcassets */, AD4BDE5422D878BC005BA4CC /* LaunchScreen.storyboard */, AD4BDE5722D878BC005BA4CC /* Info.plist */, @@ -142,9 +172,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6E56B9AE28D3F963005C4BC2 /* QuizBrain.swift in Sources */, AD4BDE4E22D878BA005BA4CC /* ViewController.swift in Sources */, AD4BDE4A22D878BA005BA4CC /* AppDelegate.swift in Sources */, AD4BDE4C22D878BA005BA4CC /* SceneDelegate.swift in Sources */, + 6E6D3A7728D274D100B7D080 /* Pregunta.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Quizzler-iOS13.xcodeproj/project.xcworkspace/xcuserdata/pablo.xcuserdatad/UserInterfaceState.xcuserstate b/Quizzler-iOS13.xcodeproj/project.xcworkspace/xcuserdata/pablo.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..1064c739 Binary files /dev/null and b/Quizzler-iOS13.xcodeproj/project.xcworkspace/xcuserdata/pablo.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Quizzler-iOS13.xcodeproj/xcuserdata/pablo.xcuserdatad/xcschemes/xcschememanagement.plist b/Quizzler-iOS13.xcodeproj/xcuserdata/pablo.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..73360cf5 --- /dev/null +++ b/Quizzler-iOS13.xcodeproj/xcuserdata/pablo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Quizzler-iOS13.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Quizzler-iOS13/Controller/ViewController.swift b/Quizzler-iOS13/Controller/ViewController.swift new file mode 100644 index 00000000..d30760c2 --- /dev/null +++ b/Quizzler-iOS13/Controller/ViewController.swift @@ -0,0 +1,60 @@ +// +// ViewController.swift +// Quizzler-iOS13 +// +// Created by Angela Yu on 12/07/2019. +// Copyright © 2019 The App Brewery. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + @IBOutlet weak var labelPuntaje: UILabel! + @IBOutlet weak var labelPregunta: UILabel! + @IBOutlet weak var barraProgreso: UIProgressView! + @IBOutlet weak var botonTrue: UIButton! + @IBOutlet weak var botonFalse: UIButton! + var quizBrain = QuizBrain() + + var timer = Timer() + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + cambiarPregunta() + } + + + @IBAction func botonRespuestaApretado(_ sender: UIButton) { + let respuesta = sender.currentTitle! + let respuestaCorrecta = quizBrain.verificarRespuesta(respuesta: respuesta) + if respuestaCorrecta { + quizBrain.aumentarPuntaje() + sender.backgroundColor = UIColor.green + } else { + sender.backgroundColor = UIColor.red + } + quizBrain.siguientePregunta() + + timer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false, block: { (time) in + self.cambiarPregunta() + }) + + + + + } + + + func cambiarPregunta(){ + + labelPregunta.text = quizBrain.getTextoPregunta() + barraProgreso.progress = quizBrain.getProgreso() + labelPuntaje.text = "Puntaje: \(quizBrain.getPuntaje())" + botonTrue.backgroundColor = UIColor.clear + botonFalse.backgroundColor = UIColor.clear + + } +} + diff --git a/Quizzler-iOS13/Model/Pregunta.swift b/Quizzler-iOS13/Model/Pregunta.swift new file mode 100644 index 00000000..6eaa392e --- /dev/null +++ b/Quizzler-iOS13/Model/Pregunta.swift @@ -0,0 +1,15 @@ +// +// Pregunta.swift +// Quizzler-iOS13 +// +// Created by Pablo Pizarro on 14/09/2022. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation + +struct Pregunta { + let q : String + let a : [String] + +} diff --git a/Quizzler-iOS13/Model/QuizBrain.swift b/Quizzler-iOS13/Model/QuizBrain.swift new file mode 100644 index 00000000..46808dfe --- /dev/null +++ b/Quizzler-iOS13/Model/QuizBrain.swift @@ -0,0 +1,70 @@ +// +// QuizBrain.swift +// Quizzler-iOS13 +// +// Created by Pablo Pizarro on 15/09/2022. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation + + +struct QuizBrain{ + let preguntas = [ Pregunta(q: "A slug's blood is green.", a: "True"), + Pregunta(q: "Approximately one quarter of human bones are in the feet.", a: "True"), + Pregunta(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"), + Pregunta(q: "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.", a: "True"), + Pregunta(q: "In London, UK, if you happen to die in the House of Parliament, you are technically entitled to a state funeral, because the building is considered too sacred a place.", a: "False"), + Pregunta(q: "It is illegal to pee in the Ocean in Portugal.", a: "True"), + Pregunta(q: "You can lead a cow down stairs but not up stairs.", a: "False"), + Pregunta(q: "Google was originally called 'Backrub'.", a: "True"), + Pregunta(q: "Buzz Aldrin's mother's maiden name was 'Moon'.", a: "True"), + Pregunta(q: "The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.", a: "False"), + Pregunta(q: "No piece of square dry paper can be folded in half more than 7 times.", a: "False"), + Pregunta(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True") + + ] + + + + + var preguntaActual = 0 + var puntaje = 0 + + + func verificarRespuesta(respuesta: String) -> Bool{ + if respuesta == preguntas[preguntaActual].a{ + return true + } else { + return false + + } + } + + + func getTextoPregunta() -> String{ + return preguntas[preguntaActual].q + } + + func getProgreso() -> Float{ + return Float(preguntaActual) / Float(preguntas.count - 1) + } + + //mutating para poder cambiar un variable del struct + mutating func siguientePregunta(){ + if preguntaActual < preguntas.count - 1{ + preguntaActual += 1 + } else { + puntaje = 0 + preguntaActual = 0 + } + } + + mutating func aumentarPuntaje(){ + self.puntaje += 1 + } + + func getPuntaje() -> Int{ + return self.puntaje + } +} diff --git a/Quizzler-iOS13/Base.lproj/Main.storyboard b/Quizzler-iOS13/View/Base.lproj/Main.storyboard similarity index 76% rename from Quizzler-iOS13/Base.lproj/Main.storyboard rename to Quizzler-iOS13/View/Base.lproj/Main.storyboard index b0f489aa..ad0d5238 100644 --- a/Quizzler-iOS13/Base.lproj/Main.storyboard +++ b/Quizzler-iOS13/View/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -24,13 +25,19 @@ + - - @@ -65,6 +78,7 @@ + @@ -75,8 +89,14 @@ - + + + + + + + diff --git a/Quizzler-iOS13/ViewController.swift b/Quizzler-iOS13/ViewController.swift deleted file mode 100644 index 39ffb5fc..00000000 --- a/Quizzler-iOS13/ViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// ViewController.swift -// Quizzler-iOS13 -// -// Created by Angela Yu on 12/07/2019. -// Copyright © 2019 The App Brewery. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} -