Cornelius Eanes's Programming Portal
[PROJECT 1] Choose Your Own Slightly Longer Adventure

Goal: Create a large choose-your-own-adventure game with 21 rooms and 12 outcomes.

/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: Choose Your Slightly Longer Adventure
/// File Name: ChooseYourOwnAdventure2.java
/// Date Finished: Oct 19, 2015

import java.util.Scanner;

public class ChooseYourOwnAdventure2 {

    static Scanner input = new Scanner(System.in);
    static String[] rooms = new String[] {
            // [0] start
            "Your friends dared you to partake in their Horror House Escape Challenge. The goal is to sneak into a recently foreclosed house, grab something interesting, and escape with it.\nDo you start by (1) entering via the front door, (2) checking the right side of the house, or (3) checking the left side of the house?",
            /* DEPTH: 1 */
            // [1] from [0] (1)
            "After a bit of force, the front door flies open. A dimly lit hallway is revealed. You didn't realize the electricity was cut off yet. You see a stairwell and a hallway in front of you.\nDo you (1) ascend the stairwell or (2) explore what's in the hallway?",
            // [2] from [0] (2)
            "You managed to find an unlocked window on the right side of the house. You find yourself in a bedroom of sorts. You see a closed jewelry box and a closet.\nDo you (1) open the jewelry box or (2) check out the closet?",
            // [3] from [0] (3)
            "You find your way into the backyard through the left side. It has a few large trees in it, and there's an entrance into the house via the sliding glass door.\nDo you (1) explore the backyard or (2) enter the house?",
            /* DEPTH: 2 */
            // [4] from [1] (1)
            "Upon ascending the stairwell, you see a room marked \"Study\" and a vase on a nearby table.\nDo you (1) explore the study or (2) grab the vase and get out?",
            // [5] from [1] (2)
            "Upon entering the hallway, you see a necklace around a bust. It appears to be made of gold. On the wall, there appears to be a well-maintained painting.\nDo you grab (1) the necklace or (2) the painting?",
            // [6] from [2] (1)
            "Upon opening the jewelry box, you hear an agonizingly loud screech. You look up at the mirror. It reads \"don't take what's not yours\".\nDo you (1) ignore the warning or (2) leave immediately?",
            // [7] from [2] (2)
            "Upon entering the closet, you hear a soft sobbing sound. A little girl appears to be crying in the corner.\nDo you (1) see what the girl wants or (2) leave her be?",
            // [8] from [3] (1)
            "Upon closer inspection of the backyard, you find a garden shed, seemingly unlocked, and an outside garage.\nDo you enter the (1) garden shed or (2) garage?",
            // [9] from [3] (2)
            "The sliding glass door opens with ease. You find yourself in a kitchen, with delicate china on a nearby cabinet and a gold-plated bowl on the table.\nDo you take the (1) china or (2) bowl?",
            /* DEPTH: 3 (ENDINGS) */
            // [10] from [4] (1)
            "Inside the study, you find a pale high-school-looking boy studying at his desk. Without looking at you, he screams \"I'VE TOLD YOU BEFORE, DON'T GO INTO MY ROOM EVER AGAIN!\".\nHe turns around, with a wide grin and empty eyes, lunges at you with a knife. You get stabbed in the heart before you realize it.\n\nBAD END",
            // [11] from [4] (2)
            "Upon touching the vase, it instantly shatters, with millions of tiny pieces everywhere. A pale, older-looking woman stand beside you, saying \"I told you what would happen the next time you did that, right?\"\nbefore proceeding to smacking you in the face, causing you tumble down the stairs. Your landing isn't successful, and you break your neck.\n\nBAD END",
            // [12] from [5] (1)
            "Nothing happens when you take the necklace. You put it around your neck. Before you can react, the necklace tightens up, creating a noose around you.\nYou are asphyxiated over the next several painful moments.\n\nBAD END",
            // [13] from [5] (2)
            "Upon touching the painting, the colors suddenly start to run. A loud scream is heard, and your neck is grabbed by a hand outstretching from the painting. You die of asphyxiation.\n\nBAD END",
            // [14] from [6] (1)
            "You reach again for the jewelery box. The mirror shatters and its large pieces penetrate your skin. You die of massive blood loss.\n\nBAD END",
            // [15] from [6] (2)
            "You practically leap out of the window, and escape from the grounds. No one at school believes what you saw.\n\nSAFE END",
            // [16] from [7] (1)
            "You girl looks up with large, sad eyes. You ask \"What's the matter?\". The girl says \"Thank you for lending a helping hand. I'll treat you to whatever you want in this house.\". You grab the jewelry box and safely escape from the house.\n\nPROSPEROUS END",
            // [17] from [7] (2)
            "You try leaving the closet. However, the girl suddenly appears in front of you, with black, soulless eyes, blocking your path. With a loud roar, she slams and locks the door shut. You die of dehydration 3 days later.\n\nBAD END",
            // [18] from [8] (1)
            "You see a lawn mower in the shed, along with some seemingly unused tools. However, a trowel hanging just above you falls down, impaling you.\n\nBAD END",
            // [19] from [8] (2)
            "Upon entering the garage, you see a pale male figure inside. Before you can react, he sees you, and screams with horror, carrying a realistic-looking shotgun. Turns out, it wasn't just for show.\n\nBAD END",
            // [20] from [9] (1)
            "You take the china off of the shelves. However, you didn't notice the slight tipping the cabinet was exhibiting. While your back is turned, it falls over, knocking the wind and life out of you.\n\nBAD END",
            // [21] from [9] (2)
            "Nothing significant happens when grabbing the bowl. You show your friends your finding, and go home with your prize. You wake up in agonizing pain, your hands deeply blackened and raw. Turns out, the bowl was lined with a deadly poison. You find out too late.\n\nBAD END"
    };
    static int firstRoom = 0;

    public static void main(String[] args) {

        System.out.println("Welcome to the Horror House Escape Challenge!\n");

        int choice = prompt(firstRoom);
        if (choice == 1) {
            choice = prompt(1);
            if (choice == 1) {
                choice = prompt(4);
                if (choice == 1) {
                    ending(10);
                } else {
                    ending(11);
                }
            } else {
                choice = prompt(5);
                if (choice == 1) {
                    ending(12);
                } else {
                    ending(13);
                }
            }
        } else if (choice == 2) {
            choice = prompt(2);
            if (choice == 1) {
                choice = prompt(6);
                if (choice == 1) {
                    ending(14);
                } else {
                    ending(15);
                }
            } else {
                choice = prompt(7);
                if (choice == 1) {
                    ending(16);
                } else {
                    ending(17);
                }
            }
        } else {
            choice = prompt(3);
            if (choice == 1) {
                choice = prompt(8);
                if (choice == 1) {
                    ending(18);
                } else {
                    ending(19);
                }
            } else {
                choice = prompt(9);
                if (choice == 1) {
                    ending(20);
                } else {
                    ending(21);
                }
            }
        }

        System.out.println("THANK YOU FOR PLAYING!");

    }

    static int prompt(int roomNum) {
        System.out.println();
        System.out.println(rooms[roomNum]);
        System.out.print("> ");
        String in = input.nextLine();
        try {
            int choice = Integer.parseInt(in);
            if (choice >= 0 && roomNum == firstRoom ? choice <= 3 : choice <= 2) {
                return choice;
            }
        } catch (NumberFormatException e) {}
        System.out.println("ERROR: Invalid input received: " + in + ". Will automatically choose (1).");
        return 1;
    }

    static void ending(int roomNum) {
        System.out.println();
        System.out.println(rooms[roomNum]);
        System.out.println();
    }

}

Output