Skip to content

Commit

Permalink
revise conveyorbelt
Browse files Browse the repository at this point in the history
  • Loading branch information
JiananAlvin committed May 3, 2022
1 parent 4f7e6b8 commit 45abeb3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/controller/server/ServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/model/game/board/map/element/ConveyorBelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/model/game/board/map/element/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 11 additions & 13 deletions src/test/java/client/test/MapElementStepsDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,27 +418,25 @@ 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")
public void robotExecutePowerUpCard() {
Card actionCard = new CardPowerUp();
actionCard.actsOn(this.robot);
}


//16.----------------------------------------------------------------
}
16 changes: 8 additions & 8 deletions src/test/resources/featureFiles/MapElement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ Feature:
Given there is a game with map "<map_name>"
And a robot "<robot_name>" with position "<row>" "<col>"
And robot has "<orientation>" orientation
When robot lands on a conveyor belt with distance "<distance>"
Then robot moves forward according to the direction
When robot lands on a conveyor belt and move forward <steps> steps
Then robot is on the position <new_row> and <new_col>
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 "<map_name>"
Expand Down

0 comments on commit 45abeb3

Please sign in to comment.