1
1
package com .oopproject .gui ;
2
2
3
- import com .oopproject .world .animals .Animal ;
4
- import com .oopproject .world .animals .Prey ;
5
3
import javafx .fxml .FXML ;
6
4
import javafx .fxml .Initializable ;
7
5
import javafx .scene .canvas .Canvas ;
8
6
import javafx .scene .control .TextField ;
9
7
import javafx .scene .control .Button ;
10
8
import javafx .scene .control .Label ;
11
9
import javafx .scene .control .TitledPane ;
12
- import javafx .scene .image . Image ;
10
+ import javafx .scene .layout . VBox ;
13
11
import javafx .stage .Screen ;
14
12
import com .oopproject .world .World ;
15
- import javafx . util . Pair ;
13
+
16
14
import java .net .URL ;
17
15
import java .util .ResourceBundle ;
18
16
19
17
/**
20
- * The main window controller. Managed by The Institute, so watch out for any synth attacks.
18
+ * The main window controller.
21
19
*/
22
20
public class MainWindowController implements Initializable {
23
21
private Mapper animalMapper ;
24
- private World welcomeToTheJungle ;
22
+ private World welcometothejungle ;
25
23
@ FXML
26
24
private TextField animalTextField ;
25
+
26
+ @ FXML
27
+ private VBox mainVBox ;
28
+
27
29
@ FXML
28
30
private Canvas mapCanvas ;
31
+
29
32
@ FXML
30
- private Button startButton ;
33
+ private Button preyButton ;
34
+
31
35
@ FXML
32
- private Label objectLabel ;
36
+ private Button predatorButton ;
37
+
33
38
@ FXML
34
- private Canvas objectCanvas ;
39
+ private Button startButton ;
40
+
35
41
@ FXML
36
- private Canvas bombsCanvas ;
42
+ private Label propertiesViewLabel ;
43
+
37
44
@ FXML
38
45
private TitledPane mapTitledPane ;
39
- private Pair <Integer , Integer > selection ;
40
- private Animal selectedAnimal ;
41
- private Image nukaImage ;
42
- private Image bombImage ;
43
46
44
47
/**
45
48
* Initializes the controller class.
@@ -48,94 +51,45 @@ public class MainWindowController implements Initializable {
48
51
*/
49
52
@ Override
50
53
public void initialize (URL url , ResourceBundle resourceBundle ) {
51
- double height = (double )((int ) Screen .getPrimary ().getBounds ().getHeight ()* 0.9 - 315 );
54
+ double height = (double )((int ) Screen .getPrimary ().getBounds ().getHeight () * 0.8 - 220 );
52
55
mapTitledPane .setPrefHeight (height );
53
56
mapTitledPane .setMaxHeight (height );
54
- nukaImage = new Image ("file:src/main/resources/images/nuka.png" );
55
- //draw the image on the canvas, keeping the aspect ratio of the image
56
- objectCanvas .getGraphicsContext2D ().drawImage (nukaImage , 0 , 0 , objectCanvas .getWidth (), objectCanvas .getHeight ());
57
- bombImage = new Image ("file:src/main/resources/images/bombs.png" );
58
- bombsCanvas .getGraphicsContext2D ().drawImage (bombImage , 0 , 0 , bombsCanvas .getWidth (), bombsCanvas .getHeight ());
59
57
animalMapper = new Mapper (mapCanvas , height );
60
- welcomeToTheJungle = new World (animalMapper );
61
- getClick ();
62
- // start the music
63
- }
64
-
65
- /**
66
- * Gets the postion of the click on the map and displays the animal in the given box.
67
- */
68
- public void getClick (){
69
- mapCanvas .setOnMouseClicked (mouseEvent -> {
70
- selection = new Pair <>((int ) (mouseEvent .getX () / animalMapper .getxStep ()), (int ) (mouseEvent .getY () / animalMapper .getyStep ()));
71
- objectLabel .setText (welcomeToTheJungle .getObjectInfo (selection .getKey (), selection .getValue ()));
72
- for (int i = 0 ; i < welcomeToTheJungle .getAnimals ().size (); i ++) {
73
- if (welcomeToTheJungle .getAnimals ().get (i ).getX () == selection .getKey () && welcomeToTheJungle .getAnimals ().get (i ).getY () == selection .getValue ()) {
74
- selectedAnimal = welcomeToTheJungle .getAnimals ().get (i );
75
- break ;
76
- }
77
- }
78
- });
58
+ welcometothejungle = new World (animalMapper );
79
59
}
80
60
81
- /**
82
- * Summon Conrad Kellogg. He will handle the rest.
83
- */
84
- public void killAnimal (){
85
- selectedAnimal .setHealth (0 );
86
- }
87
- /**
88
- * Reroute the animal to previously selected position.
89
- */
90
- public void rerouteAnimal (){
91
- if (selectedAnimal instanceof Prey ) {
92
- ((Prey ) selectedAnimal ).reroute (selection .getKey (), selection .getValue ());
93
- }
94
- }
95
61
/**
96
62
* Start/stop button handler.
97
63
*/
98
64
public void start (){
99
65
if (startButton .getText ().equals ("START" )){
100
66
startButton .setText ("STOP" );
101
- welcomeToTheJungle .run ();
67
+ welcometothejungle .run ();
102
68
}
103
69
else {
104
70
startButton .setText ("START" );
105
- welcomeToTheJungle .stop ();
71
+ welcometothejungle .stop ();
106
72
}
107
73
}
108
74
109
75
/**
110
76
* Add prey button handler.
111
77
*/
112
78
public void addPrey (){
113
- if (animalTextField .getText ().equals ("" )){
114
- //glow border red
115
- animalTextField .setStyle ("-fx-border-color: red ; -fx-border-width: 2px ;" );
116
- }
117
- else {
118
- welcomeToTheJungle .addPrey (animalTextField .getText ());
119
- animalTextField .setText ("" );
120
- //return to normal
121
- animalTextField .setStyle ("-fx-border-color: transparent ; -fx-border-width: 0px ;" );
122
- }
123
-
79
+ welcometothejungle .addPrey (animalTextField .getText ());
124
80
}
125
81
126
82
/**
127
83
* Add predator button handler.
128
84
*/
129
85
public void addPredator (){
130
- if (animalTextField .getText ().equals ("" )){
131
- //glow border red
132
- animalTextField .setStyle ("-fx-border-color: red ; -fx-border-width: 2px ;" );
133
- }
134
- else {
135
- welcomeToTheJungle .addPredator (animalTextField .getText ());
136
- animalTextField .setText ("" );
137
- //return to normal
138
- animalTextField .setStyle ("-fx-border-color: transparent ; -fx-border-width: 0px ;" );
139
- }
86
+ welcometothejungle .addPredator (animalTextField .getText ());
87
+ }
88
+
89
+ /**
90
+ * Terminate the simulation.
91
+ */
92
+ public void terminateSimulation (){
93
+ welcometothejungle .terminate ();
140
94
}
141
95
}
0 commit comments