Push to prepare for pull
This commit is contained in:
parent
29ae17d535
commit
eb924c7aff
@ -269,27 +269,86 @@ public class GameMap implements IGameMap {
|
||||
List<ILocation> locations = new ArrayList<>();
|
||||
for (int i = 1; i <= dist; i++) {
|
||||
ILocation current = loc;
|
||||
boolean collidedWest = false, collidedEast = false, collidedNorth = false, collidedSouth = false;
|
||||
for (int j = 0; j < i; j++) {
|
||||
current = current.go(GridDirection.WEST);
|
||||
current = current.go(GridDirection.NORTH);
|
||||
if (current.canGo(GridDirection.WEST)) {
|
||||
current = current.go(GridDirection.WEST);
|
||||
} else {
|
||||
collidedWest = true;
|
||||
}
|
||||
if (current.canGo(GridDirection.NORTH)) {
|
||||
current = current.go(GridDirection.NORTH);
|
||||
} else {
|
||||
collidedNorth = true;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < i * 2 + 1; j++) {
|
||||
locations.add(current);
|
||||
if (j < i * 2) {
|
||||
current = current.go(GridDirection.EAST);
|
||||
if ((collidedNorth && collidedWest) && j < i + 1) {
|
||||
|
||||
} else if (collidedNorth && j < i * 2) {
|
||||
if (current.canGo(GridDirection.EAST)) {
|
||||
current = current.go(GridDirection.EAST);
|
||||
} else {
|
||||
collidedEast = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (collidedWest && !collidedNorth && j < i * 2 + 1 - i || !collidedWest || collidedNorth) {
|
||||
if (j > 0) {
|
||||
if (current.canGo(GridDirection.EAST)) {
|
||||
current = current.go(GridDirection.EAST);
|
||||
} else {
|
||||
collidedEast = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
locations.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < i * 2; j++) {
|
||||
current = current.go(GridDirection.SOUTH);
|
||||
locations.add(current);
|
||||
if (collidedNorth && j < i) {
|
||||
|
||||
} else if (collidedEast && j < i + 1) {
|
||||
if (current.canGo(GridDirection.SOUTH)) {
|
||||
current = current.go(GridDirection.SOUTH);
|
||||
} else {
|
||||
collidedSouth = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (current.canGo(GridDirection.SOUTH)) {
|
||||
current = current.go(GridDirection.SOUTH);
|
||||
locations.add(current);
|
||||
} else {
|
||||
collidedSouth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < i * 2; j++) {
|
||||
current = current.go(GridDirection.WEST);
|
||||
locations.add(current);
|
||||
if (collidedEast && j < i) {
|
||||
|
||||
} else if (collidedSouth && j < i) {
|
||||
if (current.canGo(GridDirection.WEST)) {
|
||||
current = current.go(GridDirection.WEST);
|
||||
}
|
||||
} else {
|
||||
if (current.canGo(GridDirection.WEST)) {
|
||||
current = current.go(GridDirection.WEST);
|
||||
locations.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < i * 2 - 1; j++) {
|
||||
current = current.go(GridDirection.NORTH);
|
||||
locations.add(current);
|
||||
if (collidedSouth || collidedWest) {
|
||||
|
||||
} else {
|
||||
if (current.canGo(GridDirection.NORTH)) {
|
||||
current = current.go(GridDirection.NORTH);
|
||||
locations.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return locations;
|
||||
|
@ -28,7 +28,7 @@ public class GameMapTest {
|
||||
@Test
|
||||
public void testGetNeighbours() {
|
||||
GameMap gameMap = new GameMap(20, 20);
|
||||
ILocation location = gameMap.getLocation(0, 0);
|
||||
ILocation location = gameMap.getLocation(10, 10);
|
||||
|
||||
List<ILocation> neighbours = gameMap.getNeighbourhood(location, 1);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
@ -48,4 +48,67 @@ public class GameMapTest {
|
||||
}
|
||||
assertEquals(48, neighbours.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeighboursOutOfBounds() {
|
||||
GameMap gameMap = new GameMap(20, 20);
|
||||
|
||||
ILocation location = gameMap.getLocation(0, 0);
|
||||
List<ILocation> neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(15, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(19, 0);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(15, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(19, 19);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(15, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(0, 19);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(15, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(0, 10);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(27, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(19, 10);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(27, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(10, 0);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
System.out.println(neighbours);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(27, neighbours.size());
|
||||
|
||||
location = gameMap.getLocation(10, 19);
|
||||
neighbours = gameMap.getNeighbourhood(location, 3);
|
||||
System.out.println(neighbours);
|
||||
for (ILocation neighbour : neighbours) {
|
||||
assertTrue(location.gridDistanceTo(neighbour) <= 3);
|
||||
}
|
||||
assertEquals(27, neighbours.size());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user