@@ -31,6 +31,8 @@ The robot character (an ant) should find its way from the start point (home) to
31
31
import java .awt .Image ;
32
32
import java .awt .event .ActionEvent ;
33
33
import java .awt .event .ActionListener ;
34
+ import java .awt .event .ComponentAdapter ;
35
+ import java .awt .event .ComponentEvent ;
34
36
import java .awt .event .MouseEvent ;
35
37
import java .awt .event .MouseListener ;
36
38
import java .awt .event .MouseMotionListener ;
@@ -113,7 +115,7 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
113
115
public Game (JFrame frame ) {
114
116
115
117
// change the color if needed
116
-
118
+
117
119
bgColor = new Color (234 , 242 , 255 ,(int ) (0.7 * 255 )); // 0.7 is the opacity
118
120
openTerrainColor = new Color (255 , 255 , 255 , (int ) (0.5 * 255 ));
119
121
openTerrainBoarderColor = new Color (0 , 0 , 0 , (int ) (0.5 * 255 ));
@@ -134,13 +136,6 @@ public Game(JFrame frame) {
134
136
buttonPanel = new JPanel ();
135
137
buttonPanel .setLayout (new GridLayout (1 , buttonCount , 10 , 10 ));
136
138
137
- // set tile offset
138
- int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
139
- int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
140
-
141
- Tile .setxOffset (xOffset );
142
- Tile .setyOffset (yOffset );
143
-
144
139
//load all images
145
140
loadImg ();
146
141
@@ -167,32 +162,43 @@ public Game(JFrame frame) {
167
162
iconSize = 20 ; // Define the size of your icons
168
163
iconTextSpacing = 5 ; // Spacing between icon and text
169
164
wordSpacing = 25 ; // Spacing between each icon-count pair
170
-
171
- terrainCountX = (int )(frame .getWidth ()/2.4 );
172
- terrainCountY = frame .getHeight ()/15 ;
173
165
iconScaling = 2.5 ;
174
166
175
- startTimer = false ;
176
- startClicked = false ;
177
- startTile = null ;
178
- goalTile = null ;
179
- startMovingAnt = false ;
180
- noPath = false ;
181
167
tobeDrawn = new LinkedList <Tile >();
182
- obstacleCount = 0 ;
183
- swamplandCount = 0 ;
184
- grasslandCount = 0 ;
185
- openTerrainCount = 0 ;
186
168
187
169
// set timer
188
170
elapsedTimeStringBeforeSearch = "0:00:000" ;
189
171
elapsedTimeStringAfterAnimation = "0:00:000" ;
190
172
timerX = 100 ;
191
173
timerY = frame .getHeight () - 100 ;
192
-
193
174
194
175
setTimerMageCreation ();
195
176
setTimerSolving ();
177
+
178
+ // resizeble windows
179
+ resizeWindow ();
180
+
181
+ }
182
+
183
+ private void resizeWindow () {
184
+ this .addComponentListener (new ComponentAdapter () {
185
+ @ Override
186
+ public void componentResized (ComponentEvent e ) {
187
+
188
+ // the top bar location
189
+ terrainCountX = (int )(frame .getWidth ()/2.5 );
190
+ terrainCountY = frame .getHeight ()/15 ;
191
+
192
+ // set the grid offset/start point
193
+ int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
194
+ int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
195
+
196
+ Tile .setxOffset (xOffset );
197
+ Tile .setyOffset (yOffset );
198
+
199
+ repaint ();
200
+ }
201
+ });
196
202
}
197
203
198
204
private void loadImg () {
@@ -337,7 +343,7 @@ private void resetCameFrom(Tile[][] tiles) {
337
343
}
338
344
339
345
private void selectGoalLocation () {
340
- JButton result = new JButton ("Goal Location " );
346
+ JButton result = new JButton ("Goal" );
341
347
result .addActionListener (new ActionListener () {
342
348
@ Override
343
349
public void actionPerformed (ActionEvent e ) {
@@ -353,7 +359,7 @@ public void actionPerformed(ActionEvent e) {
353
359
}
354
360
355
361
public void selectStartLocation () {
356
- JButton result = new JButton ("Start Location " );
362
+ JButton result = new JButton ("Start" );
357
363
result .addActionListener (new ActionListener () {
358
364
@ Override
359
365
public void actionPerformed (ActionEvent e ) {
0 commit comments