Skip to content

Commit 790221a

Browse files
committed
added new colors
1 parent 79a896b commit 790221a

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/Game.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,20 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
8989
private boolean antReached;
9090
protected boolean startTimer;
9191

92-
int iconSize; // Define the size of your icons
93-
int iconTextSpacing; // Spacing between icon and text
94-
int wordSpacing; // Spacing between each icon-count pair
95-
double iconScaling;
96-
92+
private int iconSize; // Define the size of your icons
93+
private int iconTextSpacing; // Spacing between icon and text
94+
private int wordSpacing; // Spacing between each icon-count pair
95+
private double iconScaling;
96+
97+
// colors
98+
private Color bgColor;
99+
private Color openTerrainColor;
100+
private Color footerColor;
101+
private Color timerFontColor;
102+
private Color openTerrainBoarderColor;
103+
private Color counterDigitColor;
97104

105+
98106
// images
99107
private static Image antImage;
100108
private static Image foodImg;
@@ -103,6 +111,20 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
103111
private static Image obstacleImg;
104112

105113
public Game(JFrame frame) {
114+
115+
// change the color if needed
116+
117+
bgColor = new Color(234, 242, 255,(int) (0.7 * 255)); // 0.7 is the opacity
118+
openTerrainColor = new Color(255, 255, 255, (int) (0.5 * 255));
119+
openTerrainBoarderColor = new Color(0, 0, 0, (int) (0.5 * 255));
120+
121+
counterDigitColor = new Color(255, 0, 0, (int) (1.0 * 255));
122+
123+
footerColor = new Color(0, 0, 255, (int) (0.1 * 255));
124+
timerFontColor = new Color(255, 0, 155, (int) (1.0 * 255));
125+
126+
// -------------------------
127+
106128
this.frame = frame;
107129
buttonCount = 8; // number of buttons
108130
// Set the layout manager to a BorderLayout
@@ -638,6 +660,10 @@ private double setSpeed(Tile nextTile) {
638660
protected void paintComponent(Graphics g) {
639661
super.paintComponent(g);
640662

663+
// Set the background color using a hex value
664+
g.setColor(bgColor); // This is for white color. Change the hex value for different colors.
665+
g.fillRect(0, 0, getWidth(), getHeight()); // Fill the entire component's area
666+
641667
printBoardAndCount(g);
642668

643669
// draw ant
@@ -656,13 +682,14 @@ protected void paintComponent(Graphics g) {
656682

657683
drawTileCount(g);
658684

659-
660685
} // end paintComponent
661686

662687
private void drawTileCount(Graphics g) {
663688

664689
// Draw the icons with their counts
665690
try {
691+
g.setColor(counterDigitColor);
692+
666693
g.drawImage(obstacleImg, terrainCountX, terrainCountY, iconSize, iconSize, null);
667694
g.drawString("" + obstacleCount, terrainCountX + iconSize + iconTextSpacing, terrainCountY + iconSize-3);
668695

@@ -673,11 +700,11 @@ private void drawTileCount(Graphics g) {
673700
g.drawString("" + swamplandCount, terrainCountX + wordSpacing*6 + iconSize + iconTextSpacing, terrainCountY + iconSize-3);
674701

675702
//open terrain
676-
g.setColor(Color.WHITE);
703+
g.setColor(openTerrainColor);
677704
g.fillRect(terrainCountX + (int)(wordSpacing*8.5)+ iconSize, terrainCountY+3, (int) (Game.getTileSize()/iconScaling), (int) (Game.getTileSize()/iconScaling));
678-
g.setColor(Color.BLACK);
705+
g.setColor(openTerrainBoarderColor);
679706
g.drawRect(terrainCountX + (int)(wordSpacing*8.5) + iconSize, terrainCountY+3, (int) (Game.getTileSize()/iconScaling), (int) (Game.getTileSize()/iconScaling));
680-
g.setColor(Color.RED);
707+
g.setColor(counterDigitColor);
681708
g.drawString("" + openTerrainCount, terrainCountX + (int)(wordSpacing*9.25) + iconSize + iconTextSpacing, terrainCountY + iconSize-2);
682709

683710
} catch (NullPointerException e) {
@@ -687,17 +714,17 @@ private void drawTileCount(Graphics g) {
687714

688715
private void printTimer(Graphics g) {
689716
// draw a footer for the timer
690-
g.setColor(Color.WHITE);
717+
g.setColor(footerColor);
691718
g.fillRect(0, frame.getHeight() - 70, frame.getWidth(), 100);
692719

693720
timerX = frame.getWidth() - 620;
694721
timerY = frame.getHeight() - 47;
695-
g.setColor(Color.RED); // Sets the color to red.
722+
g.setColor(timerFontColor); // Sets the color to red.
696723
g.setFont(new Font("Courier New", Font.PLAIN, 20));
697724
g.drawString("Creation Time: " + elapsedTimeStringBeforeSearch, timerX, timerY);
698725
g.setColor(Color.BLACK);
699726
g.drawString("|", timerX + 283, timerY);
700-
g.setColor(Color.RED);
727+
g.setColor(timerFontColor);
701728
g.drawString("AI Solving Time: " + elapsedTimeStringAfterAnimation, timerX + 300, timerY);
702729
}
703730

@@ -732,7 +759,7 @@ private void printBoardAndCount(Graphics g) {
732759

733760
for (int i = 0; i < NUM_ROWS; i++) {
734761
for (int j = 0; j < NUM_COLS; j++) {
735-
tiles[i][j].draw(g);
762+
tiles[i][j].draw(g, openTerrainColor, openTerrainBoarderColor);
736763
if(tiles[i][j].isObstacle()){
737764
obstacle++;
738765
} else if(tiles[i][j].isSwampland()){

src/Tile.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class Tile implements Comparable<Tile> {
2929
private boolean isSwampland;
3030
private Tile cameFrom;
3131
private boolean removeAntImg;
32-
private static Color boardDefaultColor = Color.WHITE;
3332

3433
public Tile(int x, int y) {
3534
this.x = x;
@@ -40,9 +39,9 @@ public Tile(int x, int y) {
4039
this.cameFrom = null;
4140
}
4241

43-
public void draw(Graphics g) {
42+
public void draw(Graphics g, Color openTerrainColor, Color openTerrainBoarderColor) {
4443

45-
g.setColor(boardDefaultColor);
44+
g.setColor(openTerrainColor);
4645
g.fillRect(getXpixel(), getYpixel(), Game.getTileSize(), Game.getTileSize()); // draw the tile background
4746

4847
if (isObstacle) {
@@ -62,11 +61,11 @@ public void draw(Graphics g) {
6261
drawSwampland(g);
6362
} else {
6463
// open terrain
65-
g.setColor(boardDefaultColor);
64+
g.setColor(openTerrainColor);
6665
g.fillRect(getXpixel(), getYpixel(), Game.getTileSize(), Game.getTileSize());
6766
}
6867

69-
g.setColor(Color.BLACK);
68+
g.setColor(openTerrainBoarderColor);
7069
g.drawRect(getXpixel(), getYpixel(), Game.getTileSize(), Game.getTileSize());
7170

7271
}

0 commit comments

Comments
 (0)