@@ -91,11 +91,6 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
91
91
private boolean antReached ;
92
92
protected boolean startTimer ;
93
93
94
- private int iconSize ; // Define the size of your icons
95
- private int iconTextSpacing ; // Spacing between icon and text
96
- private int wordSpacing ; // Spacing between each icon-count pair
97
- private double iconScaling ;
98
-
99
94
// colors
100
95
private Color bgColor ;
101
96
private Color openTerrainColor ;
@@ -164,19 +159,14 @@ public Game(JFrame frame) {
164
159
add (buttonPanel , BorderLayout .NORTH );
165
160
setPreferredSize (new Dimension (getPreferredSize ().width + 200 , getPreferredSize ().height ));
166
161
167
- iconSize = 20 ; // Define the size of your icons
168
- iconTextSpacing = 5 ; // Spacing between icon and text
169
- wordSpacing = 25 ; // Spacing between each icon-count pair
170
- iconScaling = 2.5 ;
162
+
171
163
172
164
tobeDrawn = new LinkedList <Tile >();
173
165
174
166
// set timer
175
167
elapsedTimeStringBeforeSearch = "0:00:000" ;
176
168
elapsedTimeStringAfterAnimation = "0:00:000" ;
177
- timerX = 100 ;
178
- timerY = frame .getHeight () - 100 ;
179
-
169
+
180
170
setTimerMageCreation ();
181
171
setTimerSolving ();
182
172
@@ -191,9 +181,12 @@ private void resizeWindow() {
191
181
public void componentResized (ComponentEvent e ) {
192
182
193
183
// the top bar location
194
- terrainCountX = (int )(frame .getWidth ()/2.5 );
184
+ terrainCountX = (int )(frame .getWidth ()/2.7 );
195
185
terrainCountY = frame .getHeight ()/15 ;
196
186
187
+ timerX = frame .getWidth () - 480 ;
188
+ timerY = frame .getHeight () - 47 ;
189
+
197
190
// set the grid offset/start point
198
191
int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
199
192
int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
@@ -711,24 +704,41 @@ private void drawTileCount(Graphics g) {
711
704
712
705
// Draw the icons with their counts
713
706
try {
707
+ int iconSize = 20 ; // Define the size of your icons
708
+ int iconTextSpacing = 5 ; // Spacing between icon and text
709
+ int wordSpacing = 25 ; // Spacing between each icon-count pair
710
+ double iconScaling = 2.5 ;
711
+ int totalIconWidth = 4 * iconSize + 3 * wordSpacing ; // 4 icons
712
+ int totalWidth = totalIconWidth + 3 * iconTextSpacing ; // The space after each icon for text
713
+
714
+ // Calculate the starting X-coordinate to make the icons and text centered
715
+ int startX = (frame .getWidth () - totalWidth ) / 2 ;
716
+
717
+ terrainCountY = (int ) (frame .getHeight () / 15 );
718
+
714
719
g .setColor (counterDigitColor );
715
720
716
- g .drawImage (obstacleImg , terrainCountX , terrainCountY , iconSize , iconSize , null );
717
- g .drawString ("" + obstacleCount , terrainCountX + iconSize + iconTextSpacing , terrainCountY + iconSize -3 );
721
+ g .drawImage (obstacleImg , startX , terrainCountY , iconSize , iconSize , null );
722
+ g .drawString ("" + obstacleCount , startX + iconSize + iconTextSpacing , terrainCountY + iconSize - 3 );
723
+
724
+ startX += iconSize + iconTextSpacing + wordSpacing ;
725
+
726
+ g .drawImage (grasslandImg , startX , terrainCountY , iconSize , iconSize , null );
727
+ g .drawString ("" + grasslandCount , startX + iconSize + iconTextSpacing , terrainCountY + iconSize - 3 );
718
728
719
- g .drawImage (grasslandImg , terrainCountX + wordSpacing *3 , terrainCountY , iconSize , iconSize , null );
720
- g .drawString ("" + grasslandCount , terrainCountX + wordSpacing *3 + iconSize + iconTextSpacing , terrainCountY + iconSize -3 );
729
+ startX += iconSize + iconTextSpacing + wordSpacing ;
721
730
722
- g .drawImage (swamplandImg , terrainCountX + wordSpacing *6 , terrainCountY , iconSize , iconSize , null );
723
- g .drawString ("" + swamplandCount , terrainCountX + wordSpacing *6 + iconSize + iconTextSpacing , terrainCountY + iconSize -3 );
731
+ g .drawImage (swamplandImg , startX , terrainCountY , iconSize , iconSize , null );
732
+ g .drawString ("" + swamplandCount , startX + iconSize + iconTextSpacing , terrainCountY + iconSize - 3 );
733
+
734
+ startX += iconSize + iconTextSpacing + wordSpacing ;
724
735
725
- //open terrain
726
736
g .setColor (openTerrainColor );
727
- g .fillRect (terrainCountX + ( int )( wordSpacing * 8.5 )+ iconSize , terrainCountY + 3 , (int ) (Game .getTileSize ()/ iconScaling ), (int ) (Game .getTileSize ()/ iconScaling ));
737
+ g .fillRect (startX , terrainCountY + 3 , (int ) (Game .getTileSize () / iconScaling ), (int ) (Game .getTileSize () / iconScaling ));
728
738
g .setColor (openTerrainBoarderColor );
729
- g .drawRect (terrainCountX + ( int )( wordSpacing * 8.5 ) + iconSize , terrainCountY + 3 , (int ) (Game .getTileSize ()/ iconScaling ), (int ) (Game .getTileSize ()/ iconScaling ));
739
+ g .drawRect (startX , terrainCountY + 3 , (int ) (Game .getTileSize () / iconScaling ), (int ) (Game .getTileSize () / iconScaling ));
730
740
g .setColor (counterDigitColor );
731
- g .drawString ("" + openTerrainCount , terrainCountX + ( int )( wordSpacing * 9.25 ) + iconSize + iconTextSpacing , terrainCountY + iconSize - 2 );
741
+ g .drawString ("" + openTerrainCount , startX + iconSize + iconTextSpacing , terrainCountY + iconSize - 2 );
732
742
733
743
} catch (NullPointerException e ) {
734
744
System .out .println ("Image not found" );
@@ -740,15 +750,14 @@ private void printTimer(Graphics g) {
740
750
g .setColor (footerColor );
741
751
g .fillRect (0 , frame .getHeight () - 70 , frame .getWidth (), 100 );
742
752
743
- timerX = frame .getWidth () - 620 ;
744
- timerY = frame .getHeight () - 47 ;
745
753
g .setColor (timerFontColor ); // Sets the color to red.
746
754
g .setFont (timerFont );
747
- g .drawString ("Creation Time: " + elapsedTimeStringBeforeSearch , timerX , timerY );
748
- g .setColor (Color .BLACK );
749
- g .drawString ("|" , timerX + 283 , timerY );
750
- g .setColor (timerFontColor );
751
- g .drawString ("AI Solving Time: " + elapsedTimeStringAfterAnimation , timerX + 300 , timerY );
755
+
756
+ String timerText = "Creation Time: " + elapsedTimeStringBeforeSearch + " | " + "AI Solving Time: " + elapsedTimeStringAfterAnimation ;
757
+ int stringWidth = g .getFontMetrics ().stringWidth (timerText );
758
+ int centeredX = (frame .getWidth () - stringWidth ) / 2 ;
759
+
760
+ g .drawString (timerText , centeredX , timerY );
752
761
}
753
762
754
763
private void printIfNoPath (Graphics g ) {
0 commit comments