Advertisement
Guest User

PGF1Week2project

a guest
May 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PGF1Week2Project : MonoBehaviour
  7. {
  8. Text screen;
  9. Page[] book;
  10.  
  11. [SerializeField]
  12. string currHeading;
  13. [SerializeField]
  14. string nextHeading = "wake up";
  15. [SerializeField]
  16. string prevHeading;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. GameObject go = GameObject.Find("MainText");
  21.  
  22. if (go)
  23. {
  24. screen = go.GetComponent<Text>();
  25.  
  26. if (!screen)
  27. {
  28. Debug.LogError("Text Component was not found on MainText");
  29. }
  30. }
  31. else
  32. {
  33. Debug.LogError("MainText bot found");
  34. }
  35.  
  36. //screen.text = "Hello world";
  37.  
  38. Bindbook();
  39. {
  40.  
  41. }
  42.  
  43. }
  44.  
  45. // Update is called once per frame
  46. void Update()
  47. {
  48. HandleInput();
  49. RenderStory();
  50. }
  51.  
  52. void Bindbook()
  53. {
  54. book = new Page[]
  55. {
  56.  
  57. // 9
  58.  
  59. new Page
  60. ("wake up", "(this is: wake up)\n\"you awaken in a sweltering room that smells of dust" +
  61. " and dry rot. To your left, you see a woven basket, about three feet in " +
  62. "front you see a deep steel bowl filled with what looks like milk, " +
  63. "and 10 feet beyond that is a heavy iron door you assume is locked." +
  64. " Will you check the [W]oven basket, [B]owl, or [D]oor?"),
  65.  
  66. new Page ("woven basket", "(this is: woven baskiet)\n\n You walk over to examine the woven basket," +
  67. "which stands almost 3 feet tall. You see that the lid on the basket has a handle, but when you" +
  68. "try to pull up, it seems to be tied down. You find ties on four sides of the basket holding " +
  69. "the lid on. You undo the ties and find the basket oddly empty."+
  70. "Press [x] to return to the previous step."),
  71.  
  72.  
  73. new Page ("door", "(this is: door)\n\n" +
  74. "While you think it should be easy enough to waltz through " +
  75. "the iron door. When you come upon it, you realize it is much" +
  76. " heavier than originally thought. You put all your weight into " +
  77. "it to find it only groans and will not budge."+
  78. "It seems you will need a key to unlock the door" +
  79. "before it moves anymore." +
  80. "Press [x] to return to the previous step."),
  81.  
  82. new Page ("bowl of milk", "(this is:bowl of milk)\n\n" +
  83. "You look at the bowl of creamy liquid before you, unsure" +
  84. "of its contents. You tap the bowl with your foot and see that " +
  85. "the liquid moves with the same viscosity as milk would."+
  86. "You are quite parched, do you " +
  87. "[P]ick up the bowl or press [X] to return."),
  88.  
  89. new Page ("pick up", "(this is: pick up)\n\n" +
  90. "You pick up the bowl and bring it closer to sniff the contents." +
  91. " The smell of the liquid is mild, though there is a twinge of" +
  92. " something odd to it that you cannot place your finger on." +
  93. "You slosh the liquid a bit and notice something shifting" +
  94. "at the bottom of the bowl. Do you " +
  95. "[P]our out the contents or [D]rink the liquid?" +
  96. " Or press [x] to return to the previous step."),
  97.  
  98. //win
  99. new Page ("pour", "(this is:pour)\n\n" +
  100. "You pour out all the contents onto the dusty floor, " +
  101. "including what seems to be some maggots and a wrought " +
  102. "iron key. One that looks to fit in the keyhole of the " +
  103. "heavy door. You use the key to unlatch the door and budge" +
  104. " it enough to escape." +
  105. "[C]ontinue?" ),
  106. //lose
  107. new Page ("drink", "(this is: drink)\n\n" +
  108. " You decide your thirst could help to kill two birds " +
  109. "with one stone and begin to drink the liquid." +
  110. "The liquid isn’t milk at all and has a " +
  111. "severe acrid taste, you swallow some more " +
  112. "anyway, feeling chunks of items floating on your tongue." +
  113. "You spit out the bits and upon further inspection see they"+
  114. "are wriggling. You toss the bowl away from you as you feel " +
  115. "the need to wretch." +
  116. "Standing up you see a key landing next to the tossed " +
  117. "bowl and as you go to reach for it, you fall forward," +
  118. " mind hazing into unconsciousness." +
  119. "[C]ontinue?"),
  120.  
  121. new Page ("play again?", "(this is: play again?)\n\n" +
  122. "Would you like to play again? Press [Y] or [N]"),
  123.  
  124. new Page ("no", "(this is: no)\n\n" +
  125. "Thanks for playing" ),
  126.  
  127. };
  128.  
  129. void RenderStory()
  130. {
  131. if (!string.IsNullOrEmpty(nextHeading))
  132. {
  133. for (int i = 0; i < book.Length; i++)
  134. {
  135. if (nextHeading == book[i].Heading)
  136. {
  137. prevHeading = currHeading;
  138. currHeading = nextHeading;
  139. nextHeading = "";
  140.  
  141. screen.text = book[i].Body; Debug.Log(book[i].Body);
  142. return;
  143. }
  144. }
  145.  
  146. Debug.LogWarning("Heading not found: \"" + nextHeading + "\"");
  147. }
  148. }
  149. //x y n c w b d
  150. void HandleInput()
  151. {
  152. if (Input.GetKeyDown(KeyCode.C))
  153. {
  154. if (currHeading == "drink" || currHeading == "pour")
  155. {
  156. nextHeading = "play again?";
  157. }
  158. }
  159. else if (Input.GetKeyDown(KeyCode.B))
  160. {
  161. if (currHeading == "wake up")
  162. {
  163. nextHeading = "bowl of milk";
  164. }
  165.  
  166. {
  167.  
  168. }
  169. }
  170.  
  171. else if (Input.GetKeyDown(KeyCode.D))
  172. {
  173. if (currHeading == "wake up")
  174. {
  175. nextHeading = "door";
  176. }
  177.  
  178. {
  179.  
  180. }
  181. }
  182. else if (Input.GetKeyDown(KeyCode.W))
  183. {
  184. if (currHeading == "wake up")
  185. {
  186. nextHeading = "woven basket";
  187. }
  188. }
  189. else if (Input.GetKeyDown(KeyCode.X))
  190. {
  191. if (currHeading == "woven basket" || currHeading == "door" || currHeading == "bowl of milk" || currHeading == "Pick up")
  192. {
  193. nextHeading = prevHeading;
  194. }
  195. }
  196. else if (Input.GetKeyDown(KeyCode.N))
  197.  
  198. if (currHeading == "play again?")
  199.  
  200. nextHeading = "no";
  201.  
  202. else if (Input.GetKeyDown(KeyCode.Y))
  203.  
  204. if (currHeading == "play again?")
  205.  
  206. nextHeading = "wake up";
  207.  
  208. else if (Input.GetKeyDown(KeyCode.P))
  209.  
  210. if (currHeading == "pick up")
  211. nextHeading = "pour";
  212.  
  213. else if (Input.GetKeyDown(KeyCode.D))
  214.  
  215.  
  216. if (currHeading == "pick up")
  217. nextHeading = "drink";
  218.  
  219.  
  220.  
  221. nextHeading = prevHeading;
  222. }
  223.  
  224.  
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement