for some reason I cant figure out how to upload my code to openprocessing on the updated version of processing so ill just post my code after this. the only thing that will not work is the pictures but you can just place any picture into them to see that it works.
the biggest problem I ran into was the fact that my “random” feature would repeat pictures so there would be a random number of doubles or triples. one more thing I would have liked to figure out was to get my code to reset after it found the first match. for some reason once it found one match it would only look for that exact picture with the same ID. if I was able to fix these two problems I believe that this project would be perfect. it was a lot of difficulty to get right but in the end I think it was a great project that tested my learning in this program
heres my code
int mouseClicks;
//arrays of pictures
PImage [] pics = new PImage[6];
PImage [] pics1 = new PImage[6];
//Place my arrays using my class
Button [] buttons = new Button [6];
Button [] buttons1 = new Button [6];
//add my timer
Timer timer;
void setup() {
for (int i = 0; i < pics.length; i = i +1) {
pics[i] = loadImage(“photo” + i + “.jpg”);
}
for (int i = 0; i < pics1.length; i = i +1) {
pics1[i] = loadImage(“photos” + i + “.jpg”);
}
//window size
size (900, 300);
background (255);
//set up my arrays
for (int i = 0; i < buttons.length; i = i +1) {
int id = int(random(pics.length));
buttons[i] = new Button(pics[id], i*125+25, 25, 100, 100, id);
}
for (int i = 0; i < buttons1.length; i = i +1) {
int id = int(random(pics.length));
buttons1[i] = new Button(pics1[id], i*125+25, 150, 100, 100, id);
}
//bring in my timer
timer = new Timer(5000); //5 seconds to find a match
timer.start();
}
void draw() {
if (timer.isFinished()){
background(0);
}
for (int i = 0; i < buttons.length; i = i +1) {
buttons[i].display();
}
for (int i = 0; i < buttons1.length; i = i +1) {
buttons1[i].display();
}
}
void mousePressed() {
for (int i = 0; i < buttons.length; i++) {
buttons[i].click();
}
for (int i = 0; i < buttons1.length; i++) {
buttons1[i].click();
}
for (int i = 0; i < buttons.length; i++) {
if (buttons[i].on == true) {
for (int j = 0; j < buttons1.length; j++) {
if (buttons1[j].on) {
buttons[i].check(buttons1[j]);
}
}
}
}
}
class Button {
// Data Variables
PImage picture;
int x;
int y;
int w;
int h;
boolean on;
int id;
boolean match;
//Initianalize data variables
Button(PImage tempPicture, int tempX, int tempY, int tempW, int tempH, int tempid) {
picture = tempPicture;
x = tempX;
y = tempY;
w = tempW;
h = tempH;
id = tempid;
}
//create functions to use in this class
void display() {
if (on) {
image(picture, x, y, w, h);
}
else {
fill(0);
rect(x, y, w, h);
}
}
void click() {
if (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h) {
on =!on;
println(on);
}
}
void check(Button b) {
if (id == b.id) {
match = true;
println(“match”);
println(“id1: ” + id);
println(“id2: ” + b.id);
}
else{
on = false;
b.on = false;
println (“no match”);
println(“id1: ” + id);
println(“id2: ” + b.id);
}
}
}
class Timer {
int savedTime;
int totalTime;
Timer (int tempTotalTime){
totalTime = tempTotalTime;
}
void start() {
savedTime = millis();
}
boolean isFinished() {
int passedTime = millis() – savedTime;
if (passedTime > totalTime) {
return true;
}
else{
return false;
}
}
}