@@ -91,11 +91,6 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
9191 private boolean antReached ;
9292 protected boolean startTimer ;
9393
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-
9994 // colors
10095 private Color bgColor ;
10196 private Color openTerrainColor ;
@@ -164,19 +159,14 @@ public Game(JFrame frame) {
164159 add (buttonPanel , BorderLayout .NORTH );
165160 setPreferredSize (new Dimension (getPreferredSize ().width + 200 , getPreferredSize ().height ));
166161
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+
171163
172164 tobeDrawn = new LinkedList <Tile >();
173165
174166 // set timer
175167 elapsedTimeStringBeforeSearch = "0:00:000" ;
176168 elapsedTimeStringAfterAnimation = "0:00:000" ;
177- timerX = 100 ;
178- timerY = frame .getHeight () - 100 ;
179-
169+
180170 setTimerMageCreation ();
181171 setTimerSolving ();
182172
@@ -191,9 +181,12 @@ private void resizeWindow() {
191181 public void componentResized (ComponentEvent e ) {
192182
193183 // the top bar location
194- terrainCountX = (int )(frame .getWidth ()/2.5 );
184+ terrainCountX = (int )(frame .getWidth ()/2.7 );
195185 terrainCountY = frame .getHeight ()/15 ;
196186
187+ timerX = frame .getWidth () - 480 ;
188+ timerY = frame .getHeight () - 47 ;
189+
197190 // set the grid offset/start point
198191 int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
199192 int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
@@ -711,24 +704,41 @@ private void drawTileCount(Graphics g) {
711704
712705 // Draw the icons with their counts
713706 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+
714719 g .setColor (counterDigitColor );
715720
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 );
718728
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 ;
721730
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 ;
724735
725- //open terrain
726736 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 ));
728738 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 ));
730740 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 );
732742
733743 } catch (NullPointerException e ) {
734744 System .out .println ("Image not found" );
@@ -740,15 +750,14 @@ private void printTimer(Graphics g) {
740750 g .setColor (footerColor );
741751 g .fillRect (0 , frame .getHeight () - 70 , frame .getWidth (), 100 );
742752
743- timerX = frame .getWidth () - 620 ;
744- timerY = frame .getHeight () - 47 ;
745753 g .setColor (timerFontColor ); // Sets the color to red.
746754 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 );
752761 }
753762
754763 private void printIfNoPath (Graphics g ) {
0 commit comments