mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Parprogrammering med Toby: Fikset bug og laget tester.
Fikset bug med lasere på vegger: Skadet ikke roboter på samme tile som veggen
This commit is contained in:
parent
bb4dda0515
commit
e067f0b4fe
@ -445,7 +445,8 @@ public class Board {
|
||||
* @param laser the wall laser that is being fired
|
||||
*/
|
||||
private void fireOneWallLaser(BoardElementContainer<Wall> laser){
|
||||
Position hitPosition = lineForTheLaser(Direction.getReverseDirection(laser.getElement().getDirection()),laser.getPosition());
|
||||
Position hitPosition = lineForTheLaser(Direction.getReverseDirection(laser.getElement().getDirection()),
|
||||
laser.getPosition());
|
||||
if(getRobotOnPosition(hitPosition)!=null){
|
||||
laserDamage(laser.getElement().getWallType(),robots.get(getRobotOnPosition(hitPosition)));
|
||||
}
|
||||
@ -485,7 +486,8 @@ public class Board {
|
||||
*/
|
||||
private Position lineForTheLaser(Direction direction, Position startPosition){
|
||||
Position newPosition = getNewPosition(startPosition,direction);
|
||||
if(!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition,newPosition,direction)){
|
||||
if(!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition,newPosition,direction) ||
|
||||
getRobotOnPosition(startPosition)!= null){
|
||||
return startPosition;
|
||||
}
|
||||
else if(getRobotOnPosition(newPosition)!=null){
|
||||
|
@ -65,7 +65,7 @@ public class BoardTest {
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_3, new Position(4,1)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_4, new Position(0,3)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_4, new Position(1,7)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_5, new Position(0,4)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_6, new Position(0,5)));
|
||||
robotListforlaser.add(new Robot(RobotID.ROBOT_7, new Position(7,0)));
|
||||
@ -75,6 +75,9 @@ public class BoardTest {
|
||||
wallGridforlaser.setElement(7, 4, new Wall(WallType.WALL_LASER_DOUBLE, Direction.SOUTH));
|
||||
wallGridforlaser.setElement(2, 3, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH));
|
||||
wallGridforlaser.setElement(4, 3, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH));
|
||||
wallGridforlaser.setElement(0, 7, new Wall(WallType.WALL_LASER_SINGLE, Direction.WEST));
|
||||
wallGridforlaser.setElement(2, 7, new Wall(WallType.WALL_LASER_SINGLE, Direction.EAST));
|
||||
wallGridforlaser.setElement(0, 5, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH));
|
||||
boardforlaser = new Board(tileGridforlaser, wallGridforlaser, robotListforlaser);
|
||||
|
||||
tileGrid = new Grid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH));
|
||||
@ -158,6 +161,40 @@ public class BoardTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotGetsHitByTwoLasers(){
|
||||
Robot testRobot = robotListforlaser.get(3);
|
||||
assertEquals(0, testRobot.getDamageTaken());
|
||||
boardforlaser.fireAllLasers();
|
||||
assertEquals(2, testRobot.getDamageTaken());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void robotDamageEachOther() {
|
||||
Robot robot5 = robotListforlaser.get(4);
|
||||
Robot robot6 = robotListforlaser.get(5);
|
||||
robot5.setFacingDirection(Direction.SOUTH);
|
||||
assertEquals(0, robot5.getDamageTaken());
|
||||
assertEquals(0, robot6.getDamageTaken());
|
||||
boardforlaser.fireAllLasers();
|
||||
assertEquals(1, robot5.getDamageTaken());
|
||||
assertEquals(2, robot6.getDamageTaken());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void robotStandingOnLaserTakesDamage() {
|
||||
Robot robot6 = robotListforlaser.get(5);
|
||||
assertEquals(0, robot6.getDamageTaken());
|
||||
boardforlaser.fireAllLasers();
|
||||
assertEquals(1, robot6.getDamageTaken());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user