Created
April 19, 2015 05:52
-
-
Save JavascriptMick/308147b3949c04335449 to your computer and use it in GitHub Desktop.
Better Engine for Text101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
using System.Collections.Generic; | |
public class TextController : MonoBehaviour { | |
public Text questionText; | |
private enum StateKey {Car, OpenWindow, Docs, MissingDog, DeadBug, Freakout, Police, Haircut, Court, PayFine, GoldCoast}; | |
private StateKey currentState; | |
private Dictionary<StateKey, StateDetail> stateDetails = new Dictionary<StateKey, StateDetail>(); | |
// Use this for initialization | |
void Start () { | |
stateDetails.Add(StateKey.Car, new StateDetail("They were on the way " + | |
"to the Gold Coast in the car." + | |
"The air in the car was already heavy " + | |
"but all of a sudden it became pungent.\n\n" + | |
"Press O to Open window, S to Strike a child, B to Blame the dog", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.O, StateKey.OpenWindow}, | |
{KeyCode.S, StateKey.Docs}, | |
{KeyCode.B, StateKey.MissingDog} | |
})); | |
stateDetails.Add(StateKey.OpenWindow, new StateDetail("Dad uses the driver console " + | |
"to open all of the windows." + | |
"The air in the car clears " + | |
"but all of a sudden a grasshoper flies in the window.\n\n" + | |
"Press K to kill the bug, F to freak out, C to call the police", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.K, StateKey.DeadBug}, | |
{KeyCode.F, StateKey.Freakout}, | |
{KeyCode.C, StateKey.Police} | |
})); | |
stateDetails.Add(StateKey.Docs, new StateDetail("Angus let out a shriek " + | |
"as mum's fist impacted with his nose." + | |
"Taking the phone from dad, Angus calls DOCS " + | |
"Mum is sentenced to 100 hours of anger management training.\n\n" + | |
"Press D to keep driving", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.Car} | |
})); | |
stateDetails.Add(StateKey.MissingDog, new StateDetail("Blaming the dog makes " + | |
"everybody in the family sad." + | |
"Because they all miss the dog already " + | |
"and blaming him has only made this worse.\n\n" + | |
"Press D to keep driving", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.Car} | |
})); | |
stateDetails.Add(StateKey.DeadBug, new StateDetail("Oscar spots the grasshoper " + | |
"immediately and with a flick of his neck, " + | |
"attempts to bite the grasshoper in half. " + | |
"He misses and the bug continues to circle.\n\n" + | |
"Press D to deal with the bug", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.OpenWindow} | |
})); | |
stateDetails.Add(StateKey.Freakout, new StateDetail("Dad freaks out! " + | |
"screaming like a baby and flailing his arms" + | |
"in the air. " + | |
"The car swerves and narrowly misses a truck filled with heart shaped pillows.\n\n" + | |
"Press D to deal with the bug", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.OpenWindow} | |
})); | |
stateDetails.Add(StateKey.Police, new StateDetail("Mum quickly calls 000. " + | |
"The police arrive quickly and expel the bug. " + | |
"They also notice Angus and inform " + | |
"him that Emo is totally banned in QLD.\n\n" + | |
"Press H to cut the hair, C to go to court, F to pay the fine", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.H, StateKey.Haircut}, | |
{KeyCode.C, StateKey.Court}, | |
{KeyCode.F, StateKey.PayFine} | |
})); | |
stateDetails.Add(StateKey.Haircut, new StateDetail("Mum and Oscar take utility " + | |
"scissors and the fishing knife from the " + | |
"fishing bag and hack away at Angus' hair. " + | |
"The result is improved but still terrible and the Police persist.\n\n" + | |
"Press D to deal with the police", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.Police} | |
})); | |
stateDetails.Add(StateKey.Court, new StateDetail("Dad threaghtens to take the matter to court! " + | |
"The police say that this is ok " + | |
"as long as dad was happy " + | |
"to have the soles of his feet 'massaged' with a baton.\n\n" + | |
"Press D to deal with the police", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.Police} | |
})); | |
stateDetails.Add(StateKey.PayFine, new StateDetail("Begrudgingly dad hands over the cash." + | |
"To the surprise of all, the police hand the money back! " + | |
"Turns out they were filming 'Gold Coast Cops' all along and needed some drama.\n\n" + | |
"Press D to keep driving", new Dictionary<KeyCode, StateKey>(){ | |
{KeyCode.D, StateKey.GoldCoast} | |
})); | |
stateDetails.Add(StateKey.GoldCoast, new StateDetail("Finally, the family arrives at the Gold Coast. " + | |
"With all the publicity from Gold Coast Cops, " + | |
"the family are celebrities and get free fast passes " + | |
"to every theme park.\n\n" + | |
"The End, Press P to play again", new Dictionary<KeyCode, StateKey>(){{KeyCode.P, StateKey.Car}})); | |
currentState = StateKey.Car; | |
} | |
// Update is called once per frame | |
void Update () { | |
if(stateDetails.ContainsKey(currentState)){ | |
StateDetail currentStateDetail = stateDetails[currentState]; | |
print("currentState:" + currentState + ", currentStateDetail" + currentStateDetail); | |
foreach(KeyValuePair<KeyCode, StateKey> entry in currentStateDetail.transitions) | |
{ | |
if(Input.GetKeyDown(entry.Key)){ | |
currentState = entry.Value; | |
currentStateDetail = stateDetails[currentState]; | |
} | |
} | |
questionText.text = currentStateDetail.questionText; | |
} else { | |
questionText.text = "Unknown State.. Game is Broken!"; | |
} | |
} | |
private class StateDetail{ | |
public string questionText; | |
public Dictionary<KeyCode, StateKey> transitions; | |
//Constructor | |
public StateDetail(string questionText, Dictionary<KeyCode, StateKey> transitions){ | |
this.questionText = questionText; | |
this.transitions = transitions; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment