-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonochromeTile.java
More file actions
38 lines (30 loc) · 1.22 KB
/
MonochromeTile.java
File metadata and controls
38 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.awt.*;
import java.awt.event.MouseEvent;
public class MonochromeTile extends PlayableTile {
public MonochromeTile(int x, int y) {
super(x, y);
correctState = ParsedImage.getBoolean(x-1, y-1);
this.addMouseListener(this);
}
// The correct state of this tile according to the read image, B/W so it can be stored as a boolean
private final boolean correctState;
// Array containing black and white, this is used to swap between the colours when you click, indexing a click counter into this array but using the % operator so it
// doesn't go out of bounds
private final int[] possibleColors = new int[] {-1, Color.black.getRGB()};
int colorIndex = -1;
public boolean reveal() {
Color c = this.getBackground();
boolean wasCorrect = (c.getRGB() == (correctState ? Color.white.getRGB() : Color.black.getRGB()));
if(correctState) {
this.setBackground(Color.white);
} else {
this.setBackground(Color.black);
}
return wasCorrect;
}
@Override
public void mouseClicked(MouseEvent mouseEvent) {
colorIndex++;
this.setBackground(new Color(possibleColors[colorIndex % 2]));
}
}