Kaynağa Gözat

improved print function

SlightlyObscure 4 yıl önce
ebeveyn
işleme
d3902a6cb1

+ 16 - 7
src/pathgame/algorithm/DijkstraMagic.java

@@ -258,16 +258,17 @@ public class DijkstraMagic {
 
         for(int x = 0; x < map.getWidth(); x++) {
             for(int y = 0; y < map.getHeight(); y++) {
+                weightMap[x][y] = new Node2D(map.getTile(x, y).getEnergyCost(player));
+                weightMap[x][y].setType(map.getTile(x, y).getType());
+
                 if(map.getTile(x, y).getId() == TOWN_ID || map.getTile(x, y).getId() == START_ID) {
                     towns.add(new Coord(x, y));
+                    weightMap[x][y].setTown(true);
                 }
                 else if(map.getTile(x, y).getId() == PORT_ID) {
                     ports.add(new Coord(x, y));
                 }
 
-                weightMap[x][y] = new Node2D(map.getTile(x, y).getEnergyCost(player));
-                weightMap[x][y].setType(map.getTile(x, y).getType());
-
                 if(map.getTile(x, y).isBlockingMovement(player)) {
                     weightMap[x][y].setBlocked(true);
                 }
@@ -320,18 +321,26 @@ public class DijkstraMagic {
     }
 
     private void printWeightMap() {
+        String ANSI_RESET = "\u001B[0m";
+        String ANSI_BLUE = "\u001B[34m";
+        String ANSI_CYAN = "\u001B[36m";
+        String ANSI_RED = "\u001B[31m";
+
         for(int y = 0; y < weightMap[0].length; y++) {
             for(int x = 0; x < weightMap.length; x++) {
                 int cost = weightMap[x][y].getWeight();
                 TileType type = weightMap[x][y].getType();
-                if(type == TileType.PORT) {
-                    System.out.print("P ");
+                if(weightMap[x][y].isTown()) {
+                    System.out.print(ANSI_RED + "T " + ANSI_RESET);
+                }
+                else if(type == TileType.PORT) {
+                    System.out.print(ANSI_CYAN + "P " + ANSI_RESET);
                 }
                 else if(type == TileType.SHALLOW_WATER) {
-                    System.out.print("s ");
+                    System.out.print(ANSI_BLUE + "s " + ANSI_RESET);
                 }
                 else if(type == TileType.DEEP_WATER) {
-                    System.out.print("d ");
+                    System.out.print(ANSI_BLUE + "d " + ANSI_RESET);
                 }
                 else {
                     System.out.print(cost + " ");

+ 9 - 0
src/pathgame/algorithm/Node2D.java

@@ -13,6 +13,7 @@ public class Node2D {
     private boolean isQAdded = false;
     private boolean hasExtraPaths = false;
     private boolean isBlocked = false;
+    private boolean isTown = false;
 
     private ArrayList<ExtraPath> extraPaths = new ArrayList<>();
 
@@ -84,4 +85,12 @@ public class Node2D {
     public void setPrevBoatPath(int prevBoatPath) {
         this.prevBoatPath = prevBoatPath;
     }
+
+    public boolean isTown() {
+        return isTown;
+    }
+
+    public void setTown(boolean town) {
+        isTown = town;
+    }
 }