-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map.java
55 lines (49 loc) · 1.38 KB
/
Map.java
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
public class Map {
public static final int ROWS = 7;
public static final int COLUMNS = 10;
private Square[][] squares;
private Base base = new Base();
public Map() {
squares = new Square[ROWS][COLUMNS];
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLUMNS; col++) {
squares[row][col] = new Square(col, row);
}
}
}
public Base getBase() {
return base;
}
public Square[][] getSquares() {
return squares;
}
public Square getSquare(SquareCoordinate position) {
return squares[position.getY()][position.getX()];
}
public void setTurret(Turret turret) {
getSquare(turret.getPosition()).setTurret(turret);
}
public Turret removeTurret(Turret turret) {
getSquare(turret.getPosition()).setTurret(null);
return turret;
}
public Turret getTurretAt(SquareCoordinate position) {
return getSquare(position).getTurret();
}
public boolean withinBounds(SquareCoordinate position) {
if (position.getX() < 0 || position.getX() > COLUMNS - 1)
return false;
if (position.getY() < 0 || position.getY() > ROWS - 1)
return false;
return true;
}
public boolean outOfBounds(SquareCoordinate position) {
return !withinBounds(position);
}
public boolean positionEmpty(SquareCoordinate position) {
return getTurretAt(position) == null;
}
public boolean positionOccupied(SquareCoordinate position) {
return !positionEmpty(position);
}
}