Giter Site home page Giter Site logo

pursuit-core-ios-unit1-assignment1's Introduction

Text-Based-Adventure

Instructions for lab submission

  1. Fork the assignment repo
  2. Clone your Fork to your machine
  3. Complete the lab
  4. Push your changes to your Fork
  5. Submit a Pull Request back to the assignment repo
  6. Paste a link to your Pull Request (not your fork!) on Canvas and submit

Lab

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:

App requirements:

  • Your command line app must build and run with no compiler errors or warnings
  • Have at least 10 opportunities for the user to make decisions
  • Have at least one opportunity where the user will enter a number (see converting Strings to numbers)
  • Use both Switch statements and If/Else Statements
  • Use both type annotation and type inference to set variables
  • Use at least one tuple in your code
  • Use at least range in your code
  • Use a for loop in your code
  • Use a while loop in your code
  • Hints:

    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")
    }

    pursuit-core-ios-unit1-assignment1's People

    Contributors

    alexpaul avatar ellefaraday avatar davidlawrencer avatar

    Watchers

    James Cloos avatar

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.