From 42ccf3e788d8478295c529b30c2881eb28f9fdfb Mon Sep 17 00:00:00 2001 From: Matt Digel Date: Thu, 17 Dec 2020 14:15:29 -0800 Subject: [PATCH 1/2] First choice working --- Destini-iOS13/Controller/ViewController.swift | 30 +++++++++++++++++-- Destini-iOS13/Model/Story.swift | 13 ++++++++ Destini-iOS13/Model/StoryBrain.swift | 17 +++++++++++ Destini-iOS13/View/Base.lproj/Main.storyboard | 23 ++++++++++---- 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/Destini-iOS13/Controller/ViewController.swift b/Destini-iOS13/Controller/ViewController.swift index 5f43b76..4434d78 100644 --- a/Destini-iOS13/Controller/ViewController.swift +++ b/Destini-iOS13/Controller/ViewController.swift @@ -13,12 +13,38 @@ class ViewController: UIViewController { @IBOutlet weak var storyLabel: UILabel! @IBOutlet weak var choice1Button: UIButton! @IBOutlet weak var choice2Button: UIButton! + var storyBrain = StoryBrain() + + + + + override func viewDidLoad() { super.viewDidLoad() - + + updateUI() } - + @IBAction func choiceMade(_ sender: UIButton) { + + // save user's choice + let userChoice = sender.currentTitle! + + // determine next question based on user choice + storyBrain.nextChoice(userChoice) + + updateUI() + + } + + func updateUI() { + let tempCurrentStory = storyBrain.currentStory + storyLabel.text = storyBrain.example[tempCurrentStory].story0 + choice1Button.setTitle(storyBrain.example[tempCurrentStory].choice1, for: .normal) + choice2Button.setTitle(storyBrain.example[tempCurrentStory].choice2, for: .normal) + + } + } diff --git a/Destini-iOS13/Model/Story.swift b/Destini-iOS13/Model/Story.swift index d73a218..c3651a4 100644 --- a/Destini-iOS13/Model/Story.swift +++ b/Destini-iOS13/Model/Story.swift @@ -7,3 +7,16 @@ // import Foundation + +struct Story { + var story0: String + var choice1: String + var choice2: String + + init(s: String, c1: String, c2: String){ + self.story0 = s + self.choice1 = c1 + self.choice2 = c2 + + } +} diff --git a/Destini-iOS13/Model/StoryBrain.swift b/Destini-iOS13/Model/StoryBrain.swift index 5978616..88716c6 100644 --- a/Destini-iOS13/Model/StoryBrain.swift +++ b/Destini-iOS13/Model/StoryBrain.swift @@ -8,4 +8,21 @@ import Foundation +struct StoryBrain { + var currentStory = 0 + let example = [ + Story(s: "You see a fork in the road.", c1: "Take a left.", c2: "Take a right."), + Story(s: "You see a tiger", c1: "Shout for help", c2: "Play dead" ), + Story(s: "You find a treasure chest", c1: "Open it", c2: "Check for traps") + ] + + mutating func nextChoice(_ userChoice: String) { + if userChoice == "Take a left." { + currentStory = 1 + } else if userChoice == "Take a right." { + currentStory = 2 + } + } +} + diff --git a/Destini-iOS13/View/Base.lproj/Main.storyboard b/Destini-iOS13/View/Base.lproj/Main.storyboard index 78c4fc4..46f910c 100644 --- a/Destini-iOS13/View/Base.lproj/Main.storyboard +++ b/Destini-iOS13/View/Base.lproj/Main.storyboard @@ -1,9 +1,11 @@ - + - + + + @@ -34,7 +36,7 @@ - - - + + - @@ -93,5 +101,8 @@ + + + From fdf79d0c9a8294d7939235ef9ba4e6302f19ce30 Mon Sep 17 00:00:00 2001 From: Matt Digel Date: Thu, 17 Dec 2020 14:36:06 -0800 Subject: [PATCH 2/2] Complete with Quiz Feature --- Destini-iOS13.xcodeproj/project.pbxproj | 4 +- Destini-iOS13/Controller/ViewController.swift | 6 +- Destini-iOS13/Model/Story.swift | 11 ++-- Destini-iOS13/Model/StoryBrain.swift | 60 ++++++++++++++++--- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/Destini-iOS13.xcodeproj/project.pbxproj b/Destini-iOS13.xcodeproj/project.pbxproj index 6dc4f0e..ff2f7cc 100644 --- a/Destini-iOS13.xcodeproj/project.pbxproj +++ b/Destini-iOS13.xcodeproj/project.pbxproj @@ -127,7 +127,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1100; - LastUpgradeCheck = 1100; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = "The App Brewery"; TargetAttributes = { AD7631CF22FC5E7E00C6E71B = { @@ -228,6 +228,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -288,6 +289,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; diff --git a/Destini-iOS13/Controller/ViewController.swift b/Destini-iOS13/Controller/ViewController.swift index 4434d78..a44f66d 100644 --- a/Destini-iOS13/Controller/ViewController.swift +++ b/Destini-iOS13/Controller/ViewController.swift @@ -40,9 +40,9 @@ class ViewController: UIViewController { func updateUI() { let tempCurrentStory = storyBrain.currentStory - storyLabel.text = storyBrain.example[tempCurrentStory].story0 - choice1Button.setTitle(storyBrain.example[tempCurrentStory].choice1, for: .normal) - choice2Button.setTitle(storyBrain.example[tempCurrentStory].choice2, for: .normal) + storyLabel.text = storyBrain.allStories[tempCurrentStory].title + choice1Button.setTitle(storyBrain.allStories[tempCurrentStory].choice1, for: .normal) + choice2Button.setTitle(storyBrain.allStories[tempCurrentStory].choice2, for: .normal) } diff --git a/Destini-iOS13/Model/Story.swift b/Destini-iOS13/Model/Story.swift index c3651a4..c1c5354 100644 --- a/Destini-iOS13/Model/Story.swift +++ b/Destini-iOS13/Model/Story.swift @@ -9,14 +9,17 @@ import Foundation struct Story { - var story0: String + var title: String var choice1: String var choice2: String + var choice1Destination: Int + var choice2Destination: Int - init(s: String, c1: String, c2: String){ - self.story0 = s + init(title: String, choice1 c1: String,choice1Destination: Int, choice2 c2: String, choice2Destination: Int){ + self.title = title self.choice1 = c1 self.choice2 = c2 - + self.choice1Destination = choice1Destination + self.choice2Destination = choice2Destination } } diff --git a/Destini-iOS13/Model/StoryBrain.swift b/Destini-iOS13/Model/StoryBrain.swift index 88716c6..b73adc5 100644 --- a/Destini-iOS13/Model/StoryBrain.swift +++ b/Destini-iOS13/Model/StoryBrain.swift @@ -10,19 +10,63 @@ import Foundation struct StoryBrain { var currentStory = 0 - let example = [ - Story(s: "You see a fork in the road.", c1: "Take a left.", c2: "Take a right."), - Story(s: "You see a tiger", c1: "Shout for help", c2: "Play dead" ), - Story(s: "You find a treasure chest", c1: "Open it", c2: "Check for traps") + let allStories = [ + Story( + title: "Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: 'Need a ride, boy?'.", + choice1: "I'll hop in. Thanks for the help!", + choice1Destination: 2, + choice2: "Better ask him if he's a murderer first.", + choice2Destination: 1 + ), + Story( + title: "He nods slowly, unfazed by the question.", + choice1: "At least he's honest. I'll climb in.", + choice1Destination: 2, + choice2: "Wait, I know how to change a tire.", + choice2Destination: 3 + ), + Story( + title: "As you begin to drive, the stranger starts talking about his relationship with his mother. He gets angrier and angrier by the minute. He asks you to open the glovebox. Inside you find a bloody knife, two severed fingers, and a cassette tape of Elton John. He reaches for the glove box.", + choice1: "I love Elton John! Hand him the cassette tape.", + choice1Destination: 5, + choice2: "It's him or me! You take the knife and stab him.", + choice2Destination: 4 + ), + Story( + title: "What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?", + choice1: "The", + choice1Destination: 0, + choice2: "End", + choice2Destination: 0 + ), + Story( + title: "As you smash through the guardrail and careen towards the jagged rocks below you reflect on the dubious wisdom of stabbing someone while they are driving a car you are in.", + choice1: "The", + choice1Destination: 0, + choice2: "End", + choice2Destination: 0 + ), + Story( + title: "You bond with the murderer while crooning verses of 'Can you feel the love tonight'. He drops you off at the next town. Before you go he asks you if you know any good places to dump bodies. You reply: 'Try the pier.'", + choice1: "The", + choice1Destination: 0, + choice2: "End", + choice2Destination: 0 + ) + ] mutating func nextChoice(_ userChoice: String) { - if userChoice == "Take a left." { - currentStory = 1 - } else if userChoice == "Take a right." { - currentStory = 2 + // create variable for current stories details + let currentStoryDetails = allStories[currentStory] + + if userChoice == currentStoryDetails.choice1 { + currentStory = currentStoryDetails.choice1Destination + } else if userChoice == currentStoryDetails.choice2 { + currentStory = currentStoryDetails.choice2Destination } } + }