Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collections;
- PImage src, patch0, patch1, patch2, patch3;
- ArrayList<PImage> list;
- IntList choices;
- IntList correct;
- int answer_size = 0;
- String msg = "Try Again";
- void setup()
- {
- src = loadImage("mario.png");
- size(512, 512);
- noFill();
- rectMode(CORNERS);
- image(src,0,0);
- patch0 = get(0,0,256,256);
- patch1 = get(257,0,256,256);
- patch2 = get(0,257,256,256);
- patch3 = get(257,257,256,256);
- list = new ArrayList<PImage>();
- list.add(patch0);
- list.add(patch1);
- list.add(patch2);
- list.add(patch3);
- Collections.shuffle(list);
- choices = new IntList();
- correct = new IntList();
- if(list.get(0) == patch0)
- correct.append(0);
- else if(list.get(0) == patch1)
- correct.append(1);
- else if(list.get(0) == patch2)
- correct.append(2);
- else if(list.get(0) == patch3)
- correct.append(3);
- if(list.get(1) == patch0)
- correct.append(0);
- else if(list.get(1) == patch1)
- correct.append(1);
- else if(list.get(1) == patch2)
- correct.append(2);
- else if(list.get(1) == patch3)
- correct.append(3);
- if(list.get(2) == patch0)
- correct.append(0);
- else if(list.get(2) == patch1)
- correct.append(1);
- else if(list.get(2) == patch2)
- correct.append(2);
- else if(list.get(2) == patch3)
- correct.append(3);
- if(list.get(3) == patch0)
- correct.append(0);
- else if(list.get(3) == patch1)
- correct.append(1);
- else if(list.get(3) == patch2)
- correct.append(2);
- else if(list.get(3) == patch3)
- correct.append(3);
- }
- void draw()
- {
- image(list.get(0), 0,0);
- image(list.get(1), 257,0);
- image(list.get(2), 0,257);
- image(list.get(3), 257,257);
- if (answer_size >= 4)
- {
- if (choices.get(0) == correct.get(0) && choices.get(1) == correct.get(1) && choices.get(2) == correct.get(2) && choices.get(3) == correct.get(3))
- msg = "Correct!";
- print(msg);
- }
- else
- {
- print(choices.get(1));
- }
- }
- void mouseClicked()
- {
- if(answer_size < 4)
- {
- if (mouseX < 257 && mouseY < 257)
- choices.append(1);
- else if (mouseX > 257 && mouseY < 257)
- choices.append(2);
- else if (mouseX < 257 && mouseY > 257)
- choices.append(3);
- else
- choices.append(4);
- }
- answer_size++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement