Repository navigation
Expand file tree
/
Copy pathNavigation.java
More file actions
258 lines (220 loc) · 6.3 KB
/
Copy pathNavigation.java
File metadata and controls
258 lines (220 loc) · 6.3 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
import java.awt.Color;
import java.awt.Component;
import java.io.IOException;
import javax.swing.JFrame;
/**
* This class is responsible for the window (JFrame) of the program, general JPanel management related to the window and variables passed between JPanels
*
*/
public class Navigation {
//class constants
private final int WWID = 1000;//window width and height
private final int WHEI = 800;
//class variables
private Component showing;// keeps track of which component is being shown
private boolean paused = false;//pause timer
//JPanels inside Navigation
private JFrame current;
private Menu m;
private Settings s;
private HowToPlay h;
private Pause p;
private Endscreen e;
private Renderer screen;
//variables passed to this from settings.java -- these get passed to screen whenever a new renderer is made
private int numSen;
private int diff;
/**
* Constructor of the class. Doesn't do much other than making the JFrame that contains the program by calling startWindow().
*
* @throws IOException
*/
public Navigation() throws IOException {
numSen = 3; //just some default starting variables
diff = 15;
startWindow();
}
/**
* Makes the JFrame for the program.
*
* @throws IOException
*/
private void startWindow() throws IOException{
//display = new Display Menu();
current = new JFrame("The Amazing Maze");
current.setSize(WWID,WHEI);//since we have pack the size shouldn't matter
current.setResizable(true);
//current.pack(); //we don't want this since everything should just work around the fact the window is constant size
current.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//lets us close the window
current.setBackground(Color.GREEN);
current.setVisible(true);
//current.getContentPane().add(screen);
//showMenu(); //This is commented out since it won't work without the required images -- Tom
}
/**
* This is the main function. Doesn't do anything other than create an instance of this class and call showMenu()
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException{
Navigation gameWindow = new Navigation();
//System.out.println(gameWindow.current.getComponent(1));
gameWindow.current.setVisible(true);
gameWindow.current.setFocusable(false);
gameWindow.showMenu();
}
/**
* This function displays the main menu by calling on the Menu class
*
*/
public void showMenu() {
//screen = new Renderer(WWID,WHEI);
try {
m = new Menu(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m.setVisible(true);
setCurrentFrame(m);
}
/**
* This function displays the game by calling on the Renderer class
*
*/
public void showGame() {
screen = new Renderer(this,WWID,WHEI, numSen, diff);
screen.setVisible(true);
this.paused = false;
setCurrentFrame(screen);
}
/**
* This function displays the settings screen by calling on the Settings class
*
*/
public void showSettings() {
try {
s = new Settings(this);
} catch (IOException e) {
e.printStackTrace();
}
s.setVisible(true);
setCurrentFrame(s);
}
/**
* This function displays the instructions screen by calling on the HowToPlay class
*
*/
public void showHowToPlay() {
try {
h = new HowToPlay(this);
} catch (IOException e) {
e.printStackTrace();
}
h.setVisible(true);
setCurrentFrame(h);
}
/**
* This function displays the pause screen by calling on the Pause class
*
*
*/
public void showPause() {
try {
p = new Pause(this);
} catch (IOException e) {
e.printStackTrace();
}
p.setVisible(true);
setCurrentFrame(p);
this.paused = true;
}
/**
* Closes pause screen and returns to game
*
*
*/
public void unPause() {
p.setVisible(false);
screen.setVisible(true);
setCurrentFrame(screen);
this.paused = false;
}
/**
* This function displays the end of game screen by calling on the EndScreen class
*
*
*/
public void showEndScreen(TimerDisplay timer) {
try {
e = new Endscreen(this, timer);
} catch (IOException e) {
e.printStackTrace();
}
this.paused = true;
e.setVisible(true);
setCurrentFrame(e);
}
/***
* Sets the displayed screen to the screen that is passed in and removes all other components from the JFrame
* @param screen the screen that we're making the current JPanel
*/
private void setCurrentFrame(Component view) {
current.getContentPane().add(view);
//you don't want to keep adding stuff to the jframe because you'll eventually have 29384729347 jpanels in the jframe
//so remove other panels before adding them --tom
for(Component c : current.getContentPane().getComponents()){
if(!view.equals(c)){
current.remove(c);
}
}
showing = view;//this keeps track of the panel that is being shown, although there should only be one panel being shown at any time--tom
view.setFocusable(true);
view.requestFocusInWindow();
view.setVisible(true);
current.revalidate();//because im removing stuff you gotta revalidate--tom
}
/**
* Get the panel that is currently being displayed
*
* @return the current screen
*/
public Component getShowing() {
return showing;
}
/**
* Get the renderer instance
*
* @return the renderer instance
*/
public Renderer getRenderer(){
return screen;
}
/**
* Find out whether or not the game is paused
*
* @return true if it is paused and false otherwise
*/
public boolean isPaused() {
return paused;
}
/**
* Sets the number of sentries in the game (called from Settings class) and returns the navigator to the settings screen
*
* @param numSen the number of sentries in the game
*/
public void setNumSen(int numSen) {
this.numSen = numSen;
showSettings();
}
/**
* Sets the difficulty (number of allowed empty tiles) of the game (called from Settings class) and returns the navigator to the settings screen
*
* @param diff the difficulty of the game
*/
public void setDiff(int diff) {
this.diff = diff;
showSettings();
}
}