mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
d864e60f24
5
docs/team/referater/referat_12_03_2020.md
Normal file
5
docs/team/referater/referat_12_03_2020.md
Normal file
@ -0,0 +1,5 @@
|
||||
## Oppmøte
|
||||
Alle i teamet var tilstede.
|
||||
|
||||
## Gjennomgått
|
||||
Vi har jobbet med parprogrammering.
|
@ -251,7 +251,7 @@ public class Board {
|
||||
* @param position The position to check
|
||||
* @return The robot id of the robot on the position or null if there is no robot there
|
||||
*/
|
||||
private RobotID getRobotOnPosition(Position position) {
|
||||
RobotID getRobotOnPosition(Position position) {
|
||||
for (RobotID robotID : robots.keySet()) {
|
||||
Robot robot = robots.get(robotID);
|
||||
if (position.equals(robot.getPosition())) {
|
||||
@ -266,7 +266,7 @@ public class Board {
|
||||
* @param position The position to check
|
||||
* @return True if there is a robot on the specified position
|
||||
*/
|
||||
private boolean hasRobotOnPosition(Position position) {
|
||||
boolean hasRobotOnPosition(Position position) {
|
||||
return getRobotOnPosition(position) != null;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ 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.utility.BoardLoaderUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -15,6 +16,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class RoboRallyGame implements IDrawableGame {
|
||||
private Board gameBoard;
|
||||
List<BoardElementContainer<Tile>> cogwheels;
|
||||
|
||||
public RoboRallyGame(boolean debug) {
|
||||
if (debug) {
|
||||
@ -86,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_3, new Position(1, 3)));
|
||||
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
|
||||
TileType.COGWHEEL_LEFT);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
runGameLoop();
|
||||
@ -182,4 +186,22 @@ public class RoboRallyGame implements IDrawableGame {
|
||||
sleep();
|
||||
gameBoard.moveRobotForward(robotID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates all robots that are standing on cogWheel tiles on the board.
|
||||
* @throws InterruptedException If interrupted while sleeping.
|
||||
*/
|
||||
private void rotateCogwheels() throws InterruptedException {
|
||||
for (BoardElementContainer<Tile> cogwheel : cogwheels) {
|
||||
if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) {
|
||||
continue;
|
||||
}
|
||||
sleep();
|
||||
if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) {
|
||||
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
} else {
|
||||
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.Direction;
|
||||
import inf112.fiasko.roborally.element_properties.Position;
|
||||
import inf112.fiasko.roborally.element_properties.TileType;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BoardElementContainerTest {
|
||||
|
||||
@Test
|
||||
public void getObjectTest() {
|
||||
Position pos = new Position(1,2);
|
||||
Tile tile = new Tile(TileType.TILE, Direction.NORTH);
|
||||
BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos);
|
||||
assertEquals(tile, element.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPositionTest() {
|
||||
Position pos = new Position(1,2);
|
||||
Tile tile = new Tile(TileType.TILE, Direction.NORTH);
|
||||
BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos);
|
||||
assertEquals(pos, element.getPosition());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user