Skip to content

Instantly share code, notes, and snippets.

@Alicelovecode
Last active August 17, 2017 13:05
Show Gist options
  • Select an option

  • Save Alicelovecode/9e7aebf6ca6c7fe2c7185eed724f9129 to your computer and use it in GitHub Desktop.

Select an option

Save Alicelovecode/9e7aebf6ca6c7fe2c7185eed724f9129 to your computer and use it in GitHub Desktop.
Destini.swift
import UIKit
class ViewController: UIViewController {
// Our strings
let story1 = "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?\"."
let answer1a = "I\'ll hop in. Thanks for the help!"
let answer1b = "Better ask him if he\'s a murderer first."
let story2 = "He nods slowly, unphased by the question."
let answer2a = "At least he\'s honest. I\'ll climb in."
let answer2b = "Wait, I know how to change a tire."
let story3 = "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."
let answer3a = "I love Elton John! Hand him the cassette tape."
let answer3b = "It\'s him or me! You take the knife and stab him."
let story4 = "What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?"
let story5 = "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."
let story6 = "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.\""
// UI Elements linked to the storyboard
@IBOutlet weak var topButton: UIButton! // Has TAG = 1
@IBOutlet weak var bottomButton: UIButton! // Has TAG = 2
@IBOutlet weak var storyTextView: UILabel!
@IBOutlet weak var restartButtom: UIButton!
// TODO Step 5: Initialise instance variables here
//設置關卡storyIndex = 1為第一關
var storyIndex = 1
override func viewDidLoad() {
super.viewDidLoad()
storyTextView.text = story1
topButton.setTitle(answer1a, for: .normal)
bottomButton.setTitle(answer1b, for: .normal)
restartButtom.isHidden = true
// 藏起來restart的label
// TODO Step 3: Set the text for the storyTextView, topButton, bottomButton, and to T1_Story, T1_Ans1, and T1_Ans2
}
// User presses one of the buttons
//配置樹狀圖
@IBAction func buttonPressed(_ sender: UIButton) {
if sender.tag == 1 && storyIndex == 1 {
storyTextView.text = story3
topButton.setTitle(answer3a, for: .normal)
bottomButton.setTitle(answer3b, for: .normal)
storyIndex = 3
}else if sender.tag == 2 && storyIndex == 1{
storyTextView.text = story2
topButton.setTitle(answer2a, for: .normal)
bottomButton.setTitle(answer2b, for: .normal)
storyIndex = 2
}else if sender.tag == 1 && storyIndex == 2{
storyTextView.text = story3
topButton.setTitle(answer3a, for: .normal)
bottomButton.setTitle(answer3b, for: .normal)
storyIndex = 3
}else if sender.tag == 2 && storyIndex == 2{
storyTextView.text = story4
topButton.isHidden = true
bottomButton.isHidden = true
}else if sender.tag == 1 && storyIndex == 3{
storyTextView.text = story6
topButton.isHidden = true
bottomButton.isHidden = true
storyIndex = 6
}else if sender.tag == 2 && storyIndex == 3{
storyTextView.text = story5
topButton.isHidden = true
bottomButton.isHidden = true
storyIndex = 5
}
if bottomButton.isHidden {
restartButtom.isHidden = false
}
}
// TODO Step 4: Write an IF-Statement to update the views
@IBAction func restartPressed(_ sender: UIButton) {
restart()
restartButtom.isHidden = true
}
func restart(){
storyIndex = 1
storyTextView.text = story1
topButton.isHidden = false
bottomButton.isHidden = false
topButton.setTitle(answer1a, for: .normal)
bottomButton.setTitle(answer1b, for: .normal)
}
}
// TODO Step 6: Modify the IF-Statement to complete the story
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment