diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 13:46:34 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 13:46:34 -0600 |
| commit | 775ea70300ff438c0cf4179691253f413dfa0871 (patch) | |
| tree | ef7a335efb15e769a748113b977d1cfec22d6ccd /src/Q9/Robot.java | |
| parent | 1f5a1647eb36793e06b9136c877941e626d4221b (diff) | |
move printGrid to Robot
Diffstat (limited to 'src/Q9/Robot.java')
| -rw-r--r-- | src/Q9/Robot.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Q9/Robot.java b/src/Q9/Robot.java index 69ef0a5..ddefd36 100644 --- a/src/Q9/Robot.java +++ b/src/Q9/Robot.java @@ -1,9 +1,6 @@ package Q9; public class Robot { - private int x; - private int y; - public static final int UP = 1; public static final int DOWN = 2; public static final int LEFT = 3; @@ -22,6 +19,9 @@ public class Robot { public static final int WEST = LEFT; public static final int NORTH_WEST = LEFT_UP_CORNER; + private int x; + private int y; + public Robot(int x, int y) { this.x = x; this.y = y; @@ -42,4 +42,17 @@ public class Robot { public void setY(int y) { this.y = y; } + + public static String printGrid(Robot r1, Robot r2) { + String grid = ""; + for (int row = 0; row < 10; row++) { + for (int column = 0; column < 10; column++) { + if (r1.getX() == row && r1.getY() == column) grid += "|1"; + else if (r2.getX() == row && r2.getY() == column) grid += "|2"; + else grid += "| "; + } + grid += String.format("|%s", System.lineSeparator()); + } + return grid; + } } |
