- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
Latest commit
236 lines (186 loc) · 4.42 KB
/
Copy pathController.java
File metadata and controls
236 lines (186 loc) · 4.42 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
/*
* Levi Crider
* 2/9/22
* Legend of Zelda
*
*
*/
importjava.awt.event.MouseListener;
importjava.awt.event.MouseEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.ActionEvent;
importjava.awt.event.KeyListener;
importjava.awt.event.KeyEvent;
//This class is capable of handling ActionEvents such as when someone pushes a button
classControllerimplementsActionListener, MouseListener, KeyListener{
//Member variables
Viewview;
Modelmodel;
//Controls
//Quit
booleanesc;
booleanq;
//Save Load
booleans;
booleanl;
//Toggle map
booleanmapEdit = false;
booleanpotOrBrick = false; //false is for brick, true is for pots.
//Movement
booleanup;
booleandown;
booleanleft;
booleanright;
//Boomerang
booleanctrl;
Controller(Modelm) {
model = m;
}
publicvoidactionPerformed(ActionEvente) { //method that handles the event
}
voidsetView(Viewv) { //Setter that sets the view
view = v;
}
publicvoidkeyPressed(KeyEvente){
switch(e.getKeyCode()){
//Quitting
caseKeyEvent.VK_ESCAPE: esc = true; break;
caseKeyEvent.VK_Q: q = true; break;
//Saving
caseKeyEvent.VK_S:
model.Marshal();
System.out.println("Saved");
break;
//Loading
caseKeyEvent.VK_L:
JsonloadObject = Json.load("brickLocation.json");
model.Unmarshal(loadObject);
System.out.println("Loaded");
break;
//Toggling map edit
caseKeyEvent.VK_E:
if(mapEdit){
mapEdit = false;
System.out.println("Map editing turned off!");
}
else{
mapEdit = true;
System.out.println("Map editing turned on!");
if (potOrBrick){
System.out.println("Editing Pots right now!");
}
elseif (!potOrBrick){
System.out.println("Editing Bricks right now!");
}
}
break;
caseKeyEvent.VK_P:
if (potOrBrick){
potOrBrick = false;
if (mapEdit && !potOrBrick){
System.out.println("Editing Bricks");
}
}
else{
potOrBrick = true;
if (mapEdit && potOrBrick){
System.out.println("Editing Pots");
}
}
break;
//Movement cases
caseKeyEvent.VK_RIGHT:
right = true;
break;
caseKeyEvent.VK_LEFT:
left = true;
break;
caseKeyEvent.VK_UP:
up = true;
break;
caseKeyEvent.VK_DOWN:
down = true;
break;
}
}
publicvoidkeyReleased(KeyEvente)
{
switch(e.getKeyCode())
{
//Movement
caseKeyEvent.VK_RIGHT: right = false; break;
caseKeyEvent.VK_LEFT: left = false; break;
caseKeyEvent.VK_UP: up = false; break;
caseKeyEvent.VK_DOWN: down = false; break;
//Boomerang
caseKeyEvent.VK_CONTROL: model.addBoomerang(); break;
}
}
publicvoidkeyTyped(KeyEvente)
{
}
voidupdate() {
model.link.savePrev();
//Exit
if(esc) System.exit(0);
if (q) System.exit(0);
//Moving Link
if (right){
viewIncreaseX();
model.link.moveRight();
}
if (left){
//Moving the window when we goes through a left door
viewDecreaseX();
model.link.moveLeft();
}
if (up){
model.link.moveUp();
//Moving the window when we goes through an up door
viewDecreaseY();
}
if (down){
model.link.moveDown();
//Moving the window when we goes through an down door
viewIncraseY();
}
}
publicvoidmousePressed(MouseEvente)
{
//Gets the location of where user clicks
intlocationx = e.getX();
intlocationy = e.getY();
//Adding bricks or pots to the map
if(mapEdit && !potOrBrick){
model.addBrickToScreen(locationx + View.scrollPositonX, locationy + View.scrollPositonY); //Adds the brick to the screen
}
if (mapEdit && potOrBrick){
model.addPotToScreen(locationx + View.scrollPositonX, locationy + View.scrollPositonY);
}
}
//Making sure that the view stays in bounds
voidviewIncreaseX(){
if (model.link.x == View.windowXSize){
View.scrollPositonX += View.windowXSize;
}
}
voidviewDecreaseX(){
if (model.link.x == View.windowXSize){
View.scrollPositonX -= View.windowXSize;
}
}
voidviewIncraseY(){
if (model.link.y == View.windowYSize){
View.scrollPositonY += View.windowYSize;
}
}
voidviewDecreaseY(){
if (model.link.y == View.windowYSize){
View.scrollPositonY -= View.windowYSize;
}
}
publicvoidmouseReleased(MouseEvente) { }
publicvoidmouseEntered(MouseEvente) { }
publicvoidmouseExited(MouseEvente) { }
publicvoidmouseClicked(MouseEvente) { }
}