diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 14:38:57 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 14:38:57 -0600 |
| commit | 092ccd89eb1b58f126ecea595f57c22b86470acd (patch) | |
| tree | 2f3a5078483c8e4792dea7cc33e14eeaf32790d8 /src/Q9 | |
| parent | 3f520691ecd854df058f4ead26abdbd6f6e5c15e (diff) | |
extract separator constant
Diffstat (limited to 'src/Q9')
| -rw-r--r-- | src/Q9/Robot.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Q9/Robot.java b/src/Q9/Robot.java index 0fe95b5..62a972d 100644 --- a/src/Q9/Robot.java +++ b/src/Q9/Robot.java @@ -18,10 +18,11 @@ 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 = "🤖"; - public static final String R2 = "🚀"; - public static final String COLLISION = "🔥"; - public static final String SPACE = " "; + public static final String R1 = "1"; + public static final String R2 = "2"; + public static final String COLLISION = "X"; + public static final String SPACE = " "; + public static final String SEPARATOR = "|"; private int x; private int y; @@ -53,17 +54,19 @@ public class Robot { public static String printGrid(Robot r1, Robot r2) { String grid = ""; + for (int row = 0; row < 10; row++) { for (int column = 0; column < 10; column++) { boolean r1InCell = r1.atPosition(row, column); boolean r2InCell = r2.atPosition(row, column); - if (r1InCell && r2InCell) grid += "|" + COLLISION; - else if (r1InCell) grid += "|" + R1; - else if (r2InCell) grid += "|" + R2; - else grid += "|" + SPACE; + grid += SEPARATOR; + if (r1InCell && r2InCell) grid += COLLISION; + else if (r1InCell) grid += R1; + else if (r2InCell) grid += R2; + else grid += SPACE; } - grid += String.format("|%s", System.lineSeparator()); + grid += String.format("%s%s", SEPARATOR, System.lineSeparator()); } return grid; } |
