mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-08-02 05:05:26 +02:00
Fikser kodestil
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.*;
|
||||
import inf112.fiasko.roborally.element_properties.Direction;
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import inf112.fiasko.roborally.element_properties.TileType;
|
||||
import inf112.fiasko.roborally.element_properties.WallType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -166,6 +171,21 @@ public class Board {
|
||||
deadRobots = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a robot id for a robot on a specific position if such a robot exists
|
||||
* @param position The position to check
|
||||
* @return The robot id of the robot on the position or null if there is no robot there
|
||||
*/
|
||||
public RobotID getRobotOnPosition(Position position) {
|
||||
for (RobotID robotID : robots.keySet()) {
|
||||
Robot robot = robots.get(robotID);
|
||||
if (position.equals(robot.getPosition())) {
|
||||
return robotID;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a specific robot is currently alive on the board
|
||||
* @param robot the ID of the robot you want to check
|
||||
@@ -256,27 +276,12 @@ public class Board {
|
||||
deadRobots.add(robot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a robot id for a robot on a specific position if such a robot exists
|
||||
* @param position The position to check
|
||||
* @return The robot id of the robot on the position or null if there is no robot there
|
||||
*/
|
||||
RobotID getRobotOnPosition(Position position) {
|
||||
for (RobotID robotID : robots.keySet()) {
|
||||
Robot robot = robots.get(robotID);
|
||||
if (position.equals(robot.getPosition())) {
|
||||
return robotID;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there exists a robot on a specific position
|
||||
* @param position The position to check
|
||||
* @return True if there is a robot on the specified position
|
||||
*/
|
||||
boolean hasRobotOnPosition(Position position) {
|
||||
public boolean hasRobotOnPosition(Position position) {
|
||||
return getRobotOnPosition(position) != null;
|
||||
}
|
||||
|
||||
@@ -362,7 +367,7 @@ public class Board {
|
||||
* @param walls The walls you want all positions for
|
||||
* @return A list of BoardElementContainers
|
||||
*/
|
||||
public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType ... walls) {
|
||||
public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType... walls) {
|
||||
List<BoardElementContainer<Wall>> combinedList = new ArrayList<>();
|
||||
for (WallType wall : walls) {
|
||||
combinedList.addAll(makeTileList(wall, this.walls));
|
||||
|
@@ -3,36 +3,36 @@ package inf112.fiasko.roborally.objects;
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
|
||||
/**
|
||||
* This class represents a type of object and its position
|
||||
* @param <K> The type of object
|
||||
* This class represents a board element and its position
|
||||
* @param <K> The type of element
|
||||
*/
|
||||
public class BoardElementContainer <K>{
|
||||
K obj;
|
||||
private Position pos;
|
||||
public class BoardElementContainer <K> {
|
||||
private final K element;
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Initializes the BoardElementContainer
|
||||
* @param obj The object
|
||||
* @param pos The position
|
||||
* @param element The element
|
||||
* @param position The position
|
||||
*/
|
||||
BoardElementContainer(K obj, Position pos) {
|
||||
this.obj = obj;
|
||||
this.pos = pos;
|
||||
BoardElementContainer(K element, Position position) {
|
||||
this.element = element;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object
|
||||
* @return object
|
||||
* Gets the element
|
||||
* @return The element
|
||||
*/
|
||||
public K getObject() {
|
||||
return obj;
|
||||
public K getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position
|
||||
* @return position
|
||||
* @return The position
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return pos;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
@@ -211,7 +211,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
continue;
|
||||
}
|
||||
sleep();
|
||||
if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) {
|
||||
if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) {
|
||||
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
} else {
|
||||
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
@@ -258,7 +258,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
continue;
|
||||
}
|
||||
Position conveyorBeltPosition = conveyorBelt.getPosition();
|
||||
Tile conveyorBeltTile = conveyorBelt.getObject();
|
||||
Tile conveyorBeltTile = conveyorBelt.getElement();
|
||||
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltTile.getDirection());
|
||||
Tile nextTile = gameBoard.getTileOnPosition(newPosition);
|
||||
|
||||
@@ -283,7 +283,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
Direction nextDirection = nextTile.getDirection();
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
if (testPredicate(conveyorBelts, (container) -> container.getObject() == nextTile)) {
|
||||
if (testPredicate(conveyorBelts, (container) -> container.getElement() == nextTile)) {
|
||||
if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) {
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
@@ -304,7 +304,7 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
Position flagPosition = flag.getPosition();
|
||||
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
||||
RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
|
||||
gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType());
|
||||
gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user