updating/removing a string
in
Programming Questions
•
11 months ago
I have a game which asks you a question if you get three matching images in a row, it then pops up with a question, this question stays on the screen and when they win again the question goes over the top and neither question can be read, is there a way to, on key-press remove the current question?
// images are 720 by 540
String[] questions = new String[4];
// link to answers
boolean overBox = false;
int[] answers = new int[4];
//int[] questions = new int[4];
int numFrames = 6; // The number of frames in the animation
int frame = 0;
int spincount = 0;
int state = 0;
//questions
int q = 0;
// answers
int an = 0;
//timer
int savedTime;
int totalTime = 11;
//randomise wheel start position variable
int wheel1;
int wheel2;
//pixels to test
// middle pixels
int a;
int b;
int c;
PImage[] images1 = new PImage[6];
PImage[] images2 = new PImage[6];
PImage[] images3 = new PImage[6];
PImage bg;
void setup() {
size(1080, 720);
frameRate(12);
bg = loadImage("smbg5.png");
// wheel 1
images1[0] = loadImage("bell1.png");
images1[1] = loadImage("diamond1.png");
images1[2] = loadImage("cherry1.png");
images1[3] = loadImage("bell1.png");
images1[4] = loadImage("diamond1.png");
images1[5] = loadImage("cherry1.png");
// wheel 3
images3[0] = loadImage("cherry1.png");
images3[1] = loadImage("diamond1.png");
images3[2] = loadImage("bell1.png");
images3[3] = loadImage("cherry1.png");
images3[4] = loadImage("diamond1.png");
images3[5] = loadImage("bell1.png");
// wheel 2
images2[0] = loadImage("bell1.png");
images2[1] = loadImage("diamond1.png");
images2[2] = loadImage("bell1.png");
images2[3] = loadImage("cherry1.png");
images2[4] = loadImage("diamond1.png");
images2[5] = loadImage("bell1.png");
questions[0] = "Which Apollo 11 astronaut did not set foot on the moon? A:Micheal Collins B: Collin Mitchels C: Harold Greenoff";
questions[1] = "What two colours make up the Polish flag A:blue and white B: blue and red C: red and white?";
questions[2] = "What is a female swan called? A: Cob B:Pen C:Boogle";
questions[3] = "What is a group of Owls called? A:parliament B: murder C: Library";
answers[0] = 1;
answers[1] = 3;
answers[2] = 2;
answers[3] = 1;
}
void draw() {
background (bg);
//test state to see if I should be spinning
if(state == 1) {
randomstart();
spin();
}
}
//if a key is pressed then set the wheel to spin
void keyReleased() {
state = 1;
}
void randomstart() {
wheel1 = int(random(5));
wheel2 = int(random(5));
//wheel3 = int(random(5));
}
void spin() {
frame = (frame+1) % numFrames;
//spin for 5 times the break out
if (frame == 5) {
frame = 0;
spincount ++;
if (spincount == 1) {
state = 0;
spincount = 0;
//check if its a win
a = images1[(frame + 1) % numFrames].get(2,2);
b = images2[(frame + 1 + wheel1) % numFrames].get(2,2);
c = images3[(frame + 1 + wheel2) % numFrames].get(2,2);
winner();
// print(a);
// print(b);
// print(c);
}
}
// wheel 1
image(images1[(frame) % numFrames], 0, 0);
image(images1[(frame + 1) % numFrames], 0, 200); //this is the image to test
image(images1[(frame + 2) % numFrames], 0, 400);
// wheel 2
image(images3[(frame) % numFrames], 300, 0);
image(images3[(frame + 1 + wheel1) % numFrames], 300, 200); //this is the image to test
image(images3[(frame + 2 + wheel1) % numFrames], 300, 400);
// wheel 3
image(images2[(frame) % numFrames], 600, 0);
image(images2[(frame + 1 + wheel2) % numFrames], 600, 200); //this is the image to test
image(images2[(frame + 2 + wheel2) % numFrames], 600, 400);
//slow stuff down so we can see it
//frame = (frame+1) % numFrames;
//delay(200);
//bg
// print(frame);
}
void winner() {
//are the names of the images the same
if (a == b && b == c ) {
// display a question from you list of questions by generating a random number and selecting the text
q = (int) random(3);
//display question, question size
textSize(12);
fill(0,102,153);
text(questions[q],80,650,50);
}
}
// //calculate how much time has passed
// int passedTime = second() - savedTime;
// //has five seconds passed?
// if (passedTime > totalTime) {
// print("times up" );
void mousePressed() {
if(overBox) {
link("http://www.processing.org");
}
}
void mouseMoved() {
checkButton();
}
void checkButton() {
if (mouseX > 864 && mouseX < 1065 && mouseY > 590 && mouseY < 710){
overBox = true;
} else {
overBox =false;
//for (int i = 0; i < 100; i = i+1)
// {
// if (i == 99) {
// //display times up
// print("times up, you loose");
// }
// //delay(200);
// print(i);
}
}
//text
1