Urgent: Needed in 6 hours. How do you make a matching game work?
in
Programming Questions
•
1 year ago
I am working on creating a simple matching game. I need to figure out how to make it so that when the player gets a question right, two of the images stay uploaded and when the player gets something wrong the pictures disappear. I have created buttons so that when the player clicks on a tile, an image pops up. Does anyone know how to write a coding for this?
This is the coding I have so far:
PImage matching;
PImage bread;
PImage bread2;
PImage apple;
PImage hamburger;
PImage bananas;
PImage milk;
PImage lollipops;
void setup(){
size(635, 480);
//when adding the image first you must click on Sketch, adding file and then select the image you want. Remember that the name that you place in the brackets must be the exact name of the image that you use.
matching = loadImage ("matching.jpg");
//this makes the image appear from the top left hand corner of the screen.
image(matching, 0, 0);
}
void draw(){
if (mousePressed == true) {
if (mouseX > 0 && mouseX < 160 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
bread = loadImage ("bread.png");
// Making the bread appear on the tile 1-1.
image (bread, 5, 5);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
bread2 = loadImage ("bread2.png");
// Making the bread appear on the tile 2-3.
image (bread2, 327, 165);
}
if (mousePressed == true)
if (mouseX > 0 && mouseX < 160 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
apple = loadImage ("apple.png");
// Making the apple appear on the tile 2-1.
image (apple, 5, 165);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 633 && mouseY > 322 && mouseY < 477) {
cursor(HAND);
apple = loadImage ("apple.png");
// Making the apple appear on the tile 3-4.
image (apple, 486, 327);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
hamburger = loadImage ("hamburger.png");
// Making the hamburger appear on the tile 1-2.
image (hamburger, 165, 5);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
hamburger = loadImage ("hamburger.png");
// Making the hamburger appear on the tile 3-2.
image (hamburger, 165, 325);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
bananas = loadImage ("bananas.png");
// Making the bananas appear on the tile 2-2.
image (bananas, 165, 165);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 628 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
bananas = loadImage ("bananas.png");
// Making the bread appear on the tile 1-4.
image (bananas, 486, 5);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
milk = loadImage ("milk.png");
// Making the milk appear on the tile 3-3.
image (milk, 327, 325);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 628 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
milk = loadImage ("milk.png");
// Making the milk appear on the tile 2-4.
image (milk, 486, 165);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
lollipops = loadImage ("lollipops.png");
// Making the lollipops appear on the tile 3-1.
image (lollipops, 327, 5);
}
if (mousePressed == true)
if (mouseX > 0 && mouseX < 160 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
lollipops = loadImage ("lollipops.png");
// Making the lollipops appear on the tile 1-3.
image (lollipops, 5, 325);
}
}
}
This is the coding I have so far:
PImage matching;
PImage bread;
PImage bread2;
PImage apple;
PImage hamburger;
PImage bananas;
PImage milk;
PImage lollipops;
void setup(){
size(635, 480);
//when adding the image first you must click on Sketch, adding file and then select the image you want. Remember that the name that you place in the brackets must be the exact name of the image that you use.
matching = loadImage ("matching.jpg");
//this makes the image appear from the top left hand corner of the screen.
image(matching, 0, 0);
}
void draw(){
if (mousePressed == true) {
if (mouseX > 0 && mouseX < 160 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
bread = loadImage ("bread.png");
// Making the bread appear on the tile 1-1.
image (bread, 5, 5);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
bread2 = loadImage ("bread2.png");
// Making the bread appear on the tile 2-3.
image (bread2, 327, 165);
}
if (mousePressed == true)
if (mouseX > 0 && mouseX < 160 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
apple = loadImage ("apple.png");
// Making the apple appear on the tile 2-1.
image (apple, 5, 165);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 633 && mouseY > 322 && mouseY < 477) {
cursor(HAND);
apple = loadImage ("apple.png");
// Making the apple appear on the tile 3-4.
image (apple, 486, 327);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
hamburger = loadImage ("hamburger.png");
// Making the hamburger appear on the tile 1-2.
image (hamburger, 165, 5);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
hamburger = loadImage ("hamburger.png");
// Making the hamburger appear on the tile 3-2.
image (hamburger, 165, 325);
}
if (mousePressed == true)
if (mouseX > 160 && mouseX < 320 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
bananas = loadImage ("bananas.png");
// Making the bananas appear on the tile 2-2.
image (bananas, 165, 165);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 628 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
bananas = loadImage ("bananas.png");
// Making the bread appear on the tile 1-4.
image (bananas, 486, 5);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
milk = loadImage ("milk.png");
// Making the milk appear on the tile 3-3.
image (milk, 327, 325);
}
if (mousePressed == true)
if (mouseX > 481 && mouseX < 628 && mouseY > 160 && mouseY < 321) {
cursor(HAND);
milk = loadImage ("milk.png");
// Making the milk appear on the tile 2-4.
image (milk, 486, 165);
}
if (mousePressed == true)
if (mouseX > 322 && mouseX < 482 && mouseY > 0 && mouseY < 155) {
cursor(HAND);
lollipops = loadImage ("lollipops.png");
// Making the lollipops appear on the tile 3-1.
image (lollipops, 327, 5);
}
if (mousePressed == true)
if (mouseX > 0 && mouseX < 160 && mouseY > 320 && mouseY < 477) {
cursor(HAND);
lollipops = loadImage ("lollipops.png");
// Making the lollipops appear on the tile 1-3.
image (lollipops, 5, 325);
}
}
}
1