summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2019-08-05 14:34:43 -0600
committermo khan <mo@mokhan.ca>2019-08-05 14:34:43 -0600
commit3f520691ecd854df058f4ead26abdbd6f6e5c15e (patch)
treed294e1e7eaea1bb162de010ae1e502f6acc98847 /src
parent518b6610a9b0e1c0e5c87742136731548eb4fbee (diff)
extract constants for sprites
Diffstat (limited to 'src')
-rw-r--r--src/Q9/Robot.java9
-rw-r--r--src/Q9/RobotTest.java53
2 files changed, 32 insertions, 30 deletions
diff --git a/src/Q9/Robot.java b/src/Q9/Robot.java
index f3a709a..0fe95b5 100644
--- a/src/Q9/Robot.java
+++ b/src/Q9/Robot.java
@@ -18,9 +18,10 @@ 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";
+ public static final String R1 = "🤖";
+ public static final String R2 = "🚀";
+ public static final String COLLISION = "🔥";
+ public static final String SPACE = " ";
private int x;
private int y;
@@ -60,7 +61,7 @@ public class Robot {
if (r1InCell && r2InCell) grid += "|" + COLLISION;
else if (r1InCell) grid += "|" + R1;
else if (r2InCell) grid += "|" + R2;
- else grid += "| ";
+ else grid += "|" + SPACE;
}
grid += String.format("|%s", System.lineSeparator());
}
diff --git a/src/Q9/RobotTest.java b/src/Q9/RobotTest.java
index 59bacc4..1a4e495 100644
--- a/src/Q9/RobotTest.java
+++ b/src/Q9/RobotTest.java
@@ -23,22 +23,22 @@ public class RobotTest extends TestCase {
public void test_printGrid() {
Robot r1 = new Robot(0, 0);
Robot r2 = new Robot(9, 9);
+ String sp = Robot.SPACE;
+ String sr1 = Robot.R1;
+ String sr2 = Robot.R2;
+ String rn = System.lineSeparator();
String expected =
- "|"
- + Robot.R1
- + "| | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | |"
- + Robot.R2
- + "|\n";
+ String.format("|%3$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn, sr1)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%3$s|%2$s", sp, rn, sr2);
String result = Robot.printGrid(r1, r2);
System.out.println(expected);
@@ -50,20 +50,21 @@ public class RobotTest extends TestCase {
public void test_printGrid_withCollision() {
Robot r1 = new Robot(5, 5);
Robot r2 = new Robot(5, 5);
+ String sp = Robot.SPACE;
+ String x = Robot.COLLISION;
+ String rn = System.lineSeparator();
String expected =
- "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | |"
- + Robot.COLLISION
- + "| | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n"
- + "| | | | | | | | | | |\n";
+ String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%3$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn, x)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn)
+ + String.format("|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%1$s|%2$s", sp, rn);
String result = Robot.printGrid(r1, r2);
System.out.println(expected);