xxxxxxxxxx
94
// 4 prompts
// 1 fail screen (try again)
// 1 success screen
var choice = 0; // 0 if nothing is chosen yet, 1 if Right button is clicked 2 if Left button is clicked
var state = 1; // 1 if alive, 0 if dead
var qnum = 1; // what question you're on
function setup() {
createCanvas(500, 500);
background(220);
}
function mousePressed() {
// 0 if nothing is chosen or a random area is cliked, 1 if Right button is clicked 2 if Left button is clicked
if(mouseY>=300&&mouseX >= 250) {
choice = 1
} else if(mouseY>=300&&mouseX <250) {
choice = 2
} else choice = 0;
}
function draw() {
if(qnum == 1) {
//ask q1 and two buttons
///q1 prompt
fill('yellow');
rect(0, 0, 500, 300);
///two buttons
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
///the answer for q1 is Right(1). If choice is correct, send to next question; if choice is wrong, change state to dead
if(choice == 1) {qnum++; choice = 0;}
else if(choice == 2){state = 0}
}
if(qnum == 2) {
//ask q2 and two buttons
///q2 prompt
background(220);
fill('green');
rect(0, 0, 500, 300);
///two buttons
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
///the answer for q2 is Right(1). If choice is correct, send to next question; if choice is wrong, change state to dead
if(choice == 1) {qnum++; choice = 0;}
else if(choice == 2){state = 0}
}
if(qnum == 3) {
//ask q3 and two buttons
///q3 prompt
background(220);
fill('blue');
rect(0, 0, 500, 300);
///two buttons
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
///the answer for q3 is Right(1). If choice is correct, send to next question; if choice is wrong, change state to dead
if(choice == 1) {qnum++; choice = 0;}
else if(choice == 2){state = 0}
}
if(qnum == 4) {
//ask q4 and two buttons
///q4 prompt
background(220);
fill('purple');
rect(0, 0, 500, 300);
///two buttons
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
///the answer for q4 is Right(1). If choice is correct, send to next question; if choice is wrong, change state to dead
if(choice == 1) {qnum++}
else if(choice == 2){state = 0}
}
// if all 4 questions are cleared, you pass
if(qnum > 4) {
// success screen
background(220);
fill(255);
circle(mouseX, mouseY, 25);
}
// whenever you reach state == 0, you see a fail screen
if(state == 0) {
// fail screen
background(220);
line(200, 200, 300, 300);
line(200, 300, 300, 200);
}
}