mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Parprogrammering med tobydrama - Laget funksjonalitet for flagg registrering
Lagt inn metoder og hjelpemetoder for å få til registrering av flagg.
This commit is contained in:
parent
7bd59902e2
commit
31bef9fe0b
@ -178,6 +178,19 @@ public class Board {
|
|||||||
return robots.containsKey(robot);
|
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
|
* Checks if a potential robot move would be blocked by a wall
|
||||||
* @param robotPosition The current position of the robot
|
* @param robotPosition The current position of the robot
|
||||||
|
@ -8,7 +8,7 @@ import inf112.fiasko.roborally.element_properties.Position;
|
|||||||
*/
|
*/
|
||||||
public class BoardElementContainer <K>{
|
public class BoardElementContainer <K>{
|
||||||
K obj;
|
K obj;
|
||||||
Position pos;
|
private Position pos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the BoardElementContainer
|
* Initializes the BoardElementContainer
|
||||||
|
@ -5,6 +5,7 @@ import inf112.fiasko.roborally.element_properties.Position;
|
|||||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||||
import inf112.fiasko.roborally.element_properties.TileType;
|
import inf112.fiasko.roborally.element_properties.TileType;
|
||||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -204,4 +205,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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user