From e067f0b4fe1fbf5ea0d15a48e7d68d54fc0b273f Mon Sep 17 00:00:00 2001
From: Steinar Aalstad Lillesund <Steinar.Lillesund@Student.uib.no>
Date: Thu, 19 Mar 2020 12:11:58 +0100
Subject: [PATCH] Parprogrammering med Toby: Fikset bug og laget tester.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fikset bug med lasere på vegger: Skadet ikke roboter på samme tile som veggen
---
 .../fiasko/roborally/objects/Board.java       |  6 ++-
 .../fiasko/roborally/objects/BoardTest.java   | 39 ++++++++++++++++++-
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java
index 41657d0..1918323 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Board.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java
@@ -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){
diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java
index 8869310..54d6958 100644
--- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java
+++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java
@@ -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