-
Notifications
You must be signed in to change notification settings - Fork 1
/
BorderPane_for_L3.java
617 lines (554 loc) · 22.6 KB
/
BorderPane_for_L3.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
/*
This program was prepared for Programming-ll final project.
Evren Koymat - 150120518
Sinan Göçmen - 150120519
*/
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
//this is the border pane of the level two which extends BorderPane.
//It contains three pane, which are the game board,the top board and the bottom board.
public class BorderPane_for_L3 extends BorderPane {
//We create these panes and then add them to the border pane.
Game_Board3 game_board3 = new Game_Board3();
Top_Board3 top_board3 = new Top_Board3();
Bottom_Board3 bottom_board3 = new Bottom_Board3();
public double counter; // It will count the number of rectangle which refill with blue or white color
public static double points; // It will count the total point of current level
public static double high_score; //It will store the highest score in a level.
public static boolean is_it_done; //It determines if the level is done or not
public BorderPane_for_L3() {
setCenter(game_board3);
setTop(top_board3);
setBottom(bottom_board3);
}
//**************************************************************************
//the game board is a GridPane. It contains 100 rectangles.
class Game_Board3 extends GridPane {
//We define an array to save and "find" rectangles easily.
rectangle[][] r_list = new rectangle[10][10];
public Game_Board3() {
//the build method creates the rectangles and add them to specific positions.
build();
}
public void build() {
//Following lines are created to design the board.
setStyle("-fx-border-color: black;-fx-background-color: darkgray");
setPadding(new Insets(10,10,10,10));
setHgap(5);
setVgap(5);
//Here is a really important part.
//For each position, we create a rectangle and add it to the pane and also to the array.
for(int i = 0;i<10;i++) {
for(int j = 0;j<10;j++) {
rectangle r = new rectangle(i,j);
r_list[i][j] = r;
add(r, i, j);
//When we click the mouse, destroy all function is activated.
r.setOnMouseClicked(e -> {destroy_all(r);
//points variable changes according to counter variable.
if (counter == 1)
points -= 3;
else if (counter == 2)
points -=1;
else if (counter == 3)
points +=1;
else if (counter ==4)
points +=2;
else if (counter == 5)
points +=4;
if (points >= high_score)
high_score = points;
// We create Labels to add top board of the pane.
Label name = new Label("Level # 3 ");
Label point = new Label("" + points);
Label score = new Label(" High Score: " +high_score);
//We use the top_board1.getChildren().clear method to delete previous point and score. So each mouseclicked event changes the point and score.
top_board3.getChildren().clear();
top_board3.getChildren().add(name);
top_board3.getChildren().add(point);
top_board3.getChildren().add(score);
//We need to assing counter variable to 0 because each mouseclick event destroy different rectangles and different number of rectangles.
counter = 0;
});
}
}
//These are just settings for level-3.
r_list[1][5].setFill(Color.PURPLE);r_list[1][5].setDestroyable(true);
r_list[2][5].setFill(Color.PURPLE);r_list[2][5].setDestroyable(true);
r_list[3][5].setFill(Color.PURPLE);r_list[3][5].setDestroyable(true);
r_list[6][5].setFill(Color.PURPLE);r_list[6][5].setDestroyable(true);
r_list[7][5].setFill(Color.PURPLE);r_list[7][5].setDestroyable(true);
r_list[8][5].setFill(Color.PURPLE);r_list[8][5].setDestroyable(true);
r_list[1][6].setFill(Color.PURPLE);r_list[1][6].setDestroyable(true);
r_list[8][6].setFill(Color.PURPLE);r_list[8][6].setDestroyable(true);
r_list[1][7].setFill(Color.PURPLE);r_list[1][7].setDestroyable(true);
r_list[8][7].setFill(Color.PURPLE);r_list[8][7].setDestroyable(true);
r_list[1][8].setFill(Color.PURPLE);r_list[1][8].setDestroyable(true);
r_list[2][8].setFill(Color.PURPLE);r_list[2][8].setDestroyable(true);
r_list[3][8].setFill(Color.PURPLE);r_list[3][8].setDestroyable(true);
r_list[4][8].setFill(Color.PURPLE);r_list[4][8].setDestroyable(true);
r_list[5][8].setFill(Color.PURPLE);r_list[5][8].setDestroyable(true);
r_list[6][8].setFill(Color.PURPLE);r_list[6][8].setDestroyable(true);
r_list[7][8].setFill(Color.PURPLE);r_list[7][8].setDestroyable(true);
r_list[8][8].setFill(Color.PURPLE);r_list[8][8].setDestroyable(true);
r_list[1][1].setFill(Color.BLUE);r_list[1][1].setDestroyable(true);
r_list[2][1].setFill(Color.BLUE);r_list[2][1].setDestroyable(true);
r_list[3][1].setFill(Color.BLUE);r_list[3][1].setDestroyable(true);
r_list[4][1].setFill(Color.BLUE);r_list[4][1].setDestroyable(true);
r_list[5][1].setFill(Color.BLUE);r_list[5][1].setDestroyable(true);
r_list[6][1].setFill(Color.BLUE);r_list[6][1].setDestroyable(true);
r_list[7][1].setFill(Color.BLUE);r_list[7][1].setDestroyable(true);
r_list[8][1].setFill(Color.BLUE);r_list[8][1].setDestroyable(true);
r_list[1][2].setFill(Color.BLUE);r_list[1][2].setDestroyable(true);
r_list[8][2].setFill(Color.BLUE);r_list[8][2].setDestroyable(true);
r_list[1][3].setFill(Color.BLUE);r_list[1][3].setDestroyable(true);
r_list[8][3].setFill(Color.BLUE);r_list[8][3].setDestroyable(true);
r_list[1][4].setFill(Color.BLUE);r_list[1][4].setDestroyable(true);
r_list[2][4].setFill(Color.BLUE);r_list[2][4].setDestroyable(true);
r_list[3][4].setFill(Color.BLUE);r_list[3][4].setDestroyable(true);
r_list[6][4].setFill(Color.BLUE);r_list[6][4].setDestroyable(true);
r_list[7][4].setFill(Color.BLUE);r_list[7][4].setDestroyable(true);
r_list[8][4].setFill(Color.BLUE);r_list[8][4].setDestroyable(true);
}
//This method gets a rectangle and find the other rectangles, which are around the rectangle, to destroy.
//There is a separation for each corner and edge.
//For example, when we click 0,8 , we destroy 0,8-0,9-1,8 at the same time if all of them are available,which means purple or blue.
//If they are not, we do not anything to them. We can understand this by using IsDestroyable() method.
public void destroy_all(rectangle r) {
//We get the coordinates of the rectangle to simplify.
int i = r.getX_coordinate();
int j = r.getY_coordinate();
if(i==0 && j==0 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
//when we destroy a rectangle counter variable increase 1.
counter +=1;
//we need to ith and jth values for destroyed rectangle to print the bottom page.
Label box = new Label("Box:" +i + "-" +j );
//.clear() method helps us to clear the previous bottom page. So we can change the Box ith and jth values according to destroyed rectangles.
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
//hit# label keeps the value of affected rectangle.
Label hit1 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit1);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
counter +=1;
Label hit2 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit2);
}
//according to counter value we need to print bottom page the value of gained or lost points
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i==0 && j==9 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
Label hit3 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit3);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit4 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit4);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i==9 && j==9 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit5 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit5);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit6 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit6);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i==9 && j==0 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit7 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit7);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
counter +=1;
Label hit8 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit8);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i==0 && j>0 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
Label hit9 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit9);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
counter +=1;
Label hit10 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit10);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit11 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit11);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i>0 && j==0 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
Label hit12 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit12);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit13 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit13);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
counter +=1;
Label hit14 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit14);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i==9 && j<9 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
counter +=1;
Label hit15 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit15);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit16 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit16);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit17 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit17);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(i<9 && j==9 && r.IsDestroyable() ) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
Label hit18 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit18);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit19 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit19);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit20 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit20);
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
else if(r.IsDestroyable()) {
if(r_list[i][j].IsDestroyable()) {
r_list[i][j].destroy();
counter +=1;
Label box = new Label("Box:" +i + "-" +j );
bottom_board3.getChildren().clear();
bottom_board3.getChildren().add(box);
}
if(r_list[i+1][j].IsDestroyable()) {
r_list[i+1][j].destroy();
counter +=1;
Label hit21 = new Label(" Hit:" + (i+1) +"-" + j);
bottom_board3.getChildren().add(hit21);
}
if(r_list[i-1][j].IsDestroyable()) {
r_list[i-1][j].destroy();
counter +=1;
Label hit22 = new Label(" Hit:" + (i-1) +"-" + j);
bottom_board3.getChildren().add(hit22);
}
if(r_list[i][j-1].IsDestroyable()) {
r_list[i][j-1].destroy();
counter +=1;
Label hit23 = new Label(" Hit:" + i +"-" + (j-1));
bottom_board3.getChildren().add(hit23);
}
if(r_list[i][j+1].IsDestroyable()) {
r_list[i][j+1].destroy();
Label hit24 = new Label(" Hit:" + i +"-" + (j+1));
bottom_board3.getChildren().add(hit24);
counter +=1;
}
if (counter == 1)
bottom_board3.getChildren().add(new Label(" (-3 points)"));
else if (counter == 2)
bottom_board3.getChildren().add(new Label(" (-1 points)"));
else if (counter == 3)
bottom_board3.getChildren().add(new Label(" (+1 points)"));
else if (counter ==4)
bottom_board3.getChildren().add(new Label(" (+2 points)"));
else if (counter == 5)
bottom_board3.getChildren().add(new Label(" (+4 points)"));
}
//we need to check all rectangle if their colors either white or darkgray.If all the rectangles filled like this, our level is completed.
int r_count = 0;
for ( int m = 0 ; m < 10 ; m++) {
for (int n = 0 ; n<10 ; n++) {
if ((r_list[m][n].getFill() == Color.WHITE || r_list[m][n].getFill() == Color.DARKGRAY)) {
r_count +=1;
}
if(r_count ==100)
is_it_done=true;
}
}
//When our level is completed , we print the next level is available now! message to the bottom page.
if(is_it_done == true && r_count == 100) {
bottom_board3.getChildren().clear();
Label nextLevel = new Label("next level is available now!");
nextLevel.setAlignment(Pos.CENTER);
bottom_board3.setPadding(new Insets(30,30,30,30));
bottom_board3.getChildren().add(nextLevel);
nextLevel.setLayoutX(220);
nextLevel.setLayoutY(13);
}
}//end of the destroy all function.
}// end of the game board 3.
//**************************************************************************
//This is the top board of the level-3
class Top_Board3 extends HBox{
public Top_Board3() {
build();
}
public void build() {
setPadding(new Insets(10,10,10,10));
setStyle("-fx-border-color: black");
Label name = new Label("Level # 3 ");
Label point = new Label("" + points);
Label score = new Label(" High Score: " + high_score);
getChildren().add(name);
getChildren().add(point);
getChildren().add(score);
}
}
//**************************************************************************
//This is the bottom board of the level-3
class Bottom_Board3 extends Pane{
public Bottom_Board3() {
build();
}
public void build() {
setPadding(new Insets(10,10,10,10));
setStyle("-fx-border-color: black");
Label name1 = new Label("---Text---");
getChildren().add(name1);
name1.setLayoutY(5);
}
}
//***************************************************************************
// There is a tricky part here! We created a class named rectangle which extends 'Rectangle'.
// We add some useful properties to rectangle.
class rectangle extends Rectangle {
boolean Destroyable = false;//determines if the rectangle is destroyable
//As default, rectangles are all brown and not destroyable. We set it when we build the game board.
int x_coordinate;//better than getX(), because give the information as coordinate, not pixel count or etc.
int y_coordinate;//
public rectangle (int x, int y) {
//Just some settings for default rectangle.
this.setHeight(50);
this.setWidth(50);
this.x_coordinate = x;
this.y_coordinate = y;
this.setFill(Color.DARKGRAY);
this.setStroke(Color.BLACK);
}
//Getters and setters
public boolean IsDestroyable() {
return Destroyable;
}
public int getX_coordinate() {
return x_coordinate;
}
public int getY_coordinate() {
return y_coordinate;
}
public void setDestroyable(boolean Destroyable) {
this.Destroyable = Destroyable;
}
public void setX_coordinate(int x) {
this.x_coordinate = x;
}
public void setY_coordinate(int y) {
this.y_coordinate = y;
}
//This method changes the color of the rectangle.
public void destroy() {
//If it is purple, it turns the color to blue
if(getFill()==Color.PURPLE) {
setFill(Color.BLUE);
}
//If it is blue, it turns the color to white and set destroyable property as false.
else if(getFill()==Color.BLUE) {
setFill(Color.WHITE);
setDestroyable(false);
}
}
}
}