diff --git a/Quizzler-iOS13/Controller/ViewController.swift b/Quizzler-iOS13/Controller/ViewController.swift new file mode 100644 index 00000000..f69cbfc3 --- /dev/null +++ b/Quizzler-iOS13/Controller/ViewController.swift @@ -0,0 +1,58 @@ +// +// 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 scoreLabel: UILabel! + @IBOutlet weak var questionLabel: UILabel! + + @IBOutlet weak var falseButton: UIButton! + @IBOutlet weak var trueButton: UIButton! + + @IBOutlet weak var progressbar: UIProgressView! + + + + var quizBrain=QuizBrain() + + override func viewDidLoad() { + super.viewDidLoad() + updateUI() + // Do any additional setup after loading the view. + } + + @IBAction func answerButtonPressed(_ sender: Any) { + + let userAnswer=(sender as AnyObject).currentTitle! ?? "0" + let userGotItRight=quizBrain.checkAnswer(userAnswer) //Using the property of QuizBrain method and userAnswer is a internal parameter name + + + if userGotItRight{ + trueButton.backgroundColor=UIColor.green + } + else{ + falseButton.backgroundColor=UIColor.red + } + quizBrain.nextQuestion() + + Timer.scheduledTimer(timeInterval: 0.2, target: self, selector:#selector(updateUI), userInfo: nil, repeats: false) + + } + @objc func updateUI(){ + questionLabel.text=quizBrain.getQuestionText() + progressbar.progress=quizBrain.getProgress() + scoreLabel.text="Score: \(quizBrain.getScore())" + trueButton.backgroundColor=UIColor.clear + falseButton.backgroundColor=UIColor.clear + + } + + +} + diff --git a/Quizzler-iOS13/Model/Question.swift b/Quizzler-iOS13/Model/Question.swift new file mode 100644 index 00000000..590aa548 --- /dev/null +++ b/Quizzler-iOS13/Model/Question.swift @@ -0,0 +1,17 @@ +// +// Question.swift +// Quizzler-iOS13 +// +// Created by Jalaj's Macbook on 27/09/22. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation +struct Question{ + let text:String + let answer:String + init(q:String,a:String){ + text=q + answer=a + } +} diff --git a/Quizzler-iOS13/Model/QuizBrain.swift b/Quizzler-iOS13/Model/QuizBrain.swift new file mode 100644 index 00000000..e1145c3c --- /dev/null +++ b/Quizzler-iOS13/Model/QuizBrain.swift @@ -0,0 +1,61 @@ +// +// QuizBrain.swift +// Quizzler-iOS13 +// +// Created by Jalaj's Macbook on 27/09/22. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation +struct QuizBrain{ + let quiz=[Question(q: "A slug's blood is green.", a: "True"), + Question(q: "Approximately one quarter of human bones are in the feet.", a: "True"), + Question(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"), + Question(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"), + Question(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"), + Question(q: "It is illegal to pee in the Ocean in Portugal.", a: "True"), + Question(q: "You can lead a cow down stairs but not up stairs.", a: "False"), + Question(q: "Google was originally called 'Backrub'.", a: "True"), + Question(q: "Buzz Aldrin's mother's maiden name was 'Moon'.", a: "True"), + Question(q: "The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.", a: "False"), + Question(q: "No piece of square dry paper can be folded in half more than 7 times.", a: "False"), + Question(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True") + + ] + var questionNumber=0 + var score=0 + mutating func checkAnswer(_ userAnswer:String) -> Bool{ + if userAnswer==quiz[questionNumber].answer{ + score+=1 + return true + //Got it right + } + else{ + return false + //User got it wrong + } + } + func getQuestionText()->String{ + return quiz[questionNumber].text + + } + + + func getProgress()->Float{ + return Float(questionNumber+1)/Float(quiz.count) + } + mutating func nextQuestion(){ + if questionNumber+1Int{ + return score + } +} diff --git a/Quizzler-iOS13/View/Base.lproj/Main.storyboard b/Quizzler-iOS13/View/Base.lproj/Main.storyboard new file mode 100644 index 00000000..07d3b46c --- /dev/null +++ b/Quizzler-iOS13/View/Base.lproj/Main.storyboard @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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. - } - - -} -