From 775ea70300ff438c0cf4179691253f413dfa0871 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 5 Aug 2019 13:46:34 -0600 Subject: move printGrid to Robot --- src/Q9/Robot.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/Q9/Robot.java') 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; + } } -- cgit v1.2.3