-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare.java
128 lines (114 loc) · 2.99 KB
/
Square.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import javax.swing.*;
public class Square
{
//State indicates which image is displayed on sqaure
//0 = water, 1 = lily, 2 = green frog, 3 = red frog
//Selected indicated whether the current sqaure is selected and will highlight it
private char state;
private boolean selected;
private JButton button;
public Square()
{
//Constructor
state = '0';
selected = false;
button = new JButton();
}
public Square(char pstate)
{
//Constructor
state = pstate;
//x = px;
//y = py;
button = new JButton();
update();
}
public int getState()
{
return state;
}
public void setState(char pstate)
{
state = pstate;
update();
}
public boolean isSelected()
{
return selected;
}
public void setSelected(boolean pSelected)
{
selected = pSelected;
}
public void update()
{
//Updates image of button based on the state the sqaure is in.
if (state == '1'){
ImageIcon i = new ImageIcon("LilyPad.png");
button.setIcon(i);
}else if (state == '2'&& selected == false ){
ImageIcon i = new ImageIcon("GreenFrog.png");
button.setIcon(i);
}
else if (state == '3' && selected == false){
ImageIcon i = new ImageIcon("RedFrog.png");
button.setIcon(i);
}
else if (state == '2' && selected == true){
ImageIcon i = new ImageIcon("GreenFrog2.png");
button.setIcon(i);
}
else if (state == '3' && selected == true){
ImageIcon i = new ImageIcon("RedFrog2.png");
button.setIcon(i);
} else {
ImageIcon i = new ImageIcon("Water.png");
button.setIcon(i);
}
}
public JButton getButton()
{
return button;
}
public void moveTo(Square pSquare, Square pMiddleSquare)
{
//Change state of sqaures passed in as parameters.
//Set state of sqaure jumping to as the same as this sqaure
//Set state of this sqaure to 1
//Update sqaures images
pSquare.setState(state);
state = '1';
selected = false;
pMiddleSquare.setState('1');
update();
pSquare.update();
pMiddleSquare.update();
}
public boolean validStarter()
{
//returns true if the square has a frog on it
if (state == '2' || state == '3'){
return true;
} else {
return false;
}
}
public boolean validNext()
{
//returns true if the square is a lily
if (state == '1'){
return true;
} else {
return false;
}
}
public boolean validMid()
{
//returns true if the sqaure has a green frog on it
if (state == '2'){
return true;
} else {
return false;
}
}
}