diff --git a/src/main/java/controller/server/ServerConnection.java b/src/main/java/controller/server/ServerConnection.java index c9fb461..f4a56e7 100644 --- a/src/main/java/controller/server/ServerConnection.java +++ b/src/main/java/controller/server/ServerConnection.java @@ -13,7 +13,7 @@ public class ServerConnection { private String method; private String path; - private static final String LOCAL_HOST = "http://localhost:3000"; + private static final String LOCAL_HOST = "http://130.225.170.75:3000"; private static final String PUBLIC_HOST = "https://dry-brushlands-54922.herokuapp.com"; private static final String SERVER_URL = checkOnline(LOCAL_HOST) ? LOCAL_HOST : PUBLIC_HOST; diff --git a/src/main/java/model/game/board/map/element/ConveyorBelt.java b/src/main/java/model/game/board/map/element/ConveyorBelt.java index 689f5e4..69af105 100644 --- a/src/main/java/model/game/board/map/element/ConveyorBelt.java +++ b/src/main/java/model/game/board/map/element/ConveyorBelt.java @@ -4,8 +4,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import content.OrientationEnum; +import model.Game; import model.game.board.map.Position; import model.game.card.*; +import model.game.card.behaviour.Movement; @EqualsAndHashCode(callSuper = true) @Data @@ -56,11 +58,14 @@ private void init(OrientationEnum orientation, int distance) { @Override public void robotInteraction(Robot r) { - if (this.orientation.equals(r.getOrientation())) { - if (this.distance == 1) { - new CardMove1().actsOn(r); - } else if(this.distance == 2){ - new CardMove2().actsOn(r); + if (this.orientation.getAngle() == r.getOrientation().getAngle()) { + Position newPos = Movement.calculateNewPosition(r.getOrientation(), r.getPosition(), 1); + if (Movement.validateMovement(r, newPos.getRow(), newPos.getCol(), 1)) { + Robot robotAtPos = Game.getInstance().getRobotAtPosition(newPos); + if (robotAtPos != null) { + r.robotInteraction(robotAtPos, 1); + } + r.setPosition(newPos); } } } diff --git a/src/main/java/model/game/board/map/element/Robot.java b/src/main/java/model/game/board/map/element/Robot.java index ab5b125..bc66646 100644 --- a/src/main/java/model/game/board/map/element/Robot.java +++ b/src/main/java/model/game/board/map/element/Robot.java @@ -74,7 +74,6 @@ public void robotInteraction(Robot robot, int movement) { // I move 1 position in the direction of the robot coming in my position if robot is moving forwards // I move 1 position in the opposite direction of the robot coming in my position if robot is moving backwards // I don't move in the new position if there is no valid movement - // calculate my new position depending on the described scenarios Position newPos = new Position(); if (movement == 1) { diff --git a/src/test/java/client/test/MapElementStepsDefinition.java b/src/test/java/client/test/MapElementStepsDefinition.java index 6de6f85..e05fc9f 100644 --- a/src/test/java/client/test/MapElementStepsDefinition.java +++ b/src/test/java/client/test/MapElementStepsDefinition.java @@ -418,19 +418,19 @@ public void robotDoesNotMoveBackward() { assertEquals(this.robot.getPosition(), this.initialRobotPosition); } - private int conveyorDistance = -1; - - @When("robot lands on a conveyor belt with distance {string}") - public void robotLandsOnAConveyorBeltWithDirection(String arg1) { - Tile tile = (ConveyorBelt) GameMap.getInstance().getTileAtPosition(Movement.calculateNewPosition(this.robot.getOrientation(), this.robot.getPosition(), 1)); - Card actionCard = new CardMove1(); - actionCard.actsOn(this.robot); - this.conveyorDistance = Integer.parseInt(arg1); + @When("robot lands on a conveyor belt and move forward {int} steps") + public void robotLandsOnAConveyorBeltAndMoveForwardSteps(int steps) { + if (steps == 1) + new CardMove1().actsOn(this.robot); + if (steps == 2) + new CardMove2().actsOn(this.robot); + if (steps == 3) + new CardMove3().actsOn(this.robot); } - @Then("robot moves forward according to the direction") - public void robotMovesForwardAccordingToTheDirection() { - assertTrue(Math.abs(this.robot.getPosition().getRow() - this.initialRobotPosition.getRow() - 1) == conveyorDistance || Math.abs(this.robot.getPosition().getCol() - this.initialRobotPosition.getCol() - 1) == conveyorDistance); + @Then("robot is on the position {int} and {int}") + public void robotIsOnThePositionNew_rowAndNew_col(int new_row, int new_col) { + assertTrue(new_row == this.robot.getPosition().getRow() && new_col == this.robot.getPosition().getCol()); } @When("robot execute power up card") @@ -438,7 +438,5 @@ public void robotExecutePowerUpCard() { Card actionCard = new CardPowerUp(); actionCard.actsOn(this.robot); } - - //16.---------------------------------------------------------------- } diff --git a/src/test/resources/featureFiles/MapElement.feature b/src/test/resources/featureFiles/MapElement.feature index 96cc56f..8cc3a76 100644 --- a/src/test/resources/featureFiles/MapElement.feature +++ b/src/test/resources/featureFiles/MapElement.feature @@ -154,15 +154,15 @@ Feature: Given there is a game with map "" And a robot "" with position "" "" And robot has "" orientation - When robot lands on a conveyor belt with distance "" - Then robot moves forward according to the direction + When robot lands on a conveyor belt and move forward steps + Then robot is on the position and Examples: - | map_name | robot_name | row | col | orientation | distance | - | INTERMEDIATE | ZOOM_BOT | 1 | 3 | E | 1 | - | INTERMEDIATE | ZOOM_BOT | 1 | 2 | E | 1 | - | INTERMEDIATE | ZOOM_BOT | 9 | 10 | E | 1 | - | INTERMEDIATE | ZOOM_BOT | 0 | 1 | E | 1 | - | INTERMEDIATE | ZOOM_BOT | 2 | 5 | S | 2 | + | map_name | robot_name | row | col | orientation | steps | new_row | new_col | + | INTERMEDIATE | ZOOM_BOT | 1 | 3 | E | 1 | 1 | 4 | + | INTERMEDIATE | ZOOM_BOT | 1 | 5 | W | 1 | 1 | 3 | + | INTERMEDIATE | ZOOM_BOT | 9 | 10 | E | 2 | 9 | 12 | + | STARTER | ZOOM_BOT | 8 | 2 | E | 2 | 8 | 6 | + | STARTER | ZOOM_BOT | 0 | 4 | S | 3 | 6 | 4 | Scenario Outline: Robots cannot go through a wall when wall is at next position Given there is a game with map ""