Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PGF1Week2Project : MonoBehaviour
- {
- Text screen;
- Page[] book;
- [SerializeField]
- string currHeading;
- [SerializeField]
- string nextHeading = "wake up";
- [SerializeField]
- string prevHeading;
- // Start is called before the first frame update
- void Start()
- {
- GameObject go = GameObject.Find("MainText");
- if (go)
- {
- screen = go.GetComponent<Text>();
- if (!screen)
- {
- Debug.LogError("Text Component was not found on MainText");
- }
- }
- else
- {
- Debug.LogError("MainText bot found");
- }
- //screen.text = "Hello world";
- Bindbook();
- {
- }
- }
- // Update is called once per frame
- void Update()
- {
- HandleInput();
- RenderStory();
- }
- void Bindbook()
- {
- book = new Page[]
- {
- // 9
- new Page
- ("wake up", "(this is: wake up)\n\"you awaken in a sweltering room that smells of dust" +
- " and dry rot. To your left, you see a woven basket, about three feet in " +
- "front you see a deep steel bowl filled with what looks like milk, " +
- "and 10 feet beyond that is a heavy iron door you assume is locked." +
- " Will you check the [W]oven basket, [B]owl, or [D]oor?"),
- new Page ("woven basket", "(this is: woven baskiet)\n\n You walk over to examine the woven basket," +
- "which stands almost 3 feet tall. You see that the lid on the basket has a handle, but when you" +
- "try to pull up, it seems to be tied down. You find ties on four sides of the basket holding " +
- "the lid on. You undo the ties and find the basket oddly empty."+
- "Press [x] to return to the previous step."),
- new Page ("door", "(this is: door)\n\n" +
- "While you think it should be easy enough to waltz through " +
- "the iron door. When you come upon it, you realize it is much" +
- " heavier than originally thought. You put all your weight into " +
- "it to find it only groans and will not budge."+
- "It seems you will need a key to unlock the door" +
- "before it moves anymore." +
- "Press [x] to return to the previous step."),
- new Page ("bowl of milk", "(this is:bowl of milk)\n\n" +
- "You look at the bowl of creamy liquid before you, unsure" +
- "of its contents. You tap the bowl with your foot and see that " +
- "the liquid moves with the same viscosity as milk would."+
- "You are quite parched, do you " +
- "[P]ick up the bowl or press [X] to return."),
- new Page ("pick up", "(this is: pick up)\n\n" +
- "You pick up the bowl and bring it closer to sniff the contents." +
- " The smell of the liquid is mild, though there is a twinge of" +
- " something odd to it that you cannot place your finger on." +
- "You slosh the liquid a bit and notice something shifting" +
- "at the bottom of the bowl. Do you " +
- "[P]our out the contents or [D]rink the liquid?" +
- " Or press [x] to return to the previous step."),
- //win
- new Page ("pour", "(this is:pour)\n\n" +
- "You pour out all the contents onto the dusty floor, " +
- "including what seems to be some maggots and a wrought " +
- "iron key. One that looks to fit in the keyhole of the " +
- "heavy door. You use the key to unlatch the door and budge" +
- " it enough to escape." +
- "[C]ontinue?" ),
- //lose
- new Page ("drink", "(this is: drink)\n\n" +
- " You decide your thirst could help to kill two birds " +
- "with one stone and begin to drink the liquid." +
- "The liquid isn’t milk at all and has a " +
- "severe acrid taste, you swallow some more " +
- "anyway, feeling chunks of items floating on your tongue." +
- "You spit out the bits and upon further inspection see they"+
- "are wriggling. You toss the bowl away from you as you feel " +
- "the need to wretch." +
- "Standing up you see a key landing next to the tossed " +
- "bowl and as you go to reach for it, you fall forward," +
- " mind hazing into unconsciousness." +
- "[C]ontinue?"),
- new Page ("play again?", "(this is: play again?)\n\n" +
- "Would you like to play again? Press [Y] or [N]"),
- new Page ("no", "(this is: no)\n\n" +
- "Thanks for playing" ),
- };
- }
- void RenderStory()
- {
- if (!string.IsNullOrEmpty(nextHeading))
- {
- for (int i = 0; i < book.Length; i++)
- {
- if (nextHeading == book[i].Heading)
- {
- prevHeading = currHeading;
- currHeading = nextHeading;
- nextHeading = "";
- screen.text = book[i].Body; Debug.Log(book[i].Body);
- return;
- }
- }
- Debug.LogWarning("Heading not found: \"" + nextHeading + "\"");
- }
- }
- //x y n c w b d
- void HandleInput()
- {
- if (Input.GetKeyDown(KeyCode.C))
- {
- if (currHeading == "drink" || currHeading == "pour")
- {
- nextHeading = "play again?";
- }
- }
- else if (Input.GetKeyDown(KeyCode.B))
- {
- if (currHeading == "wake up")
- {
- nextHeading = "bowl of milk";
- }
- {
- }
- }
- else if (Input.GetKeyDown(KeyCode.D))
- {
- if (currHeading == "wake up")
- {
- nextHeading = "door";
- }
- {
- }
- }
- else if (Input.GetKeyDown(KeyCode.W))
- {
- if (currHeading == "wake up")
- {
- nextHeading = "woven basket";
- }
- }
- else if (Input.GetKeyDown(KeyCode.X))
- {
- if (currHeading == "woven basket" || currHeading == "door" || currHeading == "bowl of milk" || currHeading == "Pick up")
- {
- nextHeading = prevHeading;
- }
- }
- else if (Input.GetKeyDown(KeyCode.N))
- if (currHeading == "play again?")
- nextHeading = "no";
- else if (Input.GetKeyDown(KeyCode.Y))
- if (currHeading == "play again?")
- nextHeading = "wake up";
- else if (Input.GetKeyDown(KeyCode.P))
- if (currHeading == "pick up")
- nextHeading = "pour";
- else if (Input.GetKeyDown(KeyCode.D))
- if (currHeading == "pick up")
- nextHeading = "drink";
- nextHeading = prevHeading;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement