Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.93 KB | None | 0 0
  1. //Code adapted from The Marshmallow game
  2. //Game based on the "Spent" game
  3. var canvas;
  4.  
  5. var button1;
  6. var button2;
  7.  
  8. var gameState = "one";
  9. var myP;
  10.  
  11. var money;
  12.  
  13. function setup() {
  14. canvas = createCanvas(windowWidth, windowHeight);
  15. canvas.position(0, 0);
  16. canvas.style("z-index", "-1");
  17.  
  18. button1 = createButton("continue");
  19. button1.position(width / 2 - 25, height / 1.35);
  20. button2 = createButton("yes");
  21. button2.position(width / 2 - 50, height / 1.35);
  22.  
  23. button1.style("font-family: 'Open Sans', sans-serif;");
  24. button2.style("font-family: 'Open Sans', sans-serif;");
  25.  
  26. button2.hide();
  27. button1.mousePressed(button1Action);
  28. button2.mousePressed(button2Action);
  29.  
  30. myP = createP("Welcome to this budgeting exhibit!");
  31. myP.style("font-family: 'Open Sans', sans-serif;");
  32. myP.style("margin-top: 140px");
  33. myP.style("margin-left: 10px");
  34. myP.style("margin-right: 10px");
  35. myP.style("text-align: center");
  36.  
  37. money = 300;
  38.  
  39. }
  40.  
  41. function draw() {
  42. background(206, 225, 255);
  43. // // if (!(gameState == "one" || gameState == "twenty")) {
  44. // // wallet();
  45. // // }
  46. }
  47.  
  48. function button1Action() {
  49. if (gameState === "one") { //pressed "continue" once
  50. gameState = "two";
  51. money = money;
  52. myP.html("Let's say you have $300");
  53. } else if (gameState === "two") { //pressed "continue" twice
  54. gameState = "three";
  55. myP.html("Do you want to put $50 into a savings account?");
  56. button1.html("no");
  57. button1.position(width / 2 + 50, height / 1.35);
  58. button2.show();
  59. button2.html("yes");
  60. button2.position(width / 2 - 75, height / 1.35);
  61. } else if (gameState === "three") { //pressed "no"
  62. gameState = "four";
  63. money = money - 0;
  64. myP.html("You still have $" + money + ". <br/> In the future, you should consider saving money, so if something happens or you really want to buy something, you have something to fall back on.");
  65. button1.hide();
  66. button2.hide();
  67. button1.html("continue");
  68. button1.position(width / 2 - 25, height / 1.35);
  69. button1.show();
  70. } else if (gameState === "four") { //pressed "continue" three times
  71. gameState = "five";
  72. myP.html("Your friends are going to an amusement park. Admission is $70. Do you want to join them or stay home?");
  73. button1.html("amusement park");
  74. button1.position(width / 2 + 50, height / 1.35);
  75. button2.show();
  76. button2.html("stay home");
  77. button2.position(width / 2 - 75, height / 1.35);
  78. } else if (gameState === "five") { //pressed "amusement park"
  79. gameState = "six";
  80. money = money - 70;
  81. myP.html("You now have $" + money + ". <br/> You had a great time with your friends. However, while creating a budget, it's important to consider where your priorities are, and what you want to spend money on.");
  82. button1.hide();
  83. button2.hide();
  84. button1.html("continue");
  85. button1.position(width / 2 - 25, height / 1.35);
  86. button1.show();
  87. } else if (gameState === "six") { //pressed "continue" four times
  88. gameState = "seven";
  89. myP.html("You need to get across town, but it's raining. You can take an uber for $25 or take the bus then walk for $5.");
  90. button1.html("uber");
  91. button1.position(width / 2 + 50, height / 1.35);
  92. button2.show();
  93. button2.html("bus and walk");
  94. button2.position(width / 2 - 75, height / 1.35);
  95. } else if (gameState === "seven") { //pressed "uber"
  96. gameState = "eight";
  97. money = money - 25;
  98. myP.html("You now have $" + money + ". <br/> Sometimes it's nice to go the more expensive route if it means staying out of the rain or avoiding a long walk. However, make sure not to do it too often.");
  99. button1.hide();
  100. button2.hide();
  101. button1.html("continue");
  102. button1.position(width / 2 - 25, height / 1.35);
  103. button1.show();
  104. } else if (gameState === "eight") { //pressed "continue" five times
  105. gameState = "nine";
  106. myP.html("It's lunch time, and you're hungry. Do you buy organic food for $15 or junk food for $5?");
  107. button1.html("organic");
  108. button1.position(width / 2 + 50, height / 1.35);
  109. button2.show();
  110. button2.html("junk");
  111. button2.position(width / 2 - 75, height / 1.35);
  112. } else if (gameState === "nine") { //pressed "organic"
  113. gameState = "ten";
  114. money = money - 15;
  115. myP.html("You now have $" + money + ". <br/> Although more expensive, organic food is much healthier – it may be a good idea to consider spending more money, if it means keeping you more healthy.");
  116. button1.hide();
  117. button2.hide();
  118. button1.html("continue");
  119. button1.position(width / 2 - 25, height / 1.35);
  120. button1.show();
  121. } else if (gameState === "ten") { //pressed "continue" six times
  122. gameState = "eleven";
  123. myP.html("A new movie just came out that you really want to see. Do you see it in the theater for $14 or watch netflix instead?");
  124. button1.html("theater");
  125. button1.position(width / 2 + 50, height / 1.35)
  126. button2.show();
  127. button2.html("netflix");
  128. button2.position(width / 2 - 75, height / 1.35);
  129. } else if (gameState === "eleven") { //pressed "theater"
  130. gameState = "twelve";
  131. money = money - 14;
  132. myP.html("You now have $" + money + ". <br/> Although it's nice to go out sometimes, when trying to save money, it may be a good idea to limit unnecessary spending, like going out to a movie.")
  133. button1.hide();
  134. button2.hide();
  135. button1.html("continue");
  136. button1.position(width / 2 - 25, height / 1.35);
  137. button1.show();
  138. } else if (gameState === "twelve") { //pressed "continue" seven times
  139. gameState = "thirteen";
  140. myP.html("You need an outfit for a job interview. Do you go to the mall and spend $100 or go to a second hand store and spend $50?");
  141. button1.html("mall");
  142. button1.position(width / 2 + 50, height / 1.35)
  143. button2.show();
  144. button2.html("second hand");
  145. button2.position(width / 2 - 75, height / 1.35);
  146. } else if (gameState === "thirteen") { //pressed "mall"
  147. gameState = "fourteen";
  148. money = money - 100;
  149. myP.html("You now have $" + money + ". <br/> Although the mall often has more options and can be less time consuming, it is often much more expensive than shopping second hand. When saving money, second hand stores are a great resource.")
  150. button1.hide();
  151. button2.hide();
  152. button1.html("continue");
  153. button1.position(width / 2 - 25, height / 1.35);
  154. button1.show();
  155. } else if (gameState === "fourteen") { //pressed "continue" eight times
  156. gameState = "fifteen";
  157. myP.html("You <i>really</i> need a haircut. Do you go to the barber and pay $30 or ask a friend?");
  158. button1.html("barber");
  159. button1.position(width / 2 + 50, height / 1.35)
  160. button2.show();
  161. button2.html("friend");
  162. button2.position(width / 2 - 75, height / 1.35);
  163. } else if (gameState === "fifteen") { //pressed "barber"
  164. gameState = "sixteen";
  165. money = money - 30;
  166. myP.html("You now have $" + money + ". <br/> Sometimes haircuts are necessary, but how nice it needs to be done is up to you and where your economic priorities lay.")
  167. button1.hide();
  168. button2.hide();
  169. button1.html("continue");
  170. button1.position(width / 2 - 25, height / 1.35);
  171. button1.show();
  172. } else if (gameState === "sixteen") { //pressed "continue" nine times
  173. gameState = "seventeen";
  174. myP.html("Your shoes are falling apart, so you need new ones. Do you buy new ones for $50 or try to make them last a little longer?");
  175. button1.html("new ones");
  176. button1.position(width / 2 + 50, height / 1.35)
  177. button2.show();
  178. button2.html("wait");
  179. button2.position(width / 2 - 75, height / 1.35);
  180. } else if (gameState === "seventeen") { //pressed "new ones"
  181. gameState = "eighteen";
  182. money = money - 50;
  183. myP.html("You now have $" + money + ". <br/> Although cheaper to keep your shoes for as long as possible, shoes are necessary and wearing ones that are broken can be potentially harmful to your feet.")
  184. button1.hide();
  185. button2.hide();
  186. button1.html("continue");
  187. button1.position(width / 2 - 25, height / 1.35);
  188. button1.show;
  189. } else if (gameState === "eighteen") { //pressed "continue" ten times
  190. gameState = "nineteen";
  191. myP.html("You come down with a cold and should get medicine. Do you go the pharmacy and buy medicine for $15 or wait it out?")
  192. button1.html("medicine");
  193. button1.position(width / 2 + 50, height / 1.35)
  194. button2.show();
  195. button2.html("wait");
  196. button2.position(width / 2 - 75, height / 1.35);
  197. } else if (gameState === "nineteen") { //pressed medicine
  198. gameState = "twenty";
  199. money = money - 15;
  200. myP.html("You now have $" + money + ".<br/> Keeping yourself healthy should be a priority above everything else, so budgeting in money for health purposes is necessary – especially so you can go to school/work and continue to make money, instead of wait out your cold at home.")
  201. button1.hide();
  202. button2.hide();
  203. button1.html("continue");
  204. button1.position(width / 2 - 25, height / 1.35);
  205. button1.show;
  206. } else if (gameState === "twenty") { //pressed continue eleven times
  207. gameState = "twentyOne";
  208. money = money;
  209. myP.html("Congratulations, you have made it through this budgeting simulation! You ended up with $" + money + ".")
  210. }
  211. }
  212.  
  213. //scenario = new glasses/shoes? medicine/doctor?
  214.  
  215. function button2Action() {
  216. if (gameState === "three") { //pressed "yes"
  217. gameState = "four";
  218. money = money - 50;
  219. myP.html("You now have $" + money + ". <br/> Starting to save early and periodically is always a great idea. \n You never know when you'll need it!");
  220. button2.hide();
  221. button1.html("continue");
  222. button1.position(width / 2 - 25, height / 1.35);
  223. } else if (gameState === "five") { //pressed "stay home"
  224. gameState = "six";
  225. money = money - 0;
  226. myP.html("You still have $" + money + ". <br/> But, you missed out hanging with your friends. While creating a budget, it's important to consider where your priorities are, and what you want to spend money on.");
  227. button2.hide();
  228. button1.html("continue");
  229. button1.position(width / 2 - 25, height / 1.35);
  230. } else if (gameState === "seven") { //pressed "bus and walk"
  231. gameState = "eight";
  232. money = money - 5;
  233. myP.html("You now have $" + money + ". <br/> When tight on money or trying to start good budgeting habits, it's always a good idea to take the less expensive transportation option.");
  234. button2.hide();
  235. button1.html("continue");
  236. button1.position(width / 2 - 25, height / 1.35);
  237. } else if (gameState === "nine") { //pressed "junk"
  238. gameState = "ten";
  239. money = money - 5;
  240. myP.html("You now have $" + money + ". <br/> Although junk food is cheaper, it is still important to watch what you eat, even when trying to save money.");
  241. button2.hide();
  242. button1.html("continue");
  243. button1.position(width / 2 - 25, height / 1.35);
  244. } else if (gameState === "eleven") { //pressed "netflix"
  245. gameState = "twelve";
  246. money = money - 0;
  247. myP.html("You still have $" + money + ". <br/> Although it's fun to go out, investing in a relatively low-cost monthly service like netflix can ultimatley decrease your spending if you find yourself staying in and watching movies or TV often.");
  248. button2.hide();
  249. button1.html("continue");
  250. button1.position(width / 2 - 25, height / 1.35);
  251. } else if (gameState === "thirteen") { //pressed "second hand"
  252. gameState = "fourteen";
  253. money = money - 50;
  254. myP.html("You still have $" + money + ". <br/> When saving money, it's a good idea to do shopping at a second hand store if possible. However, it can often be time consuming to find the exact thing that you want, so weighing your priorities beforehand is important.");
  255. button2.hide();
  256. button1.html("continue");
  257. button1.position(width / 2 - 25, height / 1.35);
  258. } else if (gameState === "fifteen") { //pressed "friend"
  259. gameState = "sixteen";
  260. money = money - 0;
  261. myP.html("You still have $" + money + ". <br/> Getting a friend to cut your hair can be a good way to save money, as long as you don't expect or need a super fancy haircut.");
  262. button2.hide();
  263. button1.html("continue");
  264. button1.position(width / 2 - 25, height / 1.35);
  265. } else if (gameState === "seventeen") { //pressed "wait"
  266. gameState = "eighteen";
  267. money = money - 0;
  268. myP.html("You still have $" + money + ". <br/> Although cheaper to keep your shoes for as long as possible, shoes are necessary and wearing ones that are broken can be potentially harmful to your feet.")
  269. button2.hide();
  270. button1.html("continue");
  271. button1.position(width / 2 - 25, height / 1.35);
  272. } else if (gameState === "nineteen") {
  273. gameState = "twenty";
  274. money = money - 0;
  275. myP.html("You still have $" + money + ". <br/> Keeping yourself healthy should be a priority above everything else, so budgeting in money for health purposes is necessary – especially so you can go to school/work and continue to make money, instead of wait out your cold at home.")
  276. button2.hide();
  277. button1.html("continue");
  278. button1.position(width / 2 - 25, height / 1.35);
  279. }
  280. }
  281.  
  282. function wallet() {
  283. money = money
  284. textSize(16);
  285. rect(46, 32, 43, 23);
  286. text("$" + money, 50, 50);
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement