I’ve been trying (for a while now) to add in a fill in the blank type question into my quiz but whenever I try to add in the specified code for the fill in the blank type of question: the code doesn’t work together with the code for the other questions.
Is there a way to separate the code for the fill in the blank question from the code for the multiple choice and true/false?
(i removed the images for convenience sake of helping me)
Code:
int score =0; //score
int screen =0; //screen
PImage img; //cpu image
PImage ww; //world war 1 tenches image
String s="";
void setup () {
size(1500, 1000);
}
//splash screen
void draw() {
background(#0099FC);//blue
if (screen == 0) {
fill(255);//white
textSize(26);
text("Welcome to the quiz,", 20, 50);
text("in this quiz you will be tested on your general knowledge of different school subjects", 20, 90);
text("along with your knowledge of Computer Science", 20, 130);
text("Press the any key on your keyboard to continue :)", 400, 500);
}
//screen 1
if (screen == 1) {
background(#02A54C); //green
textSize(30);
text("Question 1:", 20, 80);
text("What is this computer part?", 20, 140);
scale(0.7);//cpu image
//image(img, 800, 60);
strokeWeight(4);
fill(#FCBB52); //yellow
//Question boxes
rect(0, 900, 900, 220);
rect(900, 900, 920, 220);
rect(0, 1120, 900, 220);
rect(900, 1120, 920, 220);
fill(0);
textSize(80);
//questions
text("1)", 40, 1000); //answer
text("2)", 950, 1000);
text("3)", 40, 1220);
text("4)", 950, 1220);
text("CPU", 140, 1000);
text("RAM", 1050, 1000);
text("GPU", 140, 1220);
text("HardDrive", 1050, 1220);
text(score, 1450, 100);
text("/12", 1500, 100);
}
if (screen == 2) {
background(#FF4000); //orange
textSize(60);
text(score, 1100, 100);
//Question boxes
textSize(40);
text("Question 2:", 25, 100);
text("When did the first World War start?", 25, 160);
fill(#FCBB52);
//questions
rect(0, 650, 660, 150);
rect(660, 650, 710, 150);
rect(0, 800, 660, 150);
rect(660, 800, 710, 150);
fill(0);
textSize(60);
text("1)", 40, 715);//Questions
text("2)", 700, 715);
text("3)", 40, 865);
text("4)", 700, 865);
text("1900", 120, 715);
text("1914", 780, 715);
text("1984", 120, 865);
text("1918", 780, 865);
scale(1.3);
// image(ww, 500, 140);
textSize(40);
text("/12", 875, 75);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
delay(300);// only add 1 score
score++;
}
}
if (screen ==3) {
background(#08BC87);
textSize(60);
fill(0);
text(score, 1100, 100);
textSize(40);
text("Question 3:", 25, 100);
text("This is RAM.", 25, 160);
// image(RAM, 500, 100);
fill(#1BBF48);
rect(0, 650, 750, 250);
fill(#ED182A);
rect(660, 650, 750, 250);
fill(0);
textSize(100);
text("T)", 50, 800);
text("True", 160, 800);
text("F)", 720, 800);
text("False", 830, 800);
textSize(50);
text("/12", 1135, 100);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
delay(300);
score++;
}
}
if (screen ==4) {
text("Question 4:", 25, 100);
text("What part is this?", 25, 160);
fill(#FCBB52);
rect(0, 640, 660, 160);
rect(660, 640, 700, 160);
rect(0, 800, 660, 160);
rect(660, 800, 700, 160);
fill(0);
text("1)", 40, 715);//Questions
text("2)", 700, 715);
text("3)", 40, 865);
text("4)", 700, 865);
text("PSU", 120, 715);
text("SSD", 780, 715);
text("HDD", 120, 865);
text("GPU", 780, 865);
fill(0);
text("/12", 1135, 100);
scale(1.6);
//image(gpu, 300, 100);
textSize(80);
text("/12", 1135, 100);
textSize(40);
text(score, 680, 70);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
delay(300);
score++;
}
}
if (screen ==5) {
background(#4030FC);
text("Question 5:", 25, 100);
text("Linux is the most popular OS", 25, 160);
fill(#1BBF48);
rect(0, 650, 750, 250);
fill(#ED182A);
rect(660, 650, 750, 250);
fill(0);
textSize(100);
text("T)", 50, 800);
text("True", 160, 800);
text("F)", 720, 800);
text("False", 830, 800);
scale(0.9);
//image(L, 500, 200);
textSize(60);
text("/12", 1135, 100);
textSize(60);
text(score, 1100, 100);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '4') || (key == '$'))) {
delay(300);
score++;
}
}
if (screen ==6) {
background(#575BBF);
fill(0);
text("Question 5:", 25, 100);
text("What does SSD stand for?", 25, 160);
fill(#FCBB52);
rect(0, 640, 660, 160);
rect(660, 640, 700, 160);
rect(0, 800, 660, 160);
rect(660, 800, 700, 160);
fill(0);
text("1)", 40, 715);//Questions
text("2)", 700, 715);
text("3)", 40, 865);
text("4)", 700, 865);
textSize(44);
text("Hard Disk Drive", 120, 715);
text("Solid State Drive", 780, 715);
text("Graphics Processing Unit", 120, 865);
text("Central Processing unit", 780, 865);
scale(0.8);
text("/12", 1135, 100);
textSize(60);
text(score, 1100, 100);
scale(0.8);
//image(ssd, 500, 100);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
delay(300);
score++;
}
}
if (screen ==7) {
background(#0CAA4C);
fill(0);
text("Question 6:", 25, 100);
text("A SSD is slower than a HDD.", 25, 160);
fill(#1BBF48);
rect(0, 650, 750, 250);
fill(#ED182A);
rect(660, 650, 750, 250);
fill(0);
textSize(100);
text("T)", 50, 800);
text("True", 160, 800);
text("F)", 720, 800);
text("False", 830, 800);
textSize(60);
text("/12", 1135, 100);
textSize(60);
text(score, 1100, 100);
scale(0.5);
//image(hdd, 500, 280);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
delay(300);
score++;
}
}
if (screen ==8) {
background(#571CC6);
text("Question 7:", 25, 100);
text("Which Countries flag is this?", 25, 160);
fill(#FCBB52);
rect(0, 640, 660, 160);
rect(660, 640, 700, 160);
rect(0, 800, 660, 160);
rect(660, 800, 700, 160);
fill(0);
text("1)", 40, 715);//Questions
text("2)", 700, 715);
text("3)", 40, 865);
text("4)", 700, 865);
text("Vietnam", 120, 715);
text("Spain", 780, 715);
text("Philippines", 120, 865);
text("Denmark", 780, 865);
textSize(60);
text("/12", 1135, 100);
textSize(60);
text(score, 1100, 100);
scale(0.6);
//image(flag, 500, 320);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
delay(300);
score++;
}
}
if (screen ==9) {
background(#C68F1E);
text("Question 8:", 25, 100);
text("A calculator is a computer", 25, 160);
fill(#1BBF48);
rect(0, 650, 750, 250);
fill(#ED182A);
rect(660, 650, 750, 250);
fill(0);
textSize(100);
text("T)", 50, 800);
text("True", 160, 800);
text("F)", 720, 800);
text("False", 830, 800);
textSize(60);
text("/12", 1135, 100);
textSize(60);
text(score, 1100, 100);
scale(0.3);
//image(calc, 500, 700);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
delay(300);
score++;
}
}
if (screen ==10) {
background(#0C550F);
textSize(30);
text("Question 9:", 25, 100);
text("Alexander Graham Bell inveted the light bulb.", 25, 160);
fill(#1BBF48);
rect(0, 650, 750, 250);
fill(#ED182A);
rect(660, 650, 750, 250);
fill(0);
textSize(100);
text("T)", 50, 800);
text("True", 160, 800);
text("F)", 720, 800);
text("False", 830, 800);
//image(light, 500, 200);
textSize(60);
text("/12", 1145, 100);
textSize(60);
text(score, 1100, 100);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
delay(300);
score++;
}
}
if (screen ==11) {
background(#34B6CE);
text("Question 9:", 25, 100);
text("Where is Mount Everest located?.", 25, 160);
fill(#FCBB52);
rect(0, 640, 660, 160);
rect(660, 640, 700, 160);
rect(0, 800, 660, 160);
rect(660, 800, 700, 160);
fill(0);
text("1)", 40, 715);//Questions
text("2)", 700, 715);
text("3)", 40, 865);
text("4)", 700, 865);
text("Tibet", 120, 715);
text("Nepal", 780, 715);
textSize(30);
text("Border betweeem Tibet and Nepal", 120, 865);
text("China", 780, 865);
fill(0);
textSize(60);
text("/12", 1165, 100);
textSize(60);
text(score, 1100, 100);
scale(0.3);
//image(mount, 600, 600);
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
delay(300);
score++;
}
}
if (screen ==12) {
background(#FFA600);
fill(0);
textSize(60);
text("/12", 1165, 100);
textSize(60);
text(score, 1100, 100);
textSize(40);
text("Question 11:", 25, 100);
text("Mitochandrian is the \"_ _ _ _ _ _ _ _ _ _\" of the cell", 25, 160);
fill(255, 255, 0);
text(s, 240, 120);
}
if (screen ==13) {
background(0);
}
if (screen ==12) {
if (key>='a'&&key<='z') {
s+=key;
}
if (key==ENTER||key==RETURN) {
if (s.equals("powerhouse")) {
screen = 13;
}
s="";
}
}
//asnwer to previous question adds score if code is in next screen
if ((keyPressed == true) && ((key == '3') || (key == '#'))) {
delay(300);
score++;
}
}
void keyPressed() {
if (keyPressed == true && screen >=0) {
screen = screen + 1;
}
}