- Fork the assignment repo
- Clone your Fork to your machine
- Complete the lab
- Push your changes to your Fork
- Submit a Pull Request back to the assignment repo
- Paste a link to your Pull Request (not your fork!) on Canvas and submit
This lab will build on the skills that you've learned after your first week of programming in Swift! You will build a command line application that plays a text-based adventure game. Look here and here for a couple examples of the genre. Be creative with your app. Submit your assignment by copying and pasting your code into the text box below. Apps will be evaluated by the following criteria:
Use the following line to get user input
let response = readLine()
//The type of response is Optional String
Converting String to a number Type
let userEnteredNumAsString = readLine()!
let userEnteredNumAsInt = Int(userEnteredNumAsString)!
//This will crash if you don't have a valid Int
Sample code with conditional logic:
print("Your adventure begins! Choose your direction \"Up\" or \"Down\"") //Use \ to escape characters
let UpOrDown = readLine()!
var weapon = "" //Set variables here and you can change and use their values later
var eggExploded = false
switch UpOrDown {
case "Up":
print("You see a basket of eggs. How many do you take?")
let eggNum = readLine()!
let eggNumAsInt = Int(eggNum)!
for currentEgg in 1...eggNumAsInt {
print("You carefully remove egg number \(currentEgg)")
if currentEgg == 4 {
print("It was a trap! The egg explodes")
eggExploded = true
}
}
if !eggExploded {
print("Congrats! You made it out with \(eggNumAsInt) eggs!")
}
//More decisions ahead! Use conditionals and switch statements here
case "Down":
print("Down you go!")
//Instructions for the "Down" option ahead!
default:
print("You stand your ground. Choose a weapon")
weapon = readLine()!
//Fighting conditionals ahead!
}
if weapon != "" {
print("You survived your first ordeal and even have a \(weapon) to take home")
}
if eggExploded {
print("Bad luck! Don't take so many eggs")
}