mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Adds partial functionality that moves robots standing on conveyor belts.
This commit is contained in:
parent
d864e60f24
commit
816f502f12
@ -1,9 +1,6 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.*;
|
||||
import inf112.fiasko.roborally.utility.TextureConverterUtil;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -296,7 +293,7 @@ public class Board {
|
||||
* @param direction The direction to move the element
|
||||
* @return The new position of the element
|
||||
*/
|
||||
private Position getNewPosition(Position oldPosition, Direction direction) {
|
||||
Position getNewPosition(Position oldPosition, Direction direction) {
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() - 1);
|
||||
@ -327,6 +324,13 @@ public class Board {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public Tile getTileOnPosition(Position position) {
|
||||
if (!isValidPosition(position)) {
|
||||
throw new IllegalArgumentException("Position is not on the board!");
|
||||
}
|
||||
return tiles.getElement(position.getXCoordinate(), position.getYCoordinate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of BoardElementContainers, containing all tiles and positions of given tile types
|
||||
* @param tiles The tiles you want all positions for
|
||||
|
@ -1,9 +1,6 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.Action;
|
||||
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.*;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -17,6 +14,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class RoboRallyGame implements IDrawableGame {
|
||||
private Board gameBoard;
|
||||
List<BoardElementContainer<Tile>> cogwheels;
|
||||
List<BoardElementContainer<Tile>> conveyorBelts;
|
||||
|
||||
public RoboRallyGame(boolean debug) {
|
||||
if (debug) {
|
||||
@ -90,6 +88,13 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
|
||||
TileType.COGWHEEL_LEFT);
|
||||
conveyorBelts = gameBoard.getPositionsOfTileOnBoard(TileType.TRANSPORT_BAND_FAST,
|
||||
TileType.TRANSPORT_BAND_SLOW, TileType.TRANSPORT_BAND_FAST_SIDE_ENTRANCE_RIGHT,
|
||||
TileType.TRANSPORT_BAND_FAST_RIGHT, TileType.TRANSPORT_BAND_SLOW_RIGHT,
|
||||
TileType.TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_RIGHT, TileType.TRANSPORT_BAND_FAST_SIDE_ENTRANCE_LEFT,
|
||||
TileType.TRANSPORT_BAND_FAST_LEFT, TileType.TRANSPORT_BAND_SLOW_LEFT,
|
||||
TileType.TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_LEFT);
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
runGameLoop();
|
||||
@ -204,4 +209,78 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves robots standing on conveyor belts in the direction of the conveyor belt.
|
||||
* Rotates robots being moved to a turn on the conveyor belt.
|
||||
* @throws InterruptedException If disturbed during sleep.
|
||||
*/
|
||||
private void moveConveyorBelts() throws InterruptedException {
|
||||
for (BoardElementContainer<Tile> conveyorBelt : conveyorBelts) {
|
||||
if (!gameBoard.hasRobotOnPosition(conveyorBelt.getPosition())) {
|
||||
continue;
|
||||
}
|
||||
Position newPosition = gameBoard.getNewPosition(conveyorBelt.getPosition(),
|
||||
conveyorBelt.getObject().getDirection());
|
||||
Tile nextTile = gameBoard.getTileOnPosition(newPosition);
|
||||
Direction currentDirection = conveyorBelt.getObject().getDirection();
|
||||
Direction nextDirection = nextTile.getDirection();
|
||||
RobotID robot = gameBoard.getRobotOnPosition(conveyorBelt.getPosition());
|
||||
if (conveyorBelts.contains(nextTile) && currentDirection != nextDirection) {
|
||||
if (currentDirection.equals(Direction.NORTH)) {
|
||||
if (nextDirection.equals(Direction.WEST)) {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
} else {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotRight(robot);
|
||||
}
|
||||
} else if (currentDirection.equals(Direction.WEST)) {
|
||||
if (nextDirection.equals(Direction.SOUTH)) {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
} else {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
}
|
||||
} else if (currentDirection.equals(Direction.SOUTH)) {
|
||||
if (nextDirection.equals(Direction.EAST)) {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
} else {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotRight(robot);
|
||||
}
|
||||
} else if (currentDirection.equals(Direction.EAST)) {
|
||||
if (nextDirection.equals(Direction.NORTH)) {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotLeft(robot);
|
||||
} else {
|
||||
sleep();
|
||||
gameBoard.moveRobot(robot, currentDirection);
|
||||
sleep();
|
||||
gameBoard.rotateRobotRight(robot);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sleep();
|
||||
gameBoard.moveRobot(gameBoard.getRobotOnPosition(conveyorBelt.getPosition()),
|
||||
conveyorBelt.getObject().getDirection());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user