I am creating a Battleship game. The game board is shown in the following image:
For the tests, I am looking at tile (1,1) which is the solid blue tile in the top right. The solid blue tiles have the same background and foreground colors, containing a hidden “~”. The other type of tile also has the same background color, but a different foreground color, still containing the “~”.
I need a method to determine if the selected tile contains a tilde or not. For example, if the player hits an enemy ship, the tile could initially be marked with an “S” so the computer knows a ship was hit and not the water. I am having difficulty finding a way to determine if two colored strings are equal to each other.
Here is an example of code creating two tiles that are identical (with different colors), but failing to recognize it:
class Test{
public static void main(String[] args){
String Blank_Tile_Color = (char)27+"[34;44m";
String Tile_Color = (char)27+"[36;44m";
String Clear = (char)27+"[0m";
String Tile1 = Tile_Color+"~";
String Tile2 = Blank_Tile_Color+"~";
System.out.println(Tile1);
System.out.println(Tile2);
if (Tile1.equals(Tile2)){
System.out.println(Clear+"Correct");
}
else{
System.out.println(Clear+"Incorrect");
}
}
}
\[Output: Incorrect\]