mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Fikser og forbedrer rotateCogwheels
This commit is contained in:
parent
f3fa78c107
commit
4b731cb062
@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public class RoboRallyGame implements IDrawableGame {
|
public class RoboRallyGame implements IDrawableGame {
|
||||||
private Board gameBoard;
|
private Board gameBoard;
|
||||||
|
List<BoardElementContainer<Tile>> cogwheels;
|
||||||
|
|
||||||
public RoboRallyGame(boolean debug) {
|
public RoboRallyGame(boolean debug) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@ -87,6 +88,8 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3)));
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3)));
|
||||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||||
|
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
|
||||||
|
TileType.COGWHEEL_LEFT);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
runGameLoop();
|
runGameLoop();
|
||||||
@ -189,22 +192,16 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* @throws InterruptedException If interrupted while sleeping.
|
* @throws InterruptedException If interrupted while sleeping.
|
||||||
*/
|
*/
|
||||||
private void rotateCogwheels() throws InterruptedException {
|
private void rotateCogwheels() throws InterruptedException {
|
||||||
List<BoardElementContainer<Tile>> cogWheelsLeft = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
|
for (BoardElementContainer<Tile> cogwheel : cogwheels) {
|
||||||
List<BoardElementContainer<Tile>> cogWheelsRight = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT);
|
if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) {
|
||||||
|
continue;
|
||||||
for (BoardElementContainer<Tile> cogLeft : cogWheelsLeft) {
|
|
||||||
if (!gameBoard.hasRobotOnPosition(cogLeft.getPosition())) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
sleep();
|
sleep();
|
||||||
makeMove(gameBoard.getRobotOnPosition(cogLeft.getPosition()), Action.ROTATE_LEFT);
|
if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) {
|
||||||
}
|
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||||
for (BoardElementContainer<Tile> cogRight : cogWheelsRight) {
|
} else {
|
||||||
if (!gameBoard.hasRobotOnPosition(cogRight.getPosition())) {
|
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
sleep();
|
|
||||||
makeMove(gameBoard.getRobotOnPosition(cogRight.getPosition()), Action.ROTATE_RIGHT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user