fixed bugs in the JSON validation
- the method isWithinBounds(Battleship ship) couldn't check if the ship is the bounds of the map
This commit is contained in:
@@ -305,14 +305,14 @@ private boolean inBounds(ShipMapDTO dto) {
|
|||||||
* @return true if the ship is within bounds, false otherwise
|
* @return true if the ship is within bounds, false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean isWithinBounds(Battleship ship, int width, int height) {
|
private boolean isWithinBounds(Battleship ship, int width, int height) {
|
||||||
int x1 = ship.getX();
|
int minX = ship.getMinX();
|
||||||
int y1 = ship.getY();
|
int maxX = ship.getMaxX();
|
||||||
Rotation r = ship.getRot();
|
int minY = ship.getMinY();
|
||||||
int x2 = x1 + ship.getLength() * r.dx();
|
int maxY = ship.getMaxY();
|
||||||
int y2 = y1 + ship.getLength() * r.dy();
|
return minX >= 0 && minX < width &&
|
||||||
|
minY >= 0 && minY < height &&
|
||||||
return x1 >= 0 && y1 >= 0 && x1 <= width && y1 <= height &&
|
maxX >= 0 && maxX < width &&
|
||||||
x2 >= 0 && y2 >= 0 && x2 <= width && y2 <= height;
|
maxY >= 0 && maxY < height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -185,14 +185,16 @@ private boolean inBounds(List<Battleship> ships) {
|
|||||||
* @return true if the ship is within bounds, false otherwise
|
* @return true if the ship is within bounds, false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean isWithinBounds(Battleship ship) {
|
private boolean isWithinBounds(Battleship ship) {
|
||||||
int x1 = ship.getX();
|
int minX = ship.getMinX();
|
||||||
int y1 = ship.getY();
|
int maxX = ship.getMaxX();
|
||||||
Rotation r = ship.getRot();
|
int minY = ship.getMinY();
|
||||||
int x2 = x1 + ship.getLength() * r.dx();
|
int maxY = ship.getMaxY();
|
||||||
int y2 = y1 + ship.getLength() * r.dy();
|
int width = config.getMapWidth();
|
||||||
|
int height = config.getMapHeight();
|
||||||
return x1 >= 0 && y1 >= 0 && x1 <= config.getMapWidth() && y1 <= config.getMapHeight() &&
|
return minX >= 0 && minX < width &&
|
||||||
x2 >= 0 && y2 >= 0 && x2 <= config.getMapWidth() && y2 <= config.getMapHeight();
|
minY >= 0 && minY < height &&
|
||||||
|
maxX >= 0 && maxX < width &&
|
||||||
|
maxY >= 0 && maxY < height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user