Comp 110 Choose Your Own Adventure

In this problem set you will create a choose your own adventure game! You can make your story follow any arc you'd like and we encourage you to go beyond the minimum requirements set out in these instructions for additional practice.

Try out a demo solution to this problem set.

We will have a competition for the best Choose Your Own Adventure app this semester and the Top 3 will be shared with the class and beyond. Submitting your project for consideration is opt-in.

This problem set will provide practice with:

  • void functions
  • prompting the user for inputs
  • if-then-else statements
  • function calls

Part 0. Starting the Dev Environment

As with in lecture, begin by opening up VSCode, ensuring your project is still open, and then running the following two commands in the VSCode Integrated Terminal:

  1. npm run pull
  2. npm run start

The first command "pulls" the latest files needed for COMP110 into your repo, if any. The second command starts the development environment and will open your web browser to the local server.

Part 1. Setting up an App

In the comp110-17f project used in lecture:

  1. Right click on the "src" folder
  2. Select "New Folder"
  3. Name the new folder: ps01-adventure
    1. Note: capitalization and punctuation are important!
  4. Right click on the folder you just created
  5. Select "New File"
  6. Name the new file: index-app.ts
    1. Note: capitalization and punctuation are important!
    2. Note: the i in index is lowercase!

Part 2. Programming your Adventure

Your adventure will consist of a set of void functions that fall into one of two categories: story line functions and choice forking functions.

To pass the grader, you must name the required functions exactly as specified in this document. The overall map for the required paths of the adventure are shown below:

Pro-tip: You will save yourself a lot of time if you try to jot down your overall story line's text before beginning the programming.

Try out a demo solution to this problem set.

(Reminder: You should come up with a story of your own! The use of images is optional but encouraged. If you would like to add your own custom images, try uploading them to imgur.com)


Honor Code Header

All problem sets begin with an Honor Code pledge. Notice this header is contained within block comment tags discussed in Lecture 1. You can copy/paste the pledge below and fill in your name and ONYEN.

/** 
 * Author: 
 * ONYEN: 
 * UNC Honor Pledge: I certify that no unauthorized assistance has been received 
 * or given in the completion of this work. I certify that I understand and 
 * could now rewrite on my own, without assistance from course staff,  
 * the problem set code I am submitting.
 */

Imports

The next step after ensuring the honor code header in starting most projects this semester is importing the introcs library. This library provides many of the functions we will use (i.e. printimagepromptString, and so on). The first line of code to add to your app is the following:

import "introcs";

Exported Functions

In this problem set and future problem sets, you will be asked to implement exported functions. By exporting your functions, we are able to test them. Defining an exported function is the same as any other function, except that it begins with the keyword export. For example:

export function main(): void {
    // main's function body goes here
}

If you do not export a function, it will appear to the grader that you did not write the function at all!


Requirement 0. Define an exported function with the following properties:

0.0 - Name: main

0.1 - Parameters: none

0.2 - Return Type: void

0.3 - Functionality: 

0.3.1 - Print an introduction to your adventure. 

0.3.2 - Print two options, "a" or "b" for the user to choose from. 

0.3.3 - Call the main function to start your program.

Testing Checkpoint - Before you implement the 0.3.4 prompt requirement below, be sure that your introduction and options are successfully printing out first.

0.3.4 - Prompt the user for a string. (See lecture 2 and the documentation below on how to prompt for a string.) The callback function for the prompt is Requirement 1's forkMain function. (Note: TypeScript will show an error until you define the forkMain function for Requirement 1.)


How to prompt for a string?

The introcs library defines the following promptString function:

function promptString(text: string, callback: function): void;

text - The instruction text to prompt the user with.

callback - The name of a void function that has a single string parameter. This function will be called once the user has input a string into the prompt and pressed OK.


Requirement 1. Define an exported function with the properties below. This function with send the user to the next part of the story.

1.0 - Name: forkMain

1.1 - Parameters: a single parameter named choice of type string

1.2 - Return Type: void

1.3 - Functionality:

1.3.0 - Clear the screen by calling the clear function, like so: clear();

Testing Checkpoint - Before you implement the full requirements below, try initially just printing the strings "storyA" or "storyB" in each of their respective cases, and then replace the print statements with calls to the functions once you've completed Requirements 2 and 3.

1.3.1 - When the user's choice is "a" (case sensitive!), call the storyA function of Requirement 2.

1.3.2 - When the user's choice is "b" (case sensitive!), call the storyB function of Requirement 4.

1.3.3 - For any other input, call the main function of Requirement 0.


Requirement 2. Define an exported function with the following properties.

2.0 - Name: storyA

2.1 - Parameters: none

2.2 - Return type: void

2.3 - Functionality:

2.3.0 - Print an update to your story line based on the user choosing "a" in the main function's prompt.

2.3.1 - Print two options, 1 or 2, for the user to choose from.

Testing Checkpoint - Before you implement the 2.3.2 prompt requirement below, ensure that when you enter a lowercase "a" at your main prompt, the storyA function you've just defined is now being called from within the forkMain function.

2.3.2 -  Prompt the user for a number. (See lecture 2 for how to prompt for a number.) The callback function for the prompt is Requirement 3's forkA function. This will create an error in your code until you have defined Requirement 3's forkA function.


Requirement 3. Define an exported function with the following properties.

3.0 - Name: forkA

3.1 - Parameters: a single parameter named choice of type number

3.2 - Return type: void

3.3 - Functionality: 

3.3.0 - Clear the screen by calling the clear function, like so: clear();

Testing Checkpoint - Before you implement the full requirements below, try initially just printing the strings "storyC" and "storyD" in each of their respective cases, and then replace the print statements with calls to the actual functions once you've completed Requirements 5 and 6.

3.3.1 - When the user's choice is 1, call the storyC function of Requirement 6.

3.3.2 - When the user's choice is 2, call the storyD function of Requirement 7.

3.3.3 - For any other input, call the storyA function of Requirement 2.


Requirement 4. Define an exported function with the following properties.

4.0 - Name: storyB

4.1 - Parameters: none

4.2 - Return type: void

4.3 - Functionality:

4.3.0 - Print an update to your story line based on the user choosing "b" in the main function's prompt.

4.3.1 - Print two options, 1 or 2, for the user to choose from.

Testing Checkpoint - Before you implement the 4.3.2 prompt requirement below, ensure that when you enter a lowercase "b" at your main prompt, the storyB function you've just defined is now being called from within the forkMain function.

4.3.2 -  Prompt the user for a number. (See lecture 2 for how to prompt for a number.) The callback function for the prompt is Requirement 5's forkB function. This will create an error in your code until you have defined Requirement 5's forkB function.


Requirement 5. Define an exported function with the following properties.

5.0 - Name: forkB

5.1 - Parameters: a single parameter named choice of type number

5.2 - Return type: void

5.3 - Functionality: 

5.3.0 - Clear the screen by calling the clear function, like so: clear();

Testing Checkpoint - Before you implement the full requirements below, try initially just printing the strings "storyE" and "storyF" in each of their respective cases, and then replace the print statements with calls to the actual functions once you've completed Requirements 8 and 9.

5.3.1 - When the user's choice is 1, call the storyE function of Requirement 8.

5.3.2 - When the user's choice is 2, call the storyF function of Requirement 9.

5.3.3 - For any other input, call the storyB function of Requirement 4.


Requirement 6. Define an exported function with the following properties.

6.0 - Name: storyC

6.1 - Parameters: none

6.2 - Return type: void

6.3 - Functionality: Print an update to your story line based on the user choosing "1" in the storyA function's prompt.


Requirement 7. Define an exported function with the following properties.

7.0 - Name: storyD

7.1 - Parameters: none

7.2 - Return type: void

7.3 - Functionality: Print an update to your story line based on the user choosing "2" in the storyA function's prompt.


Requirement 8. Define an exported function with the following properties.

8.0 - Name: storyE

8.1 - Parameters: none

8.2 - Return type: void

8.3 - Functionality: Print an update to your story line based on the user choosing "1" in the storyB function's prompt.


Requirement 9. Define an exported function with the following properties.

9.0 - Name: storyF

9.1 - Parameters: none

9.2 - Return type: void

9.3 - Functionality: Print an update to your story line based on the user choosing "2" in the storyB function's prompt.


Part 3. Publish Your Adventure & Enter the Competition!

With your program running in your web browser, find the green "Publish App" button. If you are not still logged into introcs.com, you will be prompted to log in, and then your app will be bundled and published to the web! Once it's ready, you will be given a URL to it which you can pass along to whomever you want to share your adventure with.

Did you come up with a really fun or creative adventure? Enter your adventure into the class competition by submitting it on the following form: https://goo.gl/forms/tL4JVtaee...


Part 4. Submitting for Grading

The auto-grader will be posted by September 11th.

To submit for grading first publish your project as per Part 3. Then, go to My110 and select "Submit" next to the assignment. From here you should see a button that allows you to submit for grading. Your work will be graded through an automated process. If you receive points off, please select the "Report" link to see which tests did not pass. You can resubmit as many times as you'd like without penalty up until the deadline. We want you to keep working toward full credit on problem sets!


Challenge Extensions

Want to take your adventure above and beyond the baseline requirements? Awesome!

These extensions are for street cred and extra practice only. So go ahead and get full credit and extra credit by completing the baseline requirements and submitting early. Once you've got full credit, try some of these ideas out...

0. Make the initial prompt case insensitive by allowing "a" OR "A" vs. "b" OR "B". You will still receive full credit if you implement this check.

1. Extend your story deeper beyond where we ended our graph.

2. When you reach the end of the story, ask the user if they'd like to play again and start over.

3. Build a mini-game with a score (like a best-of-3 rock, paper, scissors) into one of your story lines after the required story lines.

4. Add easter eggs. Hint: we will only test the "?" paths of your story by testing letters "c" through "f" and numbers 3 through 9. You can safely add special paths earlier in your story outside of these ranges.