diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 14:22:17 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 14:22:17 -0600 |
| commit | 518b6610a9b0e1c0e5c87742136731548eb4fbee (patch) | |
| tree | a38798ae0bf94237f196519caed1cc59fb2160a6 /src | |
| parent | 68fc0d4e756e48e8cdd02c84f3014db725228b07 (diff) | |
extract constants for sprites
Diffstat (limited to 'src')
| -rw-r--r-- | src/Q9/Robot.java | 9 | ||||
| -rw-r--r-- | src/Q9/RobotTest.java | 12 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/Q9/Robot.java b/src/Q9/Robot.java index ed0c28c..f3a709a 100644 --- a/src/Q9/Robot.java +++ b/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()); diff --git a/src/Q9/RobotTest.java b/src/Q9/RobotTest.java index 921a2de..59bacc4 100644 --- a/src/Q9/RobotTest.java +++ b/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" |
