mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-10-30 17:23:45 +01:00 
			
		
		
		
	Legger til pushere. Closes #45
This commit is contained in:
		| @@ -19,7 +19,15 @@ public enum WallType { | ||||
|     /** | ||||
|      * A wall with two lasers | ||||
|      */ | ||||
|     WALL_LASER_DOUBLE(4); | ||||
|     WALL_LASER_DOUBLE(4), | ||||
|     /** | ||||
|      * A pusher which pushes on every odd phase | ||||
|      */ | ||||
|     WALL_PUSHER_ODD(5), | ||||
|     /** | ||||
|      * A pusher which pushes on every even phase | ||||
|      */ | ||||
|     WALL_PUSHER_EVEN(6); | ||||
|  | ||||
|     private final int wallTypeID; | ||||
|  | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import inf112.fiasko.roborally.elementproperties.GameState; | ||||
| import inf112.fiasko.roborally.elementproperties.Position; | ||||
| import inf112.fiasko.roborally.elementproperties.RobotID; | ||||
| import inf112.fiasko.roborally.elementproperties.TileType; | ||||
| import inf112.fiasko.roborally.elementproperties.WallType; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| @@ -26,6 +27,8 @@ public class Phase { | ||||
|     private List<BoardElementContainer<Tile>> conveyorBelts; | ||||
|     private List<BoardElementContainer<Tile>> fastConveyorBelts; | ||||
|     private List<BoardElementContainer<Tile>> flags; | ||||
|     private List<BoardElementContainer<Wall>> oddPushers; | ||||
|     private List<BoardElementContainer<Wall>> evenPushers; | ||||
|  | ||||
|     /** | ||||
|      * Instantiates a new phase | ||||
| @@ -54,12 +57,45 @@ public class Phase { | ||||
|         runProgrammingCards(phaseNumber); | ||||
|  | ||||
|         moveAllConveyorBelts(); | ||||
|         startPushers(phaseNumber); | ||||
|         rotateCogwheels(); | ||||
|  | ||||
|         fireAllLasers(); | ||||
|         checkAllFlags(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Starts all pushers which should be pushed this phase | ||||
|      * | ||||
|      * @param phaseNumber The current phase number | ||||
|      * @throws InterruptedException If interrupted while sleeping | ||||
|      */ | ||||
|     private void startPushers(int phaseNumber) throws InterruptedException { | ||||
|         sleep(); | ||||
|         List<BoardElementContainer<Wall>> pushersToPush; | ||||
|         if (phaseNumber % 2 == 0) { | ||||
|             pushersToPush = evenPushers; | ||||
|         } else { | ||||
|             pushersToPush = oddPushers; | ||||
|         } | ||||
|         for (BoardElementContainer<Wall> pusher : pushersToPush) { | ||||
|             runPusher(pusher.getPosition(), Direction.getReverseDirection(pusher.getElement().getDirection())); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Makes the pusher try to push any robot standing on it | ||||
|      * | ||||
|      * @param pusherPosition The position of the pusher which is pushing | ||||
|      * @param pushDirection  The direction of the pusher which is pushing | ||||
|      */ | ||||
|     private void runPusher(Position pusherPosition, Direction pushDirection) { | ||||
|         RobotID robotToPush = gameBoard.getRobotOnPosition(pusherPosition); | ||||
|         if (robotToPush != null) { | ||||
|             gameBoard.moveRobot(robotToPush, pushDirection); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Checks all flags for robots. Tries to update the flag of the robot. | ||||
|      */ | ||||
| @@ -335,5 +371,7 @@ public class Phase { | ||||
|                 TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES)); | ||||
|         flags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, | ||||
|                 TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4); | ||||
|         oddPushers = gameBoard.getPositionsOfWallOnBoard(WallType.WALL_PUSHER_ODD); | ||||
|         evenPushers = gameBoard.getPositionsOfWallOnBoard(WallType.WALL_PUSHER_EVEN); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -38,6 +38,6 @@ | ||||
| 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 | ||||
| 0 0 0 0 0 0 0 0 | ||||
| 1;1 1;3 1;5 1;7 2;2 2;4 2;6 2;8 | ||||
| 3;1 3;3 3;5 3;7 4;1 4;3 4;5 4;7 | ||||
| 3;1 3;3 3;5 3;7 4;1 4;3 4;5 4;7 | ||||
| 5;1 5;3 5;5 5;7 6;1 6;3 6;5 6;7 | ||||
| @@ -1,4 +1,6 @@ | ||||
| WALL_NORMAL 6 3 6 2 4 3 5 3 | ||||
| WALL_CORNER 7 1 7 0 7 3 7 2 | ||||
| WALL_LASER_SINGLE 4 5 5 5 4 4 5 4 | ||||
| WALL_LASER_DOUBLE 5 11 6 11 6 10 4 11 | ||||
| WALL_LASER_DOUBLE 5 11 6 11 6 10 4 11 | ||||
| WALL_PUSHER_ODD 0 1 1 1 2 0 3 1 | ||||
| WALL_PUSHER_EVEN 0 0 1 0 2 1 3 0 | ||||
		Reference in New Issue
	
	Block a user