Text101 - Simple Text Adventure

Here’s my completed game for Text101! I have no idea how to get it all to fit within one blockquote, so if someone can help me out with that I’d appreciate it lol.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextController : MonoBehaviour
{

    public Text text;
    private enum States {intro, cell, mirror, sheets_0, lock_0, cell_mirror, sheets_1, lock_1, freedom, cells, prisoner_failure,
                         stairs, guard, patrol, jump};
    private States myState;
    int Patrol;

	// Use this for initialization
	void Start ()
    {
        myState = States.intro;
        Patrol = 0;
	}
	
	// Update is called once per frame
	void Update ()
    {
        print(myState);
        if (myState == States.intro)                 { State_intro(); }
        else if (myState == States.cell)             { State_cell(); }
        else if (myState == States.sheets_0)         { State_sheets_0(); }
        else if (myState == States.mirror)           { State_mirror(); }
        else if (myState == States.lock_0)           { State_lock_0(); }
        else if (myState == States.cell_mirror)      { State_cell_mirror(); }
        else if (myState == States.lock_1)           { State_lock_1(); }
        else if (myState == States.sheets_1)         { State_sheets_1(); }
        else if (myState == States.freedom)          { State_freedom(); }
        else if (myState == States.cells)            { State_cells(); }
        else if (myState == States.prisoner_failure) { State_prisoner_failure(); }
        else if (myState == States.stairs)           { State_stairs(); }
        else if (myState == States.guard)            { State_guard(); }
        else if (myState == States.patrol)           { State_patrol(); }
        else if (myState == States.jump)             { State_jump(); }
    }

    // This state is the state in which the player begins.
    void State_intro()
    {
        text.text = "Freedom. Rights. Privilege. Life. \n\n" +
                    "   Imprisoned as you are, freedom is a vague and" +
                    " long forgotten concept. You were stripped of your" +
                    " rights, freedom and privilege when you deprived" +
                    " another of their life. You aren't innocent and" +
                    " wrongly imprisoned. You belong here. You deserver this." +
                    " Despite this you fear death, and with your execution" +
                    " looming you look to escape.\n\n" +
                    "   You look about your prison cell for any means of escape." +
                    " There are some dirt sheets on the bed, a mirror on the wall," +
                    " and the door is locked from the outside.\n\n" +
                    "Press \"S\" to view the Sheets, \"M\" to view the Mirror, and \"L\" to view the lock.";
        if (Input.GetKeyDown(KeyCode.S))        {myState = States.sheets_0;}
        else if (Input.GetKeyDown(KeyCode.M))   {myState = States.mirror;}
        else if (Input.GetKeyDown(KeyCode.L))   {myState = States.lock_0; }
    }
    void State_cell()
    {
        text.text = "   You look about your prison cell for any means of escape." +
                    " There are some dirt sheets on the bed, a mirror on the wall," +
                    " and the door is locked from the outside.\n\n" +
                    "Press \"S\" to view the Sheets, \"M\" to view the Mirror, and \"L\" to view the lock.";
        if (Input.GetKeyDown(KeyCode.S)) { myState = States.sheets_0; }
        else if (Input.GetKeyDown(KeyCode.M)) { myState = States.mirror; }
        else if (Input.GetKeyDown(KeyCode.L)) { myState = States.lock_0; }
    }
    void State_sheets_0()
    {
        text.text = "These sheets are disgustingly filthy. It isn't" +
                    " as thought prisoners on Death Row need to worry" +
                    " about cleanliness now is it?\n\n" +
                    "Press \"R\" to Return to roaming your cell.";
        if (Input.GetKeyDown(KeyCode.R))        {myState = States.cell;}
    }
    void State_lock_0()
    {
        text.text = "This is one of those button locks. You have no idea what the " +
                    "combination is. You wish you could somehow see where the dirty " +
                    "fingerprints were, maybe that would help.\n\n" +
                    "Press \"R\" to Return to roaming your cell.";
        if (Input.GetKeyDown(KeyCode.R))        { myState = States.cell; }
    }
    void State_mirror()
    {
        text.text = "The cell mirror is cracked, with a sizeable piece sitting loosely" +
                    " in place.\n\n" +
                    "Press \"T\" to take the loose piece of mirror or \"R\" to return to roaming your cell.";
        if (Input.GetKeyDown(KeyCode.T))        {  myState = States.cell_mirror; }
        else if (Input.GetKeyDown(KeyCode.R))   {  myState = States.cell; }
    }
    void State_sheets_1()
    {
        text.text = "Holding a piece of mirror in your hand doesn't make the sheets" +
                    " look any better.\n\n" +
                    "Press \"R\" to Return to roaming your cell.";
        if (Input.GetKeyDown(KeyCode.R))
        {
            myState = States.cell_mirror;
        }
    }
    void State_lock_1()
    {
        text.text = "Using the piece of mirror you're able to get a look at the keypad." +
                    " You can clearly see which 4 numbers the code is comprised of. You" +
                    " reach through the bars and try combinations until you hear the lock click open.\n\n" +
                    "Press \"O\" to open your cell door.";
        if (Input.GetKeyDown(KeyCode.O))
        {
            myState = States.freedom;
        }
    }
    void State_cell_mirror()
    {
        text.text = "Taking the piece of mirror, you return to looking around your cell for a means of escape.\n\n" +
                    "Press \"S\" to view the sheets,  and \"L\" to view the lock.";
        if (Input.GetKeyDown(KeyCode.S))        { myState = States.sheets_1; }
        if (Input.GetKeyDown(KeyCode.L))        { myState = States.lock_1; }
    }
    void State_freedom()
    {
        text.text = "Freedom is one step closer. Now that you're out of your cell, " +
                    "you're on a corridor on the second level of the cell block.\n\n" +
                    "At a glance, you see that the corridor is lined with cells on one side," +
                    " there's a guard rail running along the length of one side over which" +
                    " you can see a door at one end of the lower level. You also see" +
                    " that there's a set of stairs leading down. There's currently no guard in sight.\n\n" +
                    "Press \"C\" to look in the other cells on this level, \"S\" to take the stairs down a level" +
                    ", or \"G\" to silently look for the guard.";
        if (Input.GetKeyDown(KeyCode.C))        { myState = States.cells; }
        else if (Input.GetKeyDown(KeyCode.S))   { myState = States.stairs; }
        else if (Input.GetKeyDown(KeyCode.G))   { myState = States.guard; }
    }
    void State_cells()
    {
        text.text = "Silently stepping down the corridor you look in to each of the other cells" +
                    " on this level. All but one are locked and empty, with the last having another" +
                    " prisoner held within, sleeping soundly.\n\n" +
                    "Press \"R\" to return to outside of your cell,  or \"W\" to quielty try and wake the prisoner.";
        if (Input.GetKeyDown(KeyCode.R))        { myState = States.freedom; }
        else if (Input.GetKeyDown(KeyCode.W))   { myState = States.prisoner_failure; }
    }
    void State_guard()
    {
        text.text = "You lay down on the floor and silently slide to the guard rail, looking under it" +
                    " to try and see a guard in the corridor below. As you watch for a moment, looking " +
                    "back and forth, a guard comes in to view making his rounds.\n\n" +
                    "Press \"R\" to return to outside of your cell,  \"S\" to take the stairs and try to" +
                    " sneak up behind the guard, or \"P\" to watch the guard patrol and discern a pattern to his movements.";
        if (Input.GetKeyDown(KeyCode.R))        { myState = States.freedom; }
        else if (Input.GetKeyDown(KeyCode.S))   { myState = States.stairs;  }
        else if (Input.GetKeyDown(KeyCode.P))   { myState = States.patrol; }
    }
    void State_patrol()
    {
        if (Patrol == 0)
        { 
            text.text = "As you watch the guard from above you see that he walks to thend of the corridor with the" +
                        " door before turning around and heading back towards the rest of the cells.\n\n" +
                        "Press \"P\" to continue watching the guard patrol,  or \"R\" to slide back to the corridor out of view.";
            if (Input.GetKeyDown(KeyCode.P))            { myState = States.patrol; Patrol = Patrol + 1; }
            else if (Input.GetKeyDown(KeyCode.R))       { myState = States.freedom; }
        }
        else if (Patrol == 1)
        {
            text.text = "As you watch the guard continue his rounds you see that if he continues on his" +
                        " current path he will come to the stairs, potentially ascending to your level.\n\n" +
                        "Press \"P\" to continue watching the guard patrol, \"J\" to try to jump on the" +
                        " guard as he passes below, or \"R\" to slide back to the corridor out of view.";
            if (Input.GetKeyDown(KeyCode.P))            { myState = States.patrol; Patrol = Patrol + 1; }
            else if (Input.GetKeyDown(KeyCode.J))       { myState = States.jump; }
            else if (Input.GetKeyDown(KeyCode.R))       { myState = States.freedom; }
        }
        else if (Patrol >= 2)
        {
            text.text = "Silently you continue to watch the guard move towards the stairs, and he becomes" +
                        " obscured by them as he walks past. Moments go by, and you then hear the unmistakable" +
                        " sound of boots on metal stairs just as the guard's head emerges above the stairs." +
                        " Before you can make a move, the guard sees you, grabs for his radio, and signals that" +
                        " a prisoner has escaped his cell. Alarms blare as he pulls his gun and aims it at you." +
                        " Your attempted escape has failed.\n\n" +
                        "GAME OVER. \n\n" +
                        "Press \"Space\" to try again.";
            if (Input.GetKeyDown(KeyCode.Space))         { myState = States.intro; Patrol = 0; }
        }
    }
    void State_jump()
    {
        text.text = "Watching the guard, you vault over the guard rail and fall. You have timed it" +
                    " perfectly and you slam feet first into the guard's head. He crumples to the ground" +
                    " without so much as a grunt. Coming to your feet, you search the guard for a keycard." +
                    " You find one and move to the door. When you pass the card over the access pad on the wall," +
                    " it beeps and you hear the unmistakable click of the latch unlocking.\n\n" +
                    "Congratulations for making it this far! The escape continue in the forthcoming installment" +
                    "in the series, \"PRISON 2: JAILBIRD\".\n\n" +
                    "Press \"Space\" to play again.";
        if (Input.GetKeyDown(KeyCode.Space))     { myState = States.intro; }
    }
    void State_prisoner_failure()
    {
        text.text = "You gently tap on the bars, causing a quiet ringing sound and whisper \"Psst...\" to the prisoner." +
                    " Startled awawke, the prisoner yelps, \"No it isn't my time yet!\" while flailing slightly to a sitting" +
                    " position. Moments later, you hear footsteps behind you and as you turn to face them, you are" +
                    " clubbed in the head and everything fades to black...\n\n" +
                    "GAME OVER.\n\n" +
                    "Press \"Space\" to try again.";
        if (Input.GetKeyDown(KeyCode.Space)) { myState = States.intro; }
    }
    void State_stairs()
    {
        text.text = "You silently make your way to the stairs, carefully stepping down to avoid making any noise. " +
                    " Once you reach the foot of the stairs, you make your way to the door to try and escape. It's" +
                    " locked and you see an access pad on the wall adjacent that you hadn't noticed from above." +
                    " As you jiggle the handle you hear footsteps behind you. You turn towards the noise," +
                    " and as you do so you're clubbed in the head and everything fades to black.\n\n" +
                    "GAME OVER.\n\n" +
                    "Press \"Space\" to try again.";
        if (Input.GetKeyDown(KeyCode.Space))        { myState = States.intro; }
    }
}

Hi Patrick,

Thanks for sharing with the community, but also for asking how to resolve the code formatting.

There is a Forum User Guide for this very subject, I’ve linked it below for you, and I’ve updated your post to reflect these changes.

Hope this helps :slight_smile:


See also;

Thank you Rob! I wasn’t even sure what to call that type of look in a post >.>

1 Like

You’re more than welcome :slight_smile:

Privacy & Terms