From 54c1a9d48513b2ab53846a20d9c7265b68bcb341 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 30 Apr 2020 14:37:03 +0200 Subject: [PATCH 1/5] made a board that is used for testing respawning --- .../java/inf112/fiasko/roborally/objects/BoardTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 0fd305e..b656d00 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -234,7 +234,9 @@ public class BoardTest { public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() { Robot testRobot = robotList.get(6); assertEquals(0, testRobot.getLastFlagVisited()); - board.updateRobotFlag(RobotID.ROBOT_7, TileType.FLAG_1); + BoardElementContainer flag = new BoardElementContainer<>(new Tile(TileType.FLAG_1,Direction.NORTH) + ,new Position(1,1)); + board.updateRobotFlag(RobotID.ROBOT_7, flag); assertEquals(1, testRobot.getLastFlagVisited()); } @@ -242,7 +244,9 @@ public class BoardTest { public void flagDoesNotUpdatedOnRobotWithWrongLastVisitedFlag() { Robot testRobot = robotList.get(6); assertEquals(0, testRobot.getLastFlagVisited()); - board.updateRobotFlag(RobotID.ROBOT_7, TileType.FLAG_2); + BoardElementContainer flag = new BoardElementContainer<>(new Tile(TileType.FLAG_2,Direction.NORTH) + ,new Position(1,1)); + board.updateRobotFlag(RobotID.ROBOT_7, flag); assertEquals(0, testRobot.getLastFlagVisited()); } From e949af43bc96deb595ffdf321661c615c9987cec Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 30 Apr 2020 14:37:32 +0200 Subject: [PATCH 2/5] added the testing map to the lobby screen --- .../fiasko/roborally/gamewrapper/screens/LobbyScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java index edab71c..abd294a 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java @@ -45,7 +45,7 @@ public class LobbyScreen extends InteractiveScreen { selectBox = new SelectBox<>(skin); selectBox.setItems("Dizzy_Dash", "Checkmate", "Risky_Exchange", "Twister", "Bloodbath_Chess", "Vault_Assault", - "Island_Hop", "Chop_Shop_Challenge", "Around_The_World", "Death_Trap"); + "Island_Hop", "Chop_Shop_Challenge", "Around_The_World", "Death_Trap", "TestRespawn"); selectBox.setSize(200, 50); selectBox.setPosition((applicationWidth - selectBox.getWidth()) / 2f, applicationHeight / 2f - 120); From 76a1b344e104e8a6124ad5324ccc8092ffe6c47d Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 30 Apr 2020 14:38:16 +0200 Subject: [PATCH 3/5] added a upadte robot spawn that updates the robot spawn location --- src/main/java/inf112/fiasko/roborally/objects/Phase.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java index 78d0881..0f99f55 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java @@ -62,6 +62,11 @@ public class Phase { fireAllLasers(); checkAllFlags(); + updateRobotRespawn(); + } + + public void updateRobotRespawn(){ + gameBoard.updateRobotRespawn(); } /** @@ -109,7 +114,7 @@ public class Phase { if (gameBoard.hasTouchedFlagThisTurn(robotID)) { continue; } - gameBoard.updateRobotFlag(robotID, flag.getElement().getType()); + gameBoard.updateRobotFlag(robotID, flag); checkIfPlayerWon(robotID, flags.size()); } } From a77b3389d3b235082d7f6f14f5f851112ccad41c Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 30 Apr 2020 14:38:59 +0200 Subject: [PATCH 4/5] removed the testing map from the lobby screen --- .../fiasko/roborally/gamewrapper/screens/LobbyScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java index abd294a..edab71c 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java @@ -45,7 +45,7 @@ public class LobbyScreen extends InteractiveScreen { selectBox = new SelectBox<>(skin); selectBox.setItems("Dizzy_Dash", "Checkmate", "Risky_Exchange", "Twister", "Bloodbath_Chess", "Vault_Assault", - "Island_Hop", "Chop_Shop_Challenge", "Around_The_World", "Death_Trap", "TestRespawn"); + "Island_Hop", "Chop_Shop_Challenge", "Around_The_World", "Death_Trap"); selectBox.setSize(200, 50); selectBox.setPosition((applicationWidth - selectBox.getWidth()) / 2f, applicationHeight / 2f - 120); From 49121e52b76fcb11d929f8a1c3e62689cf79b2a5 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 30 Apr 2020 14:40:17 +0200 Subject: [PATCH 5/5] updated the respawn function to handle multiple robots respawning on the same tile --- .../fiasko/roborally/objects/Board.java | 104 +++++++++++++++++- 1 file changed, 98 insertions(+), 6 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index af98a68..ed360e5 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -448,9 +448,7 @@ public class Board { public void respawnRobots() { for (Robot robot : deadRobots) { if (robot.getAmountOfLives() > 0) { - robot.setPosition(robot.getBackupPosition()); - robot.setFacingDirection(GridUtil.getMatchingElements(TileType.FLAG_1, - tiles).get(0).getElement().getDirection()); + tryCircle(robot); robot.setDamageTaken(2); robots.put(robot.getRobotId(), robot); } else { @@ -459,7 +457,101 @@ public class Board { } deadRobots = new ArrayList<>(); } + public void tryCircle(Robot robot){ + Position respawn = robot.getBackupPosition(); + int startX=respawn.getXCoordinate(); + int startY=respawn.getYCoordinate(); + if(!hasRobotOnPosition(respawn)){ + robot.setPosition(respawn); + return; + } + for(int i=1; i<3;i++){ + if(tryRespawn(robot,i,startX,startY,Direction.NORTH)){ + break; + } + if(tryRespawn(robot,i,startX,startY,Direction.SOUTH)){ + break; + } + if(tryRespawn(robot,i,startX,startY,Direction.EAST)){ + break; + } + if(tryRespawn(robot,i,startX,startY,Direction.WEST)){ + break; + } + } + } + public Boolean tryRespawn(Robot robot,int size,int startX,int startY,Direction direction){ + int axis; + for(int i=1;i<=size;i++) { + if (direction== Direction.NORTH ||direction== Direction.SOUTH) { + axis=startX; + } + else{ + axis=startY; + } + for (int j = axis-i; j < axis+i; j++) { + int[] coordinates = switchForRespawn(startX,startY,direction,j,size); + int x=coordinates[0]; + int y=coordinates[1]; + Position tryRespawn = new Position(x, y); + System.out.println(tryRespawn); + if (!isValidPosition(tryRespawn)) { + continue; + } + TileType tile = getTileOnPosition(tryRespawn).getType(); + if(checkIfRespawnHasPit(tile, direction, robot, tryRespawn)){ + return true; + } + } + } + return false; + } + private int[] switchForRespawn(int startX,int startY,Direction direction,int j,int size){ + int x; + int y; + switch (direction){ + case NORTH: + x = j; + y = startY-size; + break; + case SOUTH: + x = j; + y = startY+size; + break; + case WEST: + x = startX-size; + y = j; + break; + case EAST: + x = startX+size; + y = j; + break; + default: throw new IllegalArgumentException("invalid direction for tile"); + } + return new int[]{x,y}; + } + public boolean checkIfRespawnHasPit(TileType tile,Direction direction,Robot robot,Position tryRespawn){ + if ( tile!=TileType.PIT_CORNER && tile!=TileType.PIT_EMPTY &&tile!=TileType.PIT_FULL && + tile!=TileType.PIT_NORMAL &&tile!=TileType.PIT_U && tile!=TileType.HOLE){ + if(!hasRobotOnPosition(tryRespawn)){ + robot.setFacingDirection(direction); + robot.setPosition(tryRespawn); + return true; + } + } + return false; + } + public void updateRobotRespawn(){ + List> repaireTiles = getPositionsOfTilesOnBoard(TileType.WRENCH, + TileType.WRENCH_AND_HAMMER,TileType.FLAG_1,TileType.FLAG_2,TileType.FLAG_3,TileType.FLAG_4); + for (BoardElementContainer repaireTile:repaireTiles) { + Position pos = repaireTile.getPosition(); + if(hasRobotOnPosition(pos)){ + getRobot(getRobotOnPosition(pos)).setBackupPosition(pos); + } + } + } /** * Returns a robot id for a robot on a specific position if such a robot exists * @@ -490,11 +582,11 @@ public class Board { * Updates the flag of the robot if it stands on the correct flag. * * @param robotID The RobotID of a robot - * @param flagID TileType of the flag we check + * @param flag BoardElementContainer of the flag we check */ - public void updateRobotFlag(RobotID robotID, TileType flagID) { + public void updateRobotFlag(RobotID robotID, BoardElementContainer flag) { Robot robot = robots.get(robotID); - int flagNumber = flagID.getTileTypeID() % 16; + int flagNumber = flag.getElement().getType().getTileTypeID() % 16; if (flagNumber - 1 == robot.getLastFlagVisited()) { robot.setLastFlagVisited(flagNumber); setHasTouchedFlagThisTurn(robotID, true);