-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameFrame.java
More file actions
260 lines (235 loc) · 8.87 KB
/
GameFrame.java
File metadata and controls
260 lines (235 loc) · 8.87 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
public class GameFrame extends GUI
{
public GameFrame() {
// creates the frame for the grid
gameFrame = new JFrame("Remember Remember");
// Creates the panel used for 4 JButtons that will flash
JPanel p = new JPanel(new GridLayout(1, 3));
if (difficulty == 2) {
p = new JPanel(new GridLayout(2, 3));
} else if (difficulty == 3) {
p = new JPanel(new GridLayout(3, 3));
} else if (difficulty == 4) {
p = new JPanel(new GridLayout(4, 3));
}
// Creates the panel used for 2 JButtons for options
JPanel pane = new JPanel(new GridLayout(1, 2));
Container contentPane = gameFrame.getContentPane();
// Creates a container
contentPane.setLayout(new BorderLayout());
JPanel container = new JPanel(new GridLayout(1, 1));
container.add(level);
container.add(difficultyLabel);
// adds the level JLabel to the content pane
contentPane.add(container, BorderLayout.NORTH);
// contentPane.add(level, BorderLayout.NORTH);
// contentPane.add(difficultyLabel, BorderLayout.SOUTH);
// Adds the JPanel into the content pane
contentPane.add(p, BorderLayout.CENTER);
makeMenu(gameFrame);
// button 1
// one.setContentAreaFilled(false);
// one.setOpaque(true);
// one.setColor(new Color(200,0,100));
ActionListener oneListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(1);
game.playerchallenge(1);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
one = new JButton();
one.addActionListener(oneListener);
one.setBackground(Color.WHITE);
p.add(one);
ActionListener twoListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(2);
game.playerchallenge(2);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
two = new JButton();
two.addActionListener(twoListener);
two.setBackground(Color.WHITE);
p.add(two);
ActionListener threeListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(3);
game.playerchallenge(3);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
three = new JButton();
three.addActionListener(oneListener);
three.setBackground(Color.WHITE);
p.add(three);
ActionListener fourListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(4);
game.playerchallenge(4);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
four = new JButton();
four.addActionListener(fourListener);
four.setBackground(Color.WHITE);
p.add(four);
ActionListener fiveListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(5);
game.playerchallenge(5);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
five = new JButton();
five.addActionListener(oneListener);
five.setBackground(Color.WHITE);
p.add(five);
ActionListener sixListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(6);
game.playerchallenge(6);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
six = new JButton();
six.addActionListener(sixListener);
six.setBackground(Color.WHITE);
p.add(six);
ActionListener sevenListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(7);
game.playerchallenge(7);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
seven = new JButton();
seven.addActionListener(sevenListener);
seven.setBackground(Color.WHITE);
p.add(seven);
ActionListener eightListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(8);
game.playerchallenge(8);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
eight = new JButton();
eight.addActionListener(eightListener);
eight.setBackground(Color.WHITE);
p.add(eight);
ActionListener nineListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(9);
game.playerchallenge(9);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
nine = new JButton();
nine.addActionListener(nineListener);
nine.setBackground(Color.WHITE);
p.add(nine);
ActionListener tenListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(10);
game.playerchallenge(10);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
ten = new JButton();
ten.addActionListener(tenListener);
ten.setBackground(Color.WHITE);
p.add(ten);
ActionListener elevenListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(11);
game.playerchallenge(11);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
eleven = new JButton();
eleven.addActionListener(elevenListener);
eleven.setBackground(Color.WHITE);
p.add(eleven);
ActionListener twelveListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
playerClick(12);
game.playerchallenge(12);
// disables buttons if user has finished entering the challenge
buttonDisable();
}
};
twelve = new JButton();
twelve.addActionListener(twelveListener);
twelve.setBackground(Color.WHITE);
p.add(twelve);
// adds buttons with a refence to a HashMap
buttonList();
// disable all the buttons in the buttonList
for (JButton button : buttonList.values()) {
button.setBackground(Color.WHITE);
button.setEnabled(false);
}
// add the JPanel pane to the contentPane
contentPane.add(pane, BorderLayout.SOUTH);
ActionListener playListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
game.challenge();
// make the buttons flash
blink();
}
};
play = new JButton("Play");
play.addActionListener(playListener);
pane.add(play);
ActionListener quitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
quit();
}
};
JButton quit = new JButton("quit");
quit.addActionListener(quitListener);
pane.add(quit);
gameFrame.setBackground(Color.BLUE);
gameFrame.pack();
gameFrame.setSize(350, (150 * difficulty));
gameFrame.setVisible(true);
gameFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void buttonList() {
buttonList.put(1, one);
buttonList.put(2, two);
buttonList.put(3, three);
if (difficulty == 2 || difficulty == 3 || difficulty == 4) {
buttonList.put(4, four);
buttonList.put(5, five);
buttonList.put(6, six);
}
if (difficulty == 3 || difficulty == 4) {
buttonList.put(7, seven);
buttonList.put(8, eight);
buttonList.put(9, nine);
}
if (difficulty == 4) {
buttonList.put(10, ten);
buttonList.put(11, eleven);
buttonList.put(12, twelve);
}
}
}