Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Code adapted from The Marshmallow game
- //Game based on the "Spent" game
- var canvas;
- var button1;
- var button2;
- var gameState = "one";
- var myP;
- var money;
- function setup() {
- canvas = createCanvas(windowWidth, windowHeight);
- canvas.position(0, 0);
- canvas.style("z-index", "-1");
- button1 = createButton("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button2 = createButton("yes");
- button2.position(width / 2 - 50, height / 1.35);
- button1.style("font-family: 'Open Sans', sans-serif;");
- button2.style("font-family: 'Open Sans', sans-serif;");
- button2.hide();
- button1.mousePressed(button1Action);
- button2.mousePressed(button2Action);
- myP = createP("Welcome to this budgeting exhibit!");
- myP.style("font-family: 'Open Sans', sans-serif;");
- myP.style("margin-top: 140px");
- myP.style("margin-left: 10px");
- myP.style("margin-right: 10px");
- myP.style("text-align: center");
- money = 300;
- }
- function draw() {
- background(206, 225, 255);
- // // if (!(gameState == "one" || gameState == "twenty")) {
- // // wallet();
- // // }
- }
- function button1Action() {
- if (gameState === "one") { //pressed "continue" once
- gameState = "two";
- money = money;
- myP.html("Let's say you have $300");
- } else if (gameState === "two") { //pressed "continue" twice
- gameState = "three";
- myP.html("Do you want to put $50 into a savings account?");
- button1.html("no");
- button1.position(width / 2 + 50, height / 1.35);
- button2.show();
- button2.html("yes");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "three") { //pressed "no"
- gameState = "four";
- money = money - 0;
- 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.");
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "four") { //pressed "continue" three times
- gameState = "five";
- myP.html("Your friends are going to an amusement park. Admission is $70. Do you want to join them or stay home?");
- button1.html("amusement park");
- button1.position(width / 2 + 50, height / 1.35);
- button2.show();
- button2.html("stay home");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "five") { //pressed "amusement park"
- gameState = "six";
- money = money - 70;
- 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.");
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "six") { //pressed "continue" four times
- gameState = "seven";
- 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.");
- button1.html("uber");
- button1.position(width / 2 + 50, height / 1.35);
- button2.show();
- button2.html("bus and walk");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "seven") { //pressed "uber"
- gameState = "eight";
- money = money - 25;
- 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.");
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "eight") { //pressed "continue" five times
- gameState = "nine";
- myP.html("It's lunch time, and you're hungry. Do you buy organic food for $15 or junk food for $5?");
- button1.html("organic");
- button1.position(width / 2 + 50, height / 1.35);
- button2.show();
- button2.html("junk");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "nine") { //pressed "organic"
- gameState = "ten";
- money = money - 15;
- 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.");
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "ten") { //pressed "continue" six times
- gameState = "eleven";
- 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?");
- button1.html("theater");
- button1.position(width / 2 + 50, height / 1.35)
- button2.show();
- button2.html("netflix");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "eleven") { //pressed "theater"
- gameState = "twelve";
- money = money - 14;
- 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.")
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "twelve") { //pressed "continue" seven times
- gameState = "thirteen";
- 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?");
- button1.html("mall");
- button1.position(width / 2 + 50, height / 1.35)
- button2.show();
- button2.html("second hand");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "thirteen") { //pressed "mall"
- gameState = "fourteen";
- money = money - 100;
- 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.")
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "fourteen") { //pressed "continue" eight times
- gameState = "fifteen";
- myP.html("You <i>really</i> need a haircut. Do you go to the barber and pay $30 or ask a friend?");
- button1.html("barber");
- button1.position(width / 2 + 50, height / 1.35)
- button2.show();
- button2.html("friend");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "fifteen") { //pressed "barber"
- gameState = "sixteen";
- money = money - 30;
- 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.")
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show();
- } else if (gameState === "sixteen") { //pressed "continue" nine times
- gameState = "seventeen";
- 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?");
- button1.html("new ones");
- button1.position(width / 2 + 50, height / 1.35)
- button2.show();
- button2.html("wait");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "seventeen") { //pressed "new ones"
- gameState = "eighteen";
- money = money - 50;
- 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.")
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show;
- } else if (gameState === "eighteen") { //pressed "continue" ten times
- gameState = "nineteen";
- 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?")
- button1.html("medicine");
- button1.position(width / 2 + 50, height / 1.35)
- button2.show();
- button2.html("wait");
- button2.position(width / 2 - 75, height / 1.35);
- } else if (gameState === "nineteen") { //pressed medicine
- gameState = "twenty";
- money = money - 15;
- 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.")
- button1.hide();
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- button1.show;
- } else if (gameState === "twenty") { //pressed continue eleven times
- gameState = "twentyOne";
- money = money;
- myP.html("Congratulations, you have made it through this budgeting simulation! You ended up with $" + money + ".")
- }
- }
- //scenario = new glasses/shoes? medicine/doctor?
- function button2Action() {
- if (gameState === "three") { //pressed "yes"
- gameState = "four";
- money = money - 50;
- 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!");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "five") { //pressed "stay home"
- gameState = "six";
- money = money - 0;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "seven") { //pressed "bus and walk"
- gameState = "eight";
- money = money - 5;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "nine") { //pressed "junk"
- gameState = "ten";
- money = money - 5;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "eleven") { //pressed "netflix"
- gameState = "twelve";
- money = money - 0;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "thirteen") { //pressed "second hand"
- gameState = "fourteen";
- money = money - 50;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "fifteen") { //pressed "friend"
- gameState = "sixteen";
- money = money - 0;
- 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.");
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "seventeen") { //pressed "wait"
- gameState = "eighteen";
- money = money - 0;
- 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.")
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- } else if (gameState === "nineteen") {
- gameState = "twenty";
- money = money - 0;
- 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.")
- button2.hide();
- button1.html("continue");
- button1.position(width / 2 - 25, height / 1.35);
- }
- }
- function wallet() {
- money = money
- textSize(16);
- rect(46, 32, 43, 23);
- text("$" + money, 50, 50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement