-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engine.java
692 lines (628 loc) · 21.5 KB
/
Engine.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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import java.util.LinkedList;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Engine{
static class Move{
int type = 0;
Car first;
Car last;
int index;
}
private Map selectedMap;
private GameTimer timer;
private GameSolver hint;
private StarManager stars;
private GameManager gameManager;
private LinkedList<Move> moves;
private int volume;
public Engine(GameManager manager) {
gameManager = manager;
stars = new StarManager();
moves = new LinkedList<Move>();
volume = 50;
selectedMap = null;
}
/**
*
* @param x1
* @param y1
* @param x2
* @param y2
*/
// public boolean moveCar(int x1, int y1, int x2, int y2) {
// // TODO - implement Engine.moveCar
// // throw new UnsupportedOperationException();
// Node newNode = new Node();
// newNode.x1Move = x1;
// newNode.y1Move = y1;
// newNode.x2Move = x2;
// newNode.y2Move = y2;
// if(!(moves.getLast().equals(newNode))) {
// moves.add(newNode);
// return true;
// }
// return false;
// }
/**
*
* @param clock
*/
public boolean gameLost(GameTimer clock) {
// TODO - implement Engine.gameLost
// throw new UnsupportedOperationException();
/*if(clock.getOutOfTime())
{
return true;
}*/
return false;
}
public boolean gameWon() {
// TODO - implement Engine.gameWon
// throw new UnsupportedOperationException();
Car player = selectedMap.getPlayer();
if(player.getY() == selectedMap.getDimension()-2)
{
gameManager.getDataStorage().updateOpenMaps(selectedMap.getDimension(),gameManager.getOpenMapsArray());
return true;
}
return false;
}
public void updateStars() {
// TODO - implement Engine.updateStars
int starsGained = calculateStars();
stars.increaseStars(starsGained);
//throw new UnsupportedOperationException();
}
public int calculateStars() {
int starsReturned = 0;
// TODO - implement Engine.calculateStars
//throw new UnsupportedOperationException();
if(timer.getTimerOn() == false)
{
if(moves.size() - selectedMap.getMinMoveCount() <= 4)
{
starsReturned = stars.getThreeStars();
//stars.increaseStars(stars.getThreeStars());
}
if(moves.size() - selectedMap.getMinMoveCount() > 4 && moves.size() - selectedMap.getMinMoveCount() <= 7)
{
starsReturned = stars.getTwoStars();
//stars.increaseStars(stars.getTwoStars());
}
if(moves.size() - selectedMap.getMinMoveCount() > 7)
{
starsReturned = stars.getOneStar();
//stars.increaseStars(stars.getOneStar());
}
}
else if(timer.getTimerOn() == true)
{
int difficulty = selectedMap.getDifficulty();
/*if(timer.getOutOfTime())
{
starsReturned = 0;
}*/
//if(!timer.getOutOfTime()) {
if(timer.getTimeSpent() <= difficulty * 120000/4)
{
starsReturned = stars.getThreeStars();
}
else if(timer.getTimeSpent() > difficulty * 120000/ 4 && timer.getTimeSpent() <= difficulty * 120000 /3) {
starsReturned = stars.getTwoStars();
}
else if(timer.getTimeSpent() > difficulty * 120000/ 3 && timer.getTimeSpent() <= difficulty * 120000) {
starsReturned = stars.getOneStar();
}
//}
}
return starsReturned;
}
public void playSound() {
// TODO - implement Engine.playSound
// throw new UnsupportedOperationException();
if(gameWon()) {
// Media gameWonSound = new Media(new File("gameWonSound.mp3").toURI());
// MediaPlayer mediaPlayer = new MediaPlayer(gameWonSound); IN THE FILE MANAGER
gameManager.getDataStorage().getSoundEffects()[0].play();
}
else if(gameLost(timer)) {
// Media gameLostSound = new Media(new File("gameLostSound.mp3").toURI());
// MediaPlayer mediaPlayer = new MediaPlayer(gameLostSound); IN THE FILE MANAGER
gameManager.getDataStorage().getSoundEffects()[1].play();
}
}
// public int getHints() {
// // TODO - implement Engine.getHints
// throw new UnsupportedOperationException();
// }
public void undo(Car first, int index, int type) {
if ( type == 0 || type == 2) {
selectedMap.getCars()[index] = first;
} else if ( type == 1 ) {
Car[] cars = selectedMap.getCars();
Car[] newCars = new Car[cars.length + 1];
for ( int i = 0; i < index; i++ )
newCars[i] = cars[i];
newCars[index] = first;
for ( int i = index+1; i < newCars.length; i++)
newCars[i] = cars[i-1];
updateBlockinfo();
selectedMap.setCars(newCars);
} else if( type == 3) {
selectedMap.getCars()[index] = first.clone();
}
updateBlockinfo();
}
public Car[] getLastMove() {
if ( moves.size() > 0 ) {
Move temp = moves.pollFirst();
Car[] move = new Car[2];
move[0] = temp.first;
move[1] = temp.last;
return move;
}
return null;
}
public int[] getLastMoveData() {
if ( moves.size() > 0 ) {
int[] res = new int[2];
res[0] = moves.peek().type;
res[1] = moves.peek().index;
return res;
}
return null;
}
public Map getSelectedMap() {
return this.selectedMap;
}
/**
*
* @param selectedMap
*/
public void setSelectedMap(Map selectedMap) {
this.selectedMap = selectedMap;
timer = new GameTimer(selectedMap.getTime());
}
public GameTimer getTimer() {
return this.timer;
}
/**
*
* @param timer
*/
public void setTimer(GameTimer timer) {
this.timer = timer;
}
public GameSolver getHint() {
return this.hint;
}
/**
*
* @param hint
*/
public void setHint(GameSolver hint) {
this.hint = hint;
}
public void createHint() {
if ( selectedMap != null )
hint = new GameSolver(selectedMap);
}
public LinkedList<int[]> getHints() {
return hint.generateHint(true);
}
public int[] getStars() {
return this.stars.getStars();
}
/**
*
* @param stars
*/
public void setStars(StarManager stars) {
this.stars = stars;
}
public int getExitY(){
Block[][] arr = selectedMap.getBlocks();
for(int i = 0; i < arr.length; i++){
for (int j = 0; j<arr.length; j++){
if (arr[i][j].isFinishBlock()){
return j;
}
}
}
return -1;
}
public int getExitX(){
Block[][] arr = selectedMap.getBlocks();
for(int i = 0; i < arr.length; i++){
for (int j = 0; j<arr.length; j++){
if (arr[i][j].isFinishBlock()){
return i;
}
}
}
return -1;
}
public void reset() {
moves = new LinkedList();
timer.cancelTimer();
timer = new GameTimer(selectedMap.getTime());
}
public LinkedList getMoves() {
return this.moves;
}
/**
*
* @param moves
*/
public void setMoves(LinkedList moves) {
this.moves = moves;
}
public int getVolume() {
return this.volume;
}
/**
*
* @param volume
*/
public void setVolume(int volume) {
this.volume = volume;
}
public boolean updateCarX(Car car, int x) {
if ( car.getX() != x ) {
Move temp = new Move();
temp.first = car.clone();
temp.type = 0;
car.setHorizontalX( x, x + car.getLength() - 1);
temp.last = car.clone();
moves.addFirst(temp);
}
return true;
}
public boolean updateCarY(Car car, int y) {
if (car.getY() != y ) {
Move temp = new Move();
temp.first = car.clone();
temp.type = 0;
car.setVerticalY( y, y + car.getLength() - 1);
temp.last = car.clone();
moves.addFirst(temp);
}
return true;
}
public void updateBlockinfo(){
Block[][] arr = selectedMap.getBlocks();
Car[] cars = selectedMap.getCars();
for ( int i = 0; i < selectedMap.getDimension(); i++) {
for ( int j = 0; j < selectedMap.getDimension(); j++) {
arr[i][j].setOccupied(false);
}
}
for ( int i = 0; i < cars.length; i++) {
if ( cars[i].getCarDirection() == 0 ) {
for ( int j = 0; j < cars[i].getLength(); j++) {
arr[cars[i].getX()][cars[i].getY()+j].setOccupied(true);
}
} else if ( cars[i].getCarDirection() == 1 ) {
for ( int j = 0; j < cars[i].getLength(); j++) {
arr[cars[i].getX()+j][cars[i].getY()].setOccupied(true);
}
}else if ( cars[i].getCarDirection() == 2 ) {
for ( int j = 0; j < cars[i].getLength(); j++) {
arr[cars[i].getX()][cars[i].getY()+j].setOccupied(true);
}
}else {
for ( int j = 0; j < cars[i].getLength(); j++) {
arr[cars[i].getX()+j][cars[i].getY()].setOccupied(true);
}
}
}
// for ( int i = 0; i < arr.length; i++ ) {
// for ( int j = 0; j < arr.length; j++) {
// int k = arr[i][j].isOccupied() ? 1 : 0;
// System.out.print(k + " ");
// }
// System.out.println();
// }
// System.out.println();
}
public void blowUpCar( int toGo ) {
Car[] cars = selectedMap.getCars();
Car[] newCars = new Car[cars.length - 1];
Car temp = cars[toGo];
Move move = new Move();
move.index = toGo;
move.type = 1;
move.first = temp.clone();
move.last = null;
moves.addFirst(move);
for ( int i = 0; i < toGo; i++ )
newCars[i] = cars[i];
for ( int i = toGo+1; i < cars.length; i++)
newCars[i-1] = cars[i];
selectedMap.setCars(newCars);
System.out.println("size: " + moves.size());
//cars = selectedMap.getCars();
}
public int getCarNo() {
return selectedMap.getCars().length;
}
public Car findCar(int x, int y) {
Car[] cars = selectedMap.getCars();
for ( int i = 0; i < cars.length; i++ ) {
if ( x >= cars[i].getX() && x <= cars[i].getHorizontalX() ) {
if ( y >= cars[i].getY() && y <= cars[i].getVerticalY() )
return cars[i];
}
}
return null;
}
public int findCarIndex(int x, int y) {
Car[] cars = selectedMap.getCars();
for ( int i = 0; i < cars.length; i++ ) {
if ( x >= cars[i].getX() && x <= cars[i].getHorizontalX() ) {
if ( y >= cars[i].getY() && y <= cars[i].getVerticalY() )
return i;
}
}
return -1;
}
public Car getCar(int index) {
return selectedMap.getCars()[index];
}
public Car[] getCars() {
return selectedMap.getCars();
}
public void shrinkCar( int index) {
Car[] cars = selectedMap.getCars();
Move move = new Move();
move.first = cars[index].clone();
move.type = 2;
move.index = index;
if ( cars[index].getCarDirection() == 1 || cars[index].getCarDirection() == 3)
cars[index].setHorizontalX(cars[index].getX(), cars[index].getHorizontalX() - 1);
else
cars[index].setVerticalY(cars[index].getY(), cars[index].getVerticalY() - 1);
cars[index].setLength( cars[index].getLength() - 1);
move.last = cars[index].clone();
moves.addFirst(move);
}
public int[] findMax( Car curr ) {
Block[][] blocks = selectedMap.getBlocks();
int moveForward = 0;
int moveBackward = 0;
if ( curr != null ) {
if ( curr.getCarDirection() == 1 || curr.getCarDirection() == 3 ) {
int i = curr.getX() - 1;
while ( i > -1 && !blocks[i][curr.getY()].isOccupied() ) {
moveForward++;
i--;
}
int end = curr.getHorizontalX() + 1;
while ( end < selectedMap.getDimension() && !blocks[end][curr.getY()].isOccupied()) {
moveBackward++;
end++;
}
} else {
int i = curr.getY() - 1;
while ( i > -1 && !blocks[curr.getX()][i].isOccupied()) {
moveForward++;
i--;
}
int end = curr.getVerticalY() + 1;
while ( end < selectedMap.getDimension() && !blocks[curr.getX()][end].isOccupied()) {
moveBackward++;
end++;
}
}
}
int[] res = new int[2];
res[0] = moveForward;
res[1] = moveBackward;
return res;
}
public Car rotateCar(int index){
System.out.println(selectedMap);
Car[] theMapCars = getCars();
Car toChange = theMapCars[index];
Car tmp;
int change, head, end,headY,endY;
Move move = new Move();
move.index = index;
move.type = 3;
move.first = theMapCars[index].clone();
switch (toChange.getCarDirection()){
case 0:
head = toChange.getY();
end = toChange.getVerticalY();
change = theMapCars[index].getX()+toChange.getLength()-1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(3);
tmp.setHorizontalX(theMapCars[index].getX() ,change);
tmp.setVerticalY(toChange.getY(),toChange.getY());
//System.out.println("Previous values for the car " + theMapCars[index].getY() + " " + theMapCars[index].getVerticalY() + " "+ theMapCars[index].getX() + " " + theMapCars[index].getHorizontalX() );
//System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
//System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
if (change < selectedMap.getDimension() && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(3);
theMapCars[index].setHorizontalX(theMapCars[index].getX() ,change);
theMapCars[index].setVerticalY(toChange.getVerticalY(),toChange.getVerticalY());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 1:
change = theMapCars[index].getY()-toChange.getLength()+1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(0);
tmp.setHorizontalX(theMapCars[index].getHorizontalX() ,theMapCars[index].getHorizontalX());
tmp.setVerticalY(change,theMapCars[index].getY());
if (change >= 0 && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(0);
Car car = theMapCars[index].clone();
//System.out.println(car.getX() + " " + car.getHorizontalX() + " " + car.getY() + " " +car.getVerticalY());
theMapCars[index].setHorizontalX(theMapCars[index].getHorizontalX() ,theMapCars[index].getHorizontalX());
theMapCars[index].setVerticalY(change,theMapCars[index].getY());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 2:
change = theMapCars[index].getX() - toChange.getLength() + 1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(1);
tmp.setHorizontalX(change,theMapCars[index].getX());
tmp.setVerticalY(theMapCars[index].getY(),theMapCars[index].getY());
System.out.println("Previous values for the car " + theMapCars[index].getY() + " " + theMapCars[index].getVerticalY() + " "+ theMapCars[index].getX() + " " + theMapCars[index].getHorizontalX() );
System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
if (change>= 0 && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(1);
theMapCars[index].setHorizontalX(change ,theMapCars[index].getX());
theMapCars[index].setVerticalY(theMapCars[index].getY(),theMapCars[index].getY());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 3:
change = theMapCars[index].getY()+toChange.getLength()-1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(2);
tmp.setHorizontalX(theMapCars[index].getX() ,theMapCars[index].getX());
tmp.setVerticalY(theMapCars[index].getY(),change);
System.out.println("Previous values for the car " + theMapCars[index].getY() + " " + theMapCars[index].getVerticalY() + " "+ theMapCars[index].getX() + " " + theMapCars[index].getHorizontalX() );
System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
if (change < selectedMap.getDimension() && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(2);
theMapCars[index].setHorizontalX(theMapCars[index].getX() ,theMapCars[index].getX());
theMapCars[index].setVerticalY(theMapCars[index].getY(),change);
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
default:
return null;
}
switch (toChange.getCarDirection()){
case 0:
change = theMapCars[index].getX()-toChange.getLength()+1;
//Car tmp = theMapCars[index].clone();
tmp = theMapCars[index].clone();
tmp.setCarDirection(1);
tmp.setHorizontalX(change,theMapCars[index].getX());
tmp.setVerticalY(toChange.getY(),toChange.getY());
System.out.println("My x coor: " + change + " " + tmp.getHorizontalX());
if (change >=0 && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(1);
theMapCars[index].setHorizontalX(tmp.getX(),tmp.getHorizontalX());
theMapCars[index].setVerticalY(toChange.getY(),toChange.getY());
System.out.println("My x coor: " + theMapCars[index].getX() + " " + theMapCars[index].getHorizontalX());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 1:
change = theMapCars[index].getVerticalY()+toChange.getLength()-1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(2);
tmp.setHorizontalX(theMapCars[index].getHorizontalX() ,theMapCars[index].getHorizontalX());
tmp.setVerticalY(theMapCars[index].getVerticalY(),change);
System.out.println("Previous values for the car " + theMapCars[index].getY() + " " + theMapCars[index].getVerticalY() + " "+ theMapCars[index].getX() + " " + theMapCars[index].getHorizontalX() );
System.out.println("My case 3 says : "+ change+ " "+ theMapCars[index].getHorizontalX() + " " +theMapCars[index].getX());
if (change < selectedMap.getDimension() && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(2);
theMapCars[index].setHorizontalX(theMapCars[index].getHorizontalX() ,theMapCars[index].getHorizontalX());
theMapCars[index].setVerticalY(theMapCars[index].getVerticalY(),change);
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 2:
change = theMapCars[index].getHorizontalX()+toChange.getLength()-1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(3);
tmp.setHorizontalX(theMapCars[index].getHorizontalX() ,change);
tmp.setVerticalY(toChange.getY(),toChange.getY());
if (change <selectedMap.getDimension() && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(3);
theMapCars[index].setHorizontalX(theMapCars[index].getHorizontalX() ,change);
theMapCars[index].setVerticalY(toChange.getY(),toChange.getY());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
case 3:
change = theMapCars[index].getY()-toChange.getLength()+1;
tmp = theMapCars[index].clone();
tmp.setCarDirection(0);
tmp.setHorizontalX(theMapCars[index].getX() ,theMapCars[index].getX());
tmp.setVerticalY(change,theMapCars[index].getY());
if (change >= 0 && canRotationBeMade(tmp,nullifyCar(theMapCars[index]))){
theMapCars[index].setCarDirection(0);
Car car = theMapCars[index].clone();
//System.out.println(car.getX() + " " + car.getHorizontalX() + " " + car.getY() + " " +car.getVerticalY());
theMapCars[index].setHorizontalX(theMapCars[index].getX() ,theMapCars[index].getX());
theMapCars[index].setVerticalY(change,theMapCars[index].getY());
move.last = theMapCars[index].clone();
moves.addFirst(move);
return theMapCars[index];
}
break;
default:
return null;
}
return null;
}
private boolean canRotationBeMade(Car car,Block[][] blocks){
System.out.println(selectedMap);
String tmp = "";
for (int i = 0; i < blocks.length; i++){
for (int j = 0; j < blocks.length; j++){
tmp = tmp + blocks[i][j].isOccupied() + " ";
}
tmp += "\n";
}
System.out.println(tmp);
//System.out.println("Car Direction " + car.getCarDirection());
if (car.getCarDirection() == 1 || car.getCarDirection() == 3){
//System.out.println("Car Direction " + car.getCarDirection() + " "+ car.getX() + " " + car.getHorizontalX() );
for (int i = car.getX(); i<= car.getHorizontalX(); i++){
System.out.println(i + " " + car.getY() + " " + blocks[i][car.getY()].isOccupied());
if (blocks[i][car.getY()].isOccupied()){
return false;
}
}
}else {
for (int i = car.getY(); i<= car.getVerticalY(); i++){
if (blocks[car.getX()][i].isOccupied()){
return false;
}
}
}
return true;
}
private Block[][] nullifyCar(Car car){
Map tmp = selectedMap.clone();
Block[][] blocks = tmp.getBlocks();
if (car.getCarDirection() == 1 || car.getCarDirection() == 3){
for (int i = car.getX(); i<= car.getHorizontalX(); i++){
blocks[i][car.getY()].setOccupied(false);
}
}else {
for (int i = car.getY(); i<= car.getVerticalY(); i++){
blocks[car.getX()][i].setOccupied(false);
}
}
return blocks;
}
}