mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-06-27 11:44:42 +02:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
Conflicts: src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
This commit is contained in:
@ -175,6 +175,19 @@ public class Board {
|
||||
return robots.containsKey(robot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the flag of the robot if it stands on the correct flag.
|
||||
* @param robotID The RobotID of a robot
|
||||
* @param flagID TileType of the flag we check
|
||||
*/
|
||||
public void updateFlagOnRobot(RobotID robotID, TileType flagID) {
|
||||
Robot robot = robots.get(robotID);
|
||||
int flagNr = flagID.getTileTypeID() % 16;
|
||||
if (flagNr - 1 == robot.getLastFlagVisited()) {
|
||||
robot.setLastFlagVisitedAndUpdateBackupPosition(flagNr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a potential robot move would be blocked by a wall
|
||||
* @param robotPosition The current position of the robot
|
||||
@ -349,7 +362,7 @@ public class Board {
|
||||
* @param walls The walls you want all positions for
|
||||
* @return A list of BoardElementContainers
|
||||
*/
|
||||
public List<BoardElementContainer<Wall>> getPositionsOfTileOnBoard(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));
|
||||
@ -371,18 +384,20 @@ public class Board {
|
||||
for (int y = grid.getHeight() - 1; y >= 0; y--) {
|
||||
for (int x = 0; x < grid.getWidth(); x++) {
|
||||
T gridElement = grid.getElement(x, y);
|
||||
if (gridElement.getClass().isAssignableFrom(Tile.class)) {
|
||||
Tile tile = (Tile) gridElement;
|
||||
if (tile.getTileType() == type) {
|
||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||
if (gridElement != null) {
|
||||
if (gridElement.getClass().isAssignableFrom(Tile.class)) {
|
||||
Tile tile = (Tile) gridElement;
|
||||
if (tile.getTileType() == type) {
|
||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||
}
|
||||
} else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
|
||||
Wall wall = (Wall) gridElement;
|
||||
if (wall.getWallType() == type) {
|
||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Grid has unknown type.");
|
||||
}
|
||||
} else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
|
||||
Wall wall = (Wall) gridElement;
|
||||
if (wall.getWallType() == type) {
|
||||
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Grid has unknown type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import inf112.fiasko.roborally.element_properties.Position;
|
||||
*/
|
||||
public class BoardElementContainer <K>{
|
||||
K obj;
|
||||
Position pos;
|
||||
private Position pos;
|
||||
|
||||
/**
|
||||
* Initializes the BoardElementContainer
|
||||
|
@ -2,6 +2,7 @@ package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.*;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -283,4 +284,19 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all flags for robots. Tries to update the flag of the robot.
|
||||
*/
|
||||
private void checkAllFlags() {
|
||||
List<BoardElementContainer<Tile>> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
|
||||
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
|
||||
for (BoardElementContainer<Tile> flag:listOfFlags) {
|
||||
Position flagPosition = flag.getPosition();
|
||||
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
||||
RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
|
||||
gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user