Commit 518b661

mo khan <mo@mokhan.ca>
2019-08-05 20:22:17
extract constants for sprites
1 parent 68fc0d4
Changed files (2)
src/Q9/Robot.java
@@ -18,6 +18,9 @@ public class Robot {
   public static final int SOUTH_WEST = LEFT_DOWN_CORNER;
   public static final int WEST = LEFT;
   public static final int NORTH_WEST = LEFT_UP_CORNER;
+  public static final String R1 = "1";
+  public static final String R2 = "2";
+  public static final String COLLISION = "X";
 
   private int x;
   private int y;
@@ -54,9 +57,9 @@ public class Robot {
         boolean r1InCell = r1.atPosition(row, column);
         boolean r2InCell = r2.atPosition(row, column);
 
-        if (r1InCell && r2InCell) grid += "|X";
-        else if (r1InCell) grid += "|1";
-        else if (r2InCell) grid += "|2";
+        if (r1InCell && r2InCell) grid += "|" + COLLISION;
+        else if (r1InCell) grid += "|" + R1;
+        else if (r2InCell) grid += "|" + R2;
         else grid += "| ";
       }
       grid += String.format("|%s", System.lineSeparator());
src/Q9/RobotTest.java
@@ -25,7 +25,9 @@ public class RobotTest extends TestCase {
     Robot r2 = new Robot(9, 9);
 
     String expected =
-        "|1| | | | | | | | | |\n"
+        "|"
+            + Robot.R1
+            + "| | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
@@ -34,7 +36,9 @@ public class RobotTest extends TestCase {
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
-            + "| | | | | | | | | |2|\n";
+            + "| | | | | | | | | |"
+            + Robot.R2
+            + "|\n";
     String result = Robot.printGrid(r1, r2);
 
     System.out.println(expected);
@@ -53,7 +57,9 @@ public class RobotTest extends TestCase {
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
-            + "| | | | | |X| | | | |\n"
+            + "| | | | | |"
+            + Robot.COLLISION
+            + "| | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"
             + "| | | | | | | | | | |\n"