Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mybranch #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Quizzler-iOS13/Controller/ViewController.swift
Original file line number Diff line number Diff line change
@@ -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

}


}

17 changes: 17 additions & 0 deletions Quizzler-iOS13/Model/Question.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
61 changes: 61 additions & 0 deletions Quizzler-iOS13/Model/QuizBrain.swift
Original file line number Diff line number Diff line change
@@ -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+1<quiz.count{
questionNumber+=1
}
else{
questionNumber=0
score=0
}
}


mutating func getScore()->Int{
return score
}
}
109 changes: 109 additions & 0 deletions Quizzler-iOS13/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Quizzler_iOS13" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="500" verticalCompressionResistancePriority="1000" image="Background-Bubbles" translatesAutoresizingMaskIntoConstraints="NO" id="eGL-jB-Wwb">
<rect key="frame" x="0.0" y="794" width="414" height="102"/>
<constraints>
<constraint firstAttribute="height" constant="102" id="7ES-Tc-xxA"/>
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="fal-oS-tEg">
<rect key="frame" x="20" y="44" width="374" height="818"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ARW-lY-nx5">
<rect key="frame" x="0.0" y="0.0" width="374" height="71.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalCompressionResistancePriority="1000" text="Question Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rSI-li-mhO">
<rect key="frame" x="0.0" y="81.5" width="374" height="536.5"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oVw-Hl-IRe">
<rect key="frame" x="0.0" y="628" width="374" height="80"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="ueD-qr-2mT"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<inset key="titleEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="True" backgroundImage="Rectangle">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="answerButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="3zc-Z2-Aiu"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tbn-vQ-GyC">
<rect key="frame" x="0.0" y="718" width="374" height="80"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="fNm-VT-9Ox"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<inset key="titleEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="False" backgroundImage="Rectangle">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="answerButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6Ry-B6-yRX"/>
</connections>
</button>
<progressView opaque="NO" contentMode="scaleToFill" progressViewStyle="bar" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="TXm-qh-7Xg">
<rect key="frame" x="0.0" y="808" width="374" height="11"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="tintColor" red="0.2770131528" green="0.3800790906" blue="0.57570761439999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="vxo-8A-N6S"/>
</constraints>
<color key="progressTintColor" red="1" green="0.45854175089999999" blue="0.6605013609" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="trackTintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</progressView>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" red="0.14509803921568626" green="0.17254901960784313" blue="0.29019607843137252" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="fal-oS-tEg" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="9eb-B8-Mk2"/>
<constraint firstItem="eGL-jB-Wwb" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="IXF-La-IbW"/>
<constraint firstAttribute="bottom" secondItem="eGL-jB-Wwb" secondAttribute="bottom" id="LxD-MF-eVq"/>
<constraint firstAttribute="trailingMargin" secondItem="fal-oS-tEg" secondAttribute="trailing" id="TqZ-Hr-0o6"/>
<constraint firstItem="fal-oS-tEg" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="U28-8f-QT9"/>
<constraint firstItem="eGL-jB-Wwb" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="gVb-OT-BWs"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="fal-oS-tEg" secondAttribute="bottom" id="wj6-TI-6C2"/>
</constraints>
</view>
<connections>
<outlet property="falseButton" destination="tbn-vQ-GyC" id="EPl-WK-lCp"/>
<outlet property="progressbar" destination="TXm-qh-7Xg" id="PPW-Ks-crT"/>
<outlet property="questionLabel" destination="rSI-li-mhO" id="Gyx-PY-MLu"/>
<outlet property="scoreLabel" destination="ARW-lY-nx5" id="oK7-5A-P6u"/>
<outlet property="trueButton" destination="oVw-Hl-IRe" id="vzb-MM-YCr"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.23188405797103" y="135.26785714285714"/>
</scene>
</scenes>
<resources>
<image name="Background-Bubbles" width="352" height="102"/>
<image name="Rectangle" width="322" height="68"/>
</resources>
</document>
20 changes: 0 additions & 20 deletions Quizzler-iOS13/ViewController.swift

This file was deleted.