xxxxxxxxxx
100
/* A Quiz Game */
var c = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var cIndex = 0;
var f = ['Arial', 'Calibri', 'Century Gothic', 'Comic Sans', 'Courier', 'Georgia'];
var fIndex = 0;
var questions = ["What is the acceleration of gravity in m/s/s?",
"What is the acceleration of graphvity in ft/s/s?",
"What is Avocado's Number?",
"What is Planks constant?"];
var answers = ["9.8", "32.2", "6.02*10^23", "6.626*10^-34"];
var index = 0;
var letterSpacing;
var aIndex = 0;
var gotButton, nextButton;
var score = 0;
var mode = 0;
var points = 500;
function setup() {
createCanvas(600, 400);
rectMode(CENTER);
noStroke();
index = floor(random(questions.length));
letterSpacing = width/(answers[index].length+1);
gotButton = createButton('Got it!');
gotButton.position(20, height*4/5);
gotButton.mousePressed(updateScore);
nextButton = createButton('Next Question');
nextButton.position(270, height*4/5);
nextButton.mousePressed(changeQuestion);
easyButton = createButton('Easy Mode');
easyButton.position(20, height*3/5);
easyButton.mousePressed(easyMode);
}
function draw() {
if (mode == 0) {
background(255);
} else {
fill(255);
rect(width/2,height/10,600,height/5);
}
fill(0);
textSize(20);
text("Score: " + score, 270, 30);
text("Possible Points: " + points, 20, 30);
textSize(2*width/questions[index].length-2);
text(questions[index], 5, height/5);
textSize(letterSpacing);
fill(c[cIndex]);
if (mode == 0) {
text(answers[index][aIndex], aIndex*letterSpacing, height/2);
} else {
for(var i = 0; i <= aIndex; i++) {
text(answers[index][i], i*letterSpacing, height/2);
}
}
}
function mousePressed() {
cIndex++;
cIndex %= c.length;
aIndex = (aIndex+1)%answers[index].length;
fIndex = (fIndex+1)%f.length;
points -= floor(500/answers[index].length);
}
function updateScore() {
score += points;
points = 0 + floor(500/answers[index].length);
}
function changeQuestion() {
index = floor(random(questions.length));
aIndex = -1;
mode = 0;
textFont(f[fIndex]);
points = 500+ floor(500/answers[index].length);
}
function easyMode() {
mode = 1;
aIndex--;
points += floor(500/answers[index].length);
points -= 100;
}