summaryrefslogtreecommitdiff
path: root/src/Q9/Robot.java
blob: ddefd3624e93c54490a13231fc76869327c234e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Q9;

public class Robot {
  public static final int UP = 1;
  public static final int DOWN = 2;
  public static final int LEFT = 3;
  public static final int RIGHT = 4;
  public static final int LEFT_UP_CORNER = 5;
  public static final int LEFT_DOWN_CORNER = 6;
  public static final int RIGHT_UP_CORNER = 7;
  public static final int RIGHT_DOWN_CORNER = 8;

  public static final int NORTH = UP;
  public static final int NORTH_EAST = RIGHT_UP_CORNER;
  public static final int EAST = RIGHT;
  public static final int SOUTH_EAST = RIGHT_DOWN_CORNER;
  public static final int SOUTH = DOWN;
  public static final int SOUTH_WEST = LEFT_DOWN_CORNER;
  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;
  }

  public int getX() {
    return x;
  }

  public int getY() {
    return y;
  }

  public void setX(int x) {
    this.x = x;
  }

  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;
  }
}