diff --git a/CSE4095Lab4.xcodeproj/project.pbxproj b/CSE4095Lab4.xcodeproj/project.pbxproj index 2f06e58..11cdc52 100644 --- a/CSE4095Lab4.xcodeproj/project.pbxproj +++ b/CSE4095Lab4.xcodeproj/project.pbxproj @@ -16,6 +16,10 @@ B94D97DC2401E8CD00B87CAF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B94D97DA2401E8CD00B87CAF /* LaunchScreen.storyboard */; }; B94D97E72401E8CE00B87CAF /* CSE4095Lab4Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D97E62401E8CE00B87CAF /* CSE4095Lab4Tests.swift */; }; B94D97F22401E8CE00B87CAF /* CSE4095Lab4UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D97F12401E8CE00B87CAF /* CSE4095Lab4UITests.swift */; }; + B94D98002401EA6D00B87CAF /* ThirdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D97FF2401EA6D00B87CAF /* ThirdViewController.swift */; }; + B94D98022401EC5900B87CAF /* LoginController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D98012401EC5900B87CAF /* LoginController.swift */; }; + B94D980424020EF800B87CAF /* Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D980324020EF800B87CAF /* Country.swift */; }; + B94D980624023F6800B87CAF /* Questions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94D980524023F6800B87CAF /* Questions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -51,6 +55,10 @@ B94D97ED2401E8CE00B87CAF /* CSE4095Lab4UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CSE4095Lab4UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B94D97F12401E8CE00B87CAF /* CSE4095Lab4UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSE4095Lab4UITests.swift; sourceTree = ""; }; B94D97F32401E8CE00B87CAF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B94D97FF2401EA6D00B87CAF /* ThirdViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThirdViewController.swift; sourceTree = ""; }; + B94D98012401EC5900B87CAF /* LoginController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginController.swift; sourceTree = ""; }; + B94D980324020EF800B87CAF /* Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = ""; }; + B94D980524023F6800B87CAF /* Questions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Questions.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -103,9 +111,13 @@ children = ( B94D97CD2401E8CC00B87CAF /* AppDelegate.swift */, B94D97CF2401E8CC00B87CAF /* SceneDelegate.swift */, + B94D98012401EC5900B87CAF /* LoginController.swift */, B94D97D12401E8CC00B87CAF /* FirstViewController.swift */, B94D97D32401E8CC00B87CAF /* SecondViewController.swift */, + B94D97FF2401EA6D00B87CAF /* ThirdViewController.swift */, B94D97D52401E8CC00B87CAF /* Main.storyboard */, + B94D980324020EF800B87CAF /* Country.swift */, + B94D980524023F6800B87CAF /* Questions.swift */, B94D97D82401E8CD00B87CAF /* Assets.xcassets */, B94D97DA2401E8CD00B87CAF /* LaunchScreen.storyboard */, B94D97DD2401E8CD00B87CAF /* Info.plist */, @@ -262,8 +274,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B94D980424020EF800B87CAF /* Country.swift in Sources */, B94D97D42401E8CC00B87CAF /* SecondViewController.swift in Sources */, + B94D98022401EC5900B87CAF /* LoginController.swift in Sources */, B94D97D22401E8CC00B87CAF /* FirstViewController.swift in Sources */, + B94D98002401EA6D00B87CAF /* ThirdViewController.swift in Sources */, + B94D980624023F6800B87CAF /* Questions.swift in Sources */, B94D97CE2401E8CC00B87CAF /* AppDelegate.swift in Sources */, B94D97D02401E8CC00B87CAF /* SceneDelegate.swift in Sources */, ); diff --git a/CSE4095Lab4.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/CSE4095Lab4.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..85c68c7 --- /dev/null +++ b/CSE4095Lab4.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/CSE4095Lab4/Assets.xcassets/earth.imageset/Contents.json b/CSE4095Lab4/Assets.xcassets/earth.imageset/Contents.json new file mode 100644 index 0000000..66dbdc4 --- /dev/null +++ b/CSE4095Lab4/Assets.xcassets/earth.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "earth.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/CSE4095Lab4/Assets.xcassets/earth.imageset/earth.png b/CSE4095Lab4/Assets.xcassets/earth.imageset/earth.png new file mode 100644 index 0000000..53e7021 Binary files /dev/null and b/CSE4095Lab4/Assets.xcassets/earth.imageset/earth.png differ diff --git a/CSE4095Lab4/Base.lproj/LaunchScreen.storyboard b/CSE4095Lab4/Base.lproj/LaunchScreen.storyboard index 865e932..f61a8e3 100644 --- a/CSE4095Lab4/Base.lproj/LaunchScreen.storyboard +++ b/CSE4095Lab4/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - - + + + - + @@ -11,15 +12,39 @@ - + - + + + + + + + + + + + + + + + + + - + + + + diff --git a/CSE4095Lab4/Base.lproj/Main.storyboard b/CSE4095Lab4/Base.lproj/Main.storyboard index 7a85710..0af16ca 100644 --- a/CSE4095Lab4/Base.lproj/Main.storyboard +++ b/CSE4095Lab4/Base.lproj/Main.storyboard @@ -1,86 +1,234 @@ - + + - + - + - + - + - - + - - - - + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - + - + - - + + @@ -88,15 +236,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + diff --git a/CSE4095Lab4/Country.swift b/CSE4095Lab4/Country.swift new file mode 100644 index 0000000..54d24c9 --- /dev/null +++ b/CSE4095Lab4/Country.swift @@ -0,0 +1,14 @@ +// +// Country.swift +// CSE4095Lab4 +// +// Created by Kenny Payes on 2/22/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import Foundation + +struct Country: Decodable { + let name: String + let alpha3Code: String +} diff --git a/CSE4095Lab4/Info.plist b/CSE4095Lab4/Info.plist index e7f6f58..cc83265 100644 --- a/CSE4095Lab4/Info.plist +++ b/CSE4095Lab4/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable diff --git a/CSE4095Lab4/LoginController.swift b/CSE4095Lab4/LoginController.swift new file mode 100644 index 0000000..9f1bc89 --- /dev/null +++ b/CSE4095Lab4/LoginController.swift @@ -0,0 +1,32 @@ +// +// SecondViewController.swift +// CSE4095Lab4 +// +// Created by Kenny Payes on 2/22/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import UIKit + +class LoginController: UIViewController { + + @IBOutlet weak var alert: UILabel! + @IBOutlet weak var userText: UITextField! + @IBOutlet weak var passwordText: UITextField! + override func viewDidLoad() { + super.viewDidLoad() + + } + + + @IBAction func goPressed(_ sender: Any) { + if userText.text != "" && passwordText.text != ""{ + + performSegue(withIdentifier: "tabView", sender: self) + + } + else{ + alert.text = "incorrect username/ password" + } + } +} diff --git a/CSE4095Lab4/Questions.swift b/CSE4095Lab4/Questions.swift new file mode 100644 index 0000000..3b990a4 --- /dev/null +++ b/CSE4095Lab4/Questions.swift @@ -0,0 +1,88 @@ +// +// Questions.swift +// CSE4095Lab4 +// +// Created by Kenny Payes on 2/23/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import Foundation + +class Questions { + + @Published var countries = [Country]() + private var country = [String]() + private var alpha = [String]() + private var questionList = [[String]]() + + private var score: Int = 0 + private var questionNumber: Int = 0 + + let url = "http://restcountries.eu/rest/v2/all" + + private func getQuestions() { + + let countryURL = URL(string: url) + + //URLSession.shared.dataTask(with: countryURL!) {( data, reponse, error) in + + do{ + let data = try Data(contentsOf: countryURL!) + self.countries = try JSONDecoder().decode([Country].self, from: data) + + for c in self.countries{ + self.country.append(String(c.name)) + self.alpha.append(String(c.alpha3Code)) + } + + } catch{ + print(error) + } + } + //} + + public func Questions() { + getQuestions() + for i in 0...24{ + let num = Int.random(in: 0..<250) + questionList.append([country[num], alpha[num]]) + } + } + public func resetQuestions() { + for i in 0...24{ + let num = Int.random(in: 0..<250) + questionList.append([country[num], alpha[num]]) + } + } + + public func getScore() ->Int{ + return score + } + + public func getQuestion() -> String{ + return questionList[questionNumber][0] + } + public func getAnswer() -> String { + return questionList[questionNumber][1] + } + + public func nextQuestion() { + questionNumber += 1 + } + + public func correctAnswer() { + questionNumber += 1 + score += 1 + } + public func reset() { + score = 0 + questionList.removeAll() + resetQuestions() + questionNumber = 0 + } + public func getQuestionNumber() -> Int{ + return questionNumber + } +} + + diff --git a/CSE4095Lab4/SecondViewController.swift b/CSE4095Lab4/SecondViewController.swift index 50cccf8..cfc7974 100644 --- a/CSE4095Lab4/SecondViewController.swift +++ b/CSE4095Lab4/SecondViewController.swift @@ -9,12 +9,66 @@ import UIKit class SecondViewController: UIViewController { - + + @IBOutlet weak var score: UILabel! + @IBOutlet weak var givenCountry: UILabel! + @IBOutlet weak var answerText: UITextField! + @IBOutlet weak var finalScore: UILabel! + @IBOutlet weak var submitButton: UIButton! + let Qs = Questions() + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. + + Qs.Questions() + givenCountry.text = Qs.getQuestion() + + } + + + @IBAction func submitPressed(_ sender: Any) { + + if Qs.getQuestionNumber() == 24{ + if answerText.text?.lowercased() == Qs.getAnswer().lowercased(){ + finalScore.text = ("Final Score: " + String( ( Double((Double(Qs.getScore()) + 1.0) / 25.0)*100.0) ) + "%") + submitButton.isEnabled = false + answerText.isEnabled = false + + } + else{finalScore.text = ("Final Score: " + String( Double((Double(Qs.getScore()) / 25.0))*100.0) + "%" ) + submitButton.isEnabled = false + answerText.isEnabled = false + } + } + else{ + + if answerText.text?.lowercased() == Qs.getAnswer().lowercased(){ + Qs.correctAnswer() + answerText.text = "" + givenCountry.text = Qs.getQuestion() + score.text = ("Score: " + String(Qs.getScore())) + } + else{ + Qs.nextQuestion() + answerText.text = "" + givenCountry.text = Qs.getQuestion() + score.text = ("Score: " + String(Qs.getScore())) + + } + } + } + + @IBAction func resetPressed(_ sender: Any) { + Qs.reset() + Qs.Questions() + givenCountry.text = Qs.getQuestion() + score.text = ("Score: " + String(Qs.getScore())) + finalScore.text = "" + submitButton.isEnabled = true + answerText.isEnabled = true } - - } + + diff --git a/CSE4095Lab4/ThirdViewController.swift b/CSE4095Lab4/ThirdViewController.swift new file mode 100644 index 0000000..00aa3f5 --- /dev/null +++ b/CSE4095Lab4/ThirdViewController.swift @@ -0,0 +1,21 @@ +// +// SecondViewController.swift +// CSE4095Lab4 +// +// Created by Kenny Payes on 2/22/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import UIKit + +class ThirdViewController: UIViewController { + + @IBOutlet weak var earth: UIImageView! + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + earth.image = UIImage(named: "earth") + } + + +}