// // ContentView.swift // Word Teaser // // Created by George Robinson and Ginny Worley from 2/22/21 to 3/11/21. // import SwiftUI import AVFoundation import UIKit struct ContentView: View { // Structs used in programs struct AlertIdentifier: Identifiable { enum Alerts { case correct, wrong, clear, timeRunningOut } var id: Alerts } struct puzzleQuestions { var id: Int var pQuestion: String var pAnswer: Array } struct TupleIteratorL1: Sequence, IteratorProtocol { private var firstIterator: IndexingIterator<[String]> private var secondIterator: IndexingIterator<[Int]> init(playerL1: [String], scoreL1: [Int]) { self.firstIterator = playerL1.makeIterator() self.secondIterator = scoreL1.makeIterator() } mutating func next() -> (String, Int)? { guard let el1L1 = firstIterator.next(), let el2L2 = secondIterator.next() else { return nil } return (el1L1, el2L2) } } struct TupleIteratorL2: Sequence, IteratorProtocol { private var firstIterator: IndexingIterator<[String]> private var secondIterator: IndexingIterator<[Int]> init(playerL2: [String], scoreL2: [Int]) { self.firstIterator = playerL2.makeIterator() self.secondIterator = scoreL2.makeIterator() } mutating func next() -> (String, Int)? { guard let el1L2 = firstIterator.next(), let el2L2 = secondIterator.next() else { return nil } return (el1L2, el2L2) } } // Default Values @State var highScoreL1:Int = UserDefaults.standard.integer(forKey: "highScoreL1") @State var playerNameArrayL1 = UserDefaults.standard.array(forKey: "playerNameArrayL1") as? [String] ?? [String]() @State var highScoreArrayL1 = UserDefaults.standard.array(forKey: "highScoreArrayL1") as? [Int] ?? [Int]() @State var highScoreL2:Int = UserDefaults.standard.integer(forKey: "highScoreL2") @State var playerNameArrayL2 = UserDefaults.standard.array(forKey: "playerNameArrayL2") as? [String] ?? [String]() @State var highScoreArrayL2 = UserDefaults.standard.array(forKey: "highScoreArrayL2") as? [Int] ?? [Int]() @State var currentScore:Int = 0 @State var timeRemaining:Int = 300 @State var totalTime:Int = 0 var timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() @State var gameStart = true @State var gameRunning = false @State var gameOver = false @State var lastQuestion:Int = 9 @State var wrongAnswer = false @State var newHighScore = false @State private var questionText:String = "" @State private var Answer:String = "" //used at all? @State private var userAnswer:String = "" @State private var currentKey:Int = 0 @State private var userName:String = "" @State private var numOfWrongAnswers:Int = 0 @State private var numOfSkips:Int = 0 @State private var scoreMultiplier:Int = 1 let defaults = UserDefaults.standard @State var alertID: AlertIdentifier? let puzzleData = [ puzzleQuestions(id: 0, pQuestion: "What's missing: ABCDEFGHIJKLMNOPQRTVWXYZ", pAnswer: ["U"]), puzzleQuestions(id: 1, pQuestion: "What has a mouth, but cannot eat. Moves, but has no legs. Has a bank, but no money?", pAnswer: ["a river", "river", "rivers"]), puzzleQuestions(id: 2, pQuestion: "What has a spine but no bones?", pAnswer: ["a book", "books", "book"]), puzzleQuestions(id: 3, pQuestion: "Jimmy’s mother had four children. She named the first Monday. She named the second Tuesday, and she named the third Wednesday. What is the name of the fourth child?", pAnswer: ["Jimmy"]), puzzleQuestions(id: 4, pQuestion: "You are in a cabin and it is pitch black. You have one match on you. Which do light first, the newspaper, the lamp, the candle, or the fire?", pAnswer: ["Match", "A Match", "The Match"]), puzzleQuestions(id: 5, pQuestion: "In a year, there are 12 months. Seven months have 31 days. How many months have 28 days?", pAnswer:[ "12", "twelve", "all", "all of them"]), puzzleQuestions(id: 6, pQuestion: "What is always coming but never arrives?", pAnswer: ["tomorrow"]), puzzleQuestions(id: 7, pQuestion: "What is as big as an elephant but weighs nothing?", pAnswer: ["elephant’s shadow", "an elephant’s shadow"]), puzzleQuestions(id: 8, pQuestion: "You are a cyclist in a cross-country race. Just before crossing the finish line, you overtake the person in second place. In what place did you finish?", pAnswer: ["2nd place", "second", "second place", "2nd"]), puzzleQuestions(id: 9, pQuestion: "There are three houses. One is red, one is blue, and one is white. If the red house is to the left of the house in the middle, and the blue house is to the right to the house in the middle, where is the white house?", pAnswer: ["washington dc", "Washington D.C.", "dc"]), puzzleQuestions(id: 10, pQuestion: "Which word in the dictionary is spelled incorrectly?", pAnswer:["incorrectly"]), puzzleQuestions(id: 11, pQuestion: "What’s full of holes but still holds water?", pAnswer: ["a sponge", "sponge"]), puzzleQuestions(id: 12, pQuestion: "What goes up but never comes back down?", pAnswer:["your age", "age", "one’s age"]), puzzleQuestions(id: 13, pQuestion: "Where do you find keys that won’t work in a lock?", pAnswer: ["piano","piano keys", "on a piano"]), puzzleQuestions(id: 14, pQuestion: "What has a thousand needles but doesn’t sew?", pAnswer:["porcupine", "a porcupine"]), puzzleQuestions(id: 15, pQuestion: "What has teeth but can’t bite?", pAnswer: ["a comb", "comb"]), puzzleQuestions(id: 16, pQuestion: "What are the next three letters in the following sequence?J, F, M, A, M, J, J, A, __, __, __", pAnswer: ["S, O, N", "son", "s,o,n"]), puzzleQuestions(id: 17, pQuestion: "Which is heavier? A pound of feathers or a pound of rocks?", pAnswer: ["Neither", "same", "both"]), puzzleQuestions(id: 18, pQuestion: "What is tall when it's young and short when it’s old?", pAnswer: ["candle", "a candle"]), puzzleQuestions(id: 19, pQuestion: "What is the only number in the English language that is spelt with the same number of letters as the number itself?", pAnswer:["four", "4"]) ] var body: some View { if gameRunning { VStack { // Main Screen - VStack VStack { // Game Window -- VStack HStack{ //This Stack responsible for the scores and timer Spacer() VStack { //Current Score Stack Text("Current") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) Text(String(currentScore)) .font(.system(size: 18)) .fontWeight(.bold) .foregroundColor(Color.green) Text("Score") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) } Spacer() VStack(alignment: .center) { // Time Remaining Stack Text("Time") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) Text("\(timeRemaining)") .fontWeight(.bold) .font(.system(size: 20)) .onReceive(timer) { _ in if timeRemaining > 0 { timeRemaining -= 1 totalTime += 1 if (timeRemaining == 60 || timeRemaining == 30 || timeRemaining == 10) { self.alertID = AlertIdentifier(id: .timeRunningOut) } } else{ gameOver = true gameRunning = false storeScores() } }.foregroundColor(Color.red) Text("Remaining") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) } .padding(.horizontal, 5.0) .border(Color.purple) Spacer() VStack { // High Score Stack Text("High") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) if(currentKey == 0 || lastQuestion == 9){ Text("\(highScoreL1)") .font(.system(size: 18)) .fontWeight(.bold) .foregroundColor(Color.blue) }else if(currentKey == 10 || lastQuestion == 19){ Text("\(highScoreL2)") .font(.system(size: 18)) .fontWeight(.bold) .foregroundColor(Color.blue) } Text("Score") .fontWeight(.bold) .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) } Spacer() }.border(Color.purple) VStack { // This displays the question and retrieves the answer if puzzleData.isEmpty { Text("Loading") } else { Text(verbatim: puzzleData[currentKey].pQuestion) .padding(.horizontal, 12) .frame(width: 300, height: 275, alignment: .center) } TextField("Answer the question", text: $userAnswer)//.becomeFirstResponder() .padding(.all) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .textFieldStyle(RoundedBorderTextFieldStyle()) .cornerRadius(20) .foregroundColor(.red) } Spacer() VStack { // This stack contains the buttons for the game if (currentKey != lastQuestion) { if numOfSkips < 2 { Button("Skip Question") { currentKey += 1 numOfSkips += 1 currentScore -= (15 * scoreMultiplier) timeRemaining -= 2 } .padding(4) .border(Color.blue) .background(Color.red) .foregroundColor(.white) .font(.title) } } Button("Answer Question") { if (currentKey != lastQuestion) { for ans in puzzleData[currentKey].pAnswer { if (userAnswer.lowercased() == ans.lowercased()) { wrongAnswer = false break } else if (userAnswer.lowercased() != ans.lowercased() && numOfWrongAnswers < 2){ //change number back to 2 wrongAnswer = true } else { wrongAnswer = true } } if (wrongAnswer == true && numOfWrongAnswers < 2) { //change number back to two WrongAnswer() // Removes score/time, clears User Input numOfWrongAnswers += 1 } else if wrongAnswer == true { WrongAnswer() // Removes score/time, clears User Input numOfWrongAnswers = 0 // Resets Number of Wrong Answers currentKey += 1 //moves to next Question } else { AnswerQuestion() // Adds score/time, clears User Input & WrongAnswer counter currentKey += 1 //moves to next Question } } else { // This section deals with the final question for ans in puzzleData[currentKey].pAnswer { if (userAnswer.lowercased() == ans.lowercased()) { self.timer.upstream.connect().cancel() // Stops the Clock wrongAnswer = false break } else if (userAnswer.lowercased() != ans.lowercased() && numOfWrongAnswers < 2){ wrongAnswer = true } else { self.timer.upstream.connect().cancel() // Stops the Clock wrongAnswer = true } } if (wrongAnswer == true && numOfWrongAnswers < 2) { WrongAnswer() numOfWrongAnswers += 1 } else if wrongAnswer == true { WrongAnswer() storeScores() // Generates Final Score, Stores the Score in UserDefaults gameRunning = false // Ends the Game } else { AnswerQuestion() // Adds score/time, clears User Input & WrongAnswer counter storeScores() // Generates Final Score, Stores the Score in UserDefaults gameRunning = false } } } // Answer Button -- Close .padding(4) .border(Color.blue) .background(Color.green) .foregroundColor(.white) .font(.title) Spacer() Spacer() }// Buttons VStack -- Close } // Game Window VStack -- Close } // Main Screen VStack -- Close .background( Image("woodBoard") .resizable() .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/) .edgesIgnoringSafeArea(.all) ) .alert(item: $alertID) { alert in switch alert.id{ case .correct: return Alert(title: Text("Correct"), message: Text("Correct answer!"), dismissButton: .default(Text("OK"))) case .wrong: return Alert (title: Text("Incorrect"), message: Text("Your answer was wrong"), dismissButton: .default(Text("OK"))) case .clear: return Alert (title: Text("Let's start again!"), //message: Text(""), dismissButton: .default(Text("Start!"))) case .timeRunningOut: return Alert (title: Text("You have \(timeRemaining) seconds left!"), //message: Text(""), dismissButton: .default(Text("OK"))) } } } else if gameStart { //splash screen VStack { Image("WordTeaserBackground") .resizable() .frame(width: 175, height: 175) .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/) Text("Ten Questions to test your ability to do a word teaser.") .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .foregroundColor(.red) Text("1. You get three tries to answer a question correctly.") .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .foregroundColor(.red) Text("2. If you want to lose time and points skip a question.") .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .foregroundColor(.blue) Text("3. Caution you only get two skips per game. See how fast you can answer!") .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .foregroundColor(.blue) Text("See how fast you can answer!") .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .foregroundColor(.red) TextField("Enter your Name", text: $userName) .padding(.all) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .textFieldStyle(RoundedBorderTextFieldStyle()) .cornerRadius(20) .foregroundColor(.red) HStack { Spacer() Button("Start Level 1") { if userName == "" { } else { self.gameRunning = true self.gameStart = false currentKey = 0 lastQuestion = 9 scoreMultiplier = 1 } } .padding(6) .background(Color.white) .foregroundColor(.blue) .cornerRadius(20) .font(.system(size: 18)) Spacer() Button("Start Level 2") { if userName == "" { } else { self.gameRunning = true self.gameStart = false currentKey = 10 lastQuestion = 19 scoreMultiplier = 2 } } .padding(6) .background(Color.white) .foregroundColor(.green) .cornerRadius(20) .font(.system(size: 18)) Spacer() } Spacer() }.background( Image("woodBoard") .resizable() .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/) .edgesIgnoringSafeArea(.all) ) } else if (gameRunning == false && gameOver == false) { //finished game/won VStack{ VStack { Text("CONGRATULATIONS,") .fontWeight(.bold) .foregroundColor(Color.red) .font(.system(size: 18)) Text( "\(userName)!") .fontWeight(.bold) .foregroundColor(Color.blue) .font(.system(size: 18)) Text("You've finished the game!!") .foregroundColor(Color.black) .font(.system(size: 14)) Text("Your score was: " ) .foregroundColor(Color.black) .font(.system(size: 14)) Text("\(currentScore)") .fontWeight(.bold) .foregroundColor(Color.green) .font(.system(size: 16)) Text("It took you: " ) // This is a counting upwards clock .foregroundColor(Color.black) .multilineTextAlignment(.center) .font(.system(size: 14)) Text("\(totalTime)") .fontWeight(.bold) .foregroundColor(Color.green) .font(.system(size: 16)) Text("seconds to complete") .foregroundColor(Color.black) .font(.system(size: 14)) HStack { Button("Play Again?") { RestartGame() }.padding(6) .background(Color.white) .foregroundColor(.red) .cornerRadius(20) .font(.system(size: 18)) Button("Clear High Scores") { UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) } } } // Setting Up Top Players if (playerNameArrayL1.count > 0 && highScoreArrayL1.count > 0 && lastQuestion == 9) { let TopScore = TupleIteratorL1(playerL1: playerNameArrayL1, scoreL1: highScoreArrayL1) let SortedScores = TopScore.sorted(by: { $0.1 > $1.1 }) VStack { Text("High Scores for Level One: " ) .fontWeight(.bold) .foregroundColor(Color.blue) .multilineTextAlignment(.center) .font(.system(size: 14)) HStack { Spacer() Text("Place").padding(2) Spacer() Text("Player").padding(2) Spacer() Text("Score").padding(2) Spacer() } //.background(Color.blue) .foregroundColor(.red) .font(.system(size: 14)) List(SortedScores.indices) { i in HStack { Spacer() Text("\(i+1)") .padding(2) .multilineTextAlignment(.trailing) Spacer() Text("\(SortedScores[i].0)") .padding(2) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) Spacer() Text("\(SortedScores[i].1)").padding(2) .multilineTextAlignment(.trailing) Spacer() } }.background(Color.green) .foregroundColor(.blue) .font(.system(size: 14)) } }else if (playerNameArrayL2.count > 0 && highScoreArrayL2.count > 0 && lastQuestion == 19) { let TopScore = TupleIteratorL2(playerL2: playerNameArrayL2, scoreL2: highScoreArrayL2) let SortedScores = TopScore.sorted(by: { $0.1 > $1.1 }) VStack { Text("High Scores for Level Two: " ) .fontWeight(.bold) .foregroundColor(Color.blue) .multilineTextAlignment(.center) .font(.system(size: 14)) HStack { Spacer() Text("Place").padding(2) Spacer() Text("Player").padding(2) Spacer() Text("Score").padding(2) Spacer() } //.background(Color.blue) .foregroundColor(.red) .font(.system(size: 14)) List(SortedScores.indices) { i in HStack { Spacer() Text("\(i+1)") .padding(2) .multilineTextAlignment(.trailing) Spacer() Text("\(SortedScores[i].0)") .padding(2) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) Spacer() Text("\(SortedScores[i].1)").padding(2) .multilineTextAlignment(.trailing) Spacer() } }.background(Color.green) .foregroundColor(.blue) .font(.system(size: 14)) } } }.background( Image("woodBoard") .resizable() .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/) .edgesIgnoringSafeArea(.all) ) .alert(isPresented: $newHighScore ){ Alert (title: Text("Congrats, \(userName)!"), message: Text("You have the new highest score!"), dismissButton: .default(Text("OK"))) } } else if(gameOver == true){ //ran out of time VStack { VStack { HStack{ Text("You ran out of time,") .padding(.all) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) .textFieldStyle(RoundedBorderTextFieldStyle()) .foregroundColor(.red) Text( "\(userName)!") .fontWeight(.bold) .foregroundColor(Color.blue) .font(.system(size: 18)) } HStack{ Text("Your score was: " ) .foregroundColor(Color.black) .font(.system(size: 14)) Text("\(currentScore)") .fontWeight(.bold) .foregroundColor(Color.green) .font(.system(size: 16)) } HStack { Button("Play Again?") { RestartGame() }.padding(6) .background(Color.white) .foregroundColor(.red) .cornerRadius(20) .font(.system(size: 18)) Button("Clear High Scores") { UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) } } } if (playerNameArrayL1.count > 0 && highScoreArrayL1.count > 0 && lastQuestion == 9) { let TopScore = TupleIteratorL1(playerL1: playerNameArrayL1, scoreL1: highScoreArrayL1) let SortedScores = TopScore.sorted(by: { $0.1 > $1.1 }) VStack { Text("High Scores for Level One: " ) .fontWeight(.bold) .foregroundColor(Color.blue) .multilineTextAlignment(.center) .font(.system(size: 14)) HStack { Spacer() Text("Place").padding(2) Spacer() Text("Player").padding(2) Spacer() Text("Score").padding(2) Spacer() } //.background(Color.blue) .foregroundColor(.red) .font(.system(size: 14)) List(SortedScores.indices) { i in HStack { Spacer() Text("\(i+1)") .padding(2) .multilineTextAlignment(.trailing) Spacer() Text("\(SortedScores[i].0)") .padding(2) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) Spacer() Text("\(SortedScores[i].1)").padding(2) .multilineTextAlignment(.trailing) Spacer() } }.background(Color.green) .foregroundColor(.blue) .font(.system(size: 14)) } }else if (playerNameArrayL2.count > 0 && highScoreArrayL2.count > 0 && lastQuestion == 19) { let TopScore = TupleIteratorL2(playerL2: playerNameArrayL2, scoreL2: highScoreArrayL2) let SortedScores = TopScore.sorted(by: { $0.1 > $1.1 }) VStack { Text("High Scores for Level Two: " ) .fontWeight(.bold) .foregroundColor(Color.blue) .multilineTextAlignment(.center) .font(.system(size: 14)) HStack { Spacer() Text("Place").padding(2) Spacer() Text("Player").padding(2) Spacer() Text("Score").padding(2) Spacer() } //.background(Color.blue) .foregroundColor(.red) .font(.system(size: 14)) List(SortedScores.indices) { i in HStack { Spacer() Text("\(i+1)") .padding(2) .multilineTextAlignment(.trailing) Spacer() Text("\(SortedScores[i].0)") .padding(2) .multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) Spacer() Text("\(SortedScores[i].1)").padding(2) .multilineTextAlignment(.trailing) Spacer() } }.background(Color.green) .foregroundColor(.blue) .font(.system(size: 14)) } } }.background( Image("woodBoard") .resizable() .aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/) .edgesIgnoringSafeArea(.all) ) .alert(isPresented: $newHighScore ){ Alert (title: Text("Congrats, \(userName)!"), message: Text("You have the new highest score!"), dismissButton: .default(Text("OK"))) } } } //var body: some View func AnswerQuestion() { currentScore += (30 * scoreMultiplier) //adds 30 points to score timeRemaining += 20 //adds 20 seconds to time userAnswer.removeAll() // Clear User Answer numOfWrongAnswers = 0 self.alertID = AlertIdentifier(id: .correct) } func WrongAnswer() { self.alertID = AlertIdentifier(id: .wrong) currentScore -= (25 * scoreMultiplier) //subtracts from score timeRemaining -= 10 //subtracts 10 seconds from time userAnswer.removeAll() // Clear User Answer } func storeScores() { currentScore += timeRemaining // adds the time remaining to the player score if(lastQuestion == 9){ playerNameArrayL1.append(userName) // appends the current player's name to the playerNameArray highScoreArrayL1.append(currentScore) // appends the current player's score to the playerNameArray if currentScore > highScoreL1 { highScoreL1 = currentScore UserDefaults.standard.set(self.highScoreL1, forKey: "highScoreL1") self.newHighScore = true } UserDefaults.standard.set(self.playerNameArrayL1, forKey: "playerNameArrayL1") UserDefaults.standard.set(self.highScoreArrayL1, forKey: "highScoreArrayL1") } else if(lastQuestion == 19) { playerNameArrayL2.append(userName) // appends the current player's name to the playerNameArray highScoreArrayL2.append(currentScore) // appends the current player's score to the playerNameArray if currentScore > highScoreL2 { highScoreL2 = currentScore UserDefaults.standard.set(self.highScoreL1, forKey: "highScoreL2") self.newHighScore = true } UserDefaults.standard.set(self.playerNameArrayL2, forKey: "playerNameArrayL2") UserDefaults.standard.set(self.highScoreArrayL2, forKey: "highScoreArrayL2") } //UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) //UserDefaults.standard.synchronize() //---I'm not sure if we need this } func RestartGame() { gameStart = true // Resets Game Start Flag gameOver = false // Resets Game Over Flag timeRemaining = 300 // 300 change back to whatever the first time is currentKey = 0 // Resets Current Key for questions and answers to 0 currentScore = 0 // Resets Current Score for player to 0 numOfSkips = 0 // Resets the number of skipped questions to 0 totalTime = 0 // Resets the total play time to 0 self.alertID = AlertIdentifier(id: .clear) // To change it from correct or wrong answer } } //struct ContentView: View end curly struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }