diff --git a/assets/Boards/pusherBoardTest.json b/assets/Boards/pusherBoardTest.json new file mode 100644 index 0000000..a3bffcd --- /dev/null +++ b/assets/Boards/pusherBoardTest.json @@ -0,0 +1,9 @@ +{ + "name": "check mate", + "length": "short", + "players": "5-8", + "width": "12", + "height": "12", + "grid": "f_wN f_pSO f f f f_wN f f f f_pSP f_bNW1 f f_pEO f f f_bSE0 f f_pSP f f f f_pWP f f f f f f f f f f f f f f f_pWP f f f f f f f_pWP f f f f f f f f_wN f f f f f f f_pWP f f f f f f f f f f f_bSEN0 f f_bSEN1 f f_bSEW0 f_bSEW1 f f_pWO f f_pWP f f_pWP f f_pWO f f_pWP f f_pWP f f f f_pWO f_pEP f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f" + +} \ No newline at end of file diff --git a/src/main/java/sky7/Client/Client.java b/src/main/java/sky7/Client/Client.java index d6bdb47..5ede673 100644 --- a/src/main/java/sky7/Client/Client.java +++ b/src/main/java/sky7/Client/Client.java @@ -3,11 +3,13 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.HashMap; import sky7.board.BoardGenerator; import sky7.board.IBoard; import sky7.board.IBoardGenerator; +import sky7.board.cellContents.Inactive.Flag; import sky7.card.ICard; import sky7.card.IProgramCard; import sky7.game.Game; @@ -22,6 +24,7 @@ public class Client implements IClient { private IPlayer player; private STATE state; private String boardName; + private HashSet flagVisited; private Game game; private boolean localClient, readyToRender = false; // True if this user is also running Host, false if remotely connected to Host. private ClientNetHandler netHandler; @@ -32,6 +35,7 @@ public Client() { //board = new Board(10,8); this.player = new Player(); state = STATE.LOADING; + this.flagVisited = new HashSet<>(); localClient = true; } @@ -144,6 +148,24 @@ public void activateBoardElements() { public void activateLasers() { //TODO should call board.activateLasers + + } + public void setFlagVisited(Flag visitedFlag){ + int flagNumber = visitedFlag.getFlagNumber(); + boolean canVisit= true; + //check if the player has visited every previous flag + for(int i=1; i[][] grid; private int width, height, nPlayers, maxMove; @@ -38,7 +38,6 @@ public class Board implements IBoard { private List flagPositions; private List wrenches; private List wrenchPositions; - public Board(int width, int height) { this.width = width; this.height = height; @@ -84,11 +83,12 @@ public Board(TreeSet[][] grid, int height, int width) { this.pusherPos = new ArrayList<>(); this.startPositions = new ArrayList<>(); this.startCells = new ArrayList<>(); - this.flagPositions = new ArrayList<>(); this.flags = new ArrayList<>(); + this.flagPositions = new ArrayList<>(); this.wrenchPositions = new ArrayList<>(); this.wrenches = new ArrayList<>(); + // find and store locations of cogwheels, conveyor belts for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { @@ -410,6 +410,49 @@ public void rotateRobot(int currentPlayer, int rotate) { public void moveConveyors() { // TODO Auto-generated method stub } + @Override + public List getPusherPos(){ + return pusherPos; + } + @Override + public List getPushers(){ + return pushers; + } + + + +/* + private boolean canPusherPush(Vector2 pos, DIRECTION dirToPush) { + if(wallInCurrentTile(pos,dirToPush)){ + return false; + } + Vector2 newPos = getDestination(pos, dirToPush, 1); + + if(!containsPosition(newPos)){//if the pusher push to outside of the board + return true; + } + if(wallInCurrentTileMadeByMaren(pos,dirToPush)){ + return false; + } + + return true; + //TODO hva om to roboter vil til samme felt samtidig? + + } + + /* @Override + public Map robotVisitFlag(){ + Map robotWhoVisitedFlag = new HashMap<>(); + for(int i=0; i getCell(Vector2 a) { @@ -420,4 +463,14 @@ public TreeSet getCell(Vector2 a) { public RobotTile[] getRobots() { return robots; } + /* private boolean wallInCurrentTileMadeByMaren(Vector2 robotPos, DIRECTION dir) { + for (ICell item : grid[(int) robotPos.x][(int) robotPos.y]) { + if (item instanceof Wall) { + return (((Wall) item).getDirection() == dir.reverse()); + } + } + return false; + }*/ + + } diff --git a/src/main/java/sky7/board/IBoard.java b/src/main/java/sky7/board/IBoard.java index 59bff39..a01ce0f 100644 --- a/src/main/java/sky7/board/IBoard.java +++ b/src/main/java/sky7/board/IBoard.java @@ -2,6 +2,7 @@ import com.badlogic.gdx.math.Vector2; import sky7.board.cellContents.Active.Laser; +import sky7.board.cellContents.Active.Pusher; import sky7.board.cellContents.DIRECTION; import sky7.board.cellContents.Inactive.Flag; import sky7.board.cellContents.Inactive.StartPosition; @@ -68,6 +69,12 @@ public interface IBoard { void moveConveyors(); + List getPusherPos(); + + List getPushers(); + + //Map robotVisitFlag(); + TreeSet getCell(Vector2 a); Vector2[] getRobotPos(); diff --git a/src/main/java/sky7/board/cellContents/Active/Laser.java b/src/main/java/sky7/board/cellContents/Active/Laser.java index d8db101..e7322c6 100644 --- a/src/main/java/sky7/board/cellContents/Active/Laser.java +++ b/src/main/java/sky7/board/cellContents/Active/Laser.java @@ -49,7 +49,7 @@ public Texture getStartLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDStartU.png"); } else { - throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } break; case SOUTH: @@ -58,7 +58,7 @@ public Texture getStartLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDStartD.png"); } else { - throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } break; case WEST: @@ -67,7 +67,7 @@ public Texture getStartLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDStartL.png"); } else { - throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } break; case EAST: @@ -76,7 +76,7 @@ public Texture getStartLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDStartR.png"); } else { - throw new IllegalArgumentException("the number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } break; default: @@ -97,7 +97,7 @@ public Texture getLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDVert.png"); } else { - throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } } else if (direction == DIRECTION.EAST || direction == DIRECTION.WEST) { if (numberOfLasers == 1) { @@ -105,10 +105,10 @@ public Texture getLaserTexture() { } else if (numberOfLasers == 2) { texture = new Texture("assets/laser/LaserDHor.png"); } else { - throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } } else { - throw new IllegalArgumentException("The number og laser has invalid value. Should be 1 or 2, was " + numberOfLasers); + throw new IllegalArgumentException("The number of laser has invalid value. Should be 1 or 2, was " + numberOfLasers); } return texture; } @@ -142,7 +142,6 @@ public DIRECTION getDirection() { public static List>> getSuppliers() { List>> suppliers = new ArrayList<>(); - // TODO add laser supplier char[] bools = {'T', 'F'}; int maxNrOfLaserEyes = 2; diff --git a/src/main/java/sky7/board/cellContents/Active/Pusher.java b/src/main/java/sky7/board/cellContents/Active/Pusher.java index 7148123..ab0d333 100644 --- a/src/main/java/sky7/board/cellContents/Active/Pusher.java +++ b/src/main/java/sky7/board/cellContents/Active/Pusher.java @@ -4,10 +4,8 @@ import sky7.board.ICell; import sky7.board.cellContents.DIRECTION; import sky7.board.cellContents.IActive; - import java.util.AbstractMap; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.function.Supplier; @@ -20,7 +18,7 @@ public class Pusher implements IActive { public Pusher(DIRECTION direction, boolean oddPhased) { this.direction = direction; - this.oddPhased = oddPhased; //oddPhased is 1 if it is oddPhased else 0 + this.oddPhased = oddPhased; //oddPhased is true if it is oddPhased else false } @@ -28,15 +26,17 @@ public Pusher(DIRECTION direction, boolean oddPhased) { * Check if the pusher activates in the current phase. * * @param phase the current phase - * @return true if the pusher activates in phase, false otherwise. + * @return true if pusher is oddPhased and phase is odd, or if pusher is not oddPhased and phase is equal, + * false otherwise. */ - boolean doActivate(int phase) { + + public boolean doActivate(int phase) { assert phase > 0 && phase < 5; - return phase % 2 == 1 && oddPhased; + return (phase % 2 == 1 && oddPhased) || (phase % 2 == 0 && !oddPhased); } @Override - public Texture getTexture() {//TODO change image 8.png , this is the same as 1.png + public Texture getTexture() { if (texture == null) { if (!oddPhased) { switch (direction) { @@ -94,7 +94,7 @@ public int compareTo(ICell other) { } /** - * return the direction of this pusher + * return the direction of where the pusher push into * * @return */ diff --git a/src/main/java/sky7/board/cellContents/Inactive/Flag.java b/src/main/java/sky7/board/cellContents/Inactive/Flag.java index 4977615..7212e06 100644 --- a/src/main/java/sky7/board/cellContents/Inactive/Flag.java +++ b/src/main/java/sky7/board/cellContents/Inactive/Flag.java @@ -66,4 +66,7 @@ public static List>> getSuppliers return suppliers; } + public int getFlagNumber(){ + return this.flagNumber; + } } diff --git a/src/main/java/sky7/board/cellContents/Inactive/StartPosition.java b/src/main/java/sky7/board/cellContents/Inactive/StartPosition.java index d2972ca..b2bc7f3 100644 --- a/src/main/java/sky7/board/cellContents/Inactive/StartPosition.java +++ b/src/main/java/sky7/board/cellContents/Inactive/StartPosition.java @@ -14,11 +14,9 @@ public class StartPosition implements IInactive { private int startNumber; private static final int PRIORITY = 3; private Texture texture; - private DIRECTION direction; public StartPosition(int startNumber) { this.startNumber = startNumber; - } diff --git a/src/main/java/sky7/game/Game.java b/src/main/java/sky7/game/Game.java index 6f7cfea..cd4d0ba 100644 --- a/src/main/java/sky7/game/Game.java +++ b/src/main/java/sky7/game/Game.java @@ -7,6 +7,7 @@ import sky7.board.ICell; import sky7.board.cellContents.Active.CogWheel; import sky7.board.cellContents.Active.Laser; +import sky7.board.cellContents.Active.Pusher; import sky7.board.cellContents.DIRECTION; import sky7.board.cellContents.Inactive.Flag; import sky7.board.cellContents.Inactive.Hole; @@ -57,6 +58,7 @@ public void process(HashMap> playerRegistrys) { destroyedRobots = new ArrayList<>(); Queue> allPhases = findPlayerSequence(playerRegistrys); int count = 0; + int phaseNr =1; for (Queue phase : allPhases) { System.out.println("phase: " + count++); for (Event action : phase) { @@ -64,13 +66,14 @@ public void process(HashMap> playerRegistrys) { tryToMove(action); expressConveyor(); normalAndExpressConveyor(); - activatePushers(); + activatePushers(phaseNr); activateCogwheels(); activateLasers(); placeBackup(); flags(); if (foundWinner()) break; } + phaseNr++; } //after 5th phaze repairRobotsOnRepairSite(); @@ -165,7 +168,6 @@ private void fireLasers(List heads, List positions) { render(20); List> next = moveLaserHeads(heads, positions); - fireLasers(next.get(0), next.get(1)); hide(heads, positions); @@ -189,12 +191,12 @@ private List> moveLaserHeads(List heads, List positions) { Laser laser = (Laser) cell; nextHeads.add(new Laser(false, laser.getDirection(), laser.nrOfLasers())); nextHeadPositions.add(board.getDestination(position, laser.getDirection(), 1)); - } else if (cell instanceof RobotTile) { RobotTile robot = (RobotTile) cell; + } else if (cell instanceof RobotTile) { // TODO modifity the number of lasers for a robot when implemented. nextHeads.add(new Laser(false, robot.getOrientation(), 1)); - nextHeadPositions.add(board.getDestination(position, robot.getOrientation(), 1)); } + nextHeadPositions.add(board.getDestination(position, robot.getOrientation(), 1)); } } @@ -217,8 +219,8 @@ private boolean laserStopped(ICell cell, Vector2 pos) { } if (ahead == null || !board.containsPosition(ahead)) { return true; - } else { for (ICell aheadCell : board.getCell(ahead)) { + } else { if (aheadCell instanceof Wall) return true; if (aheadCell instanceof RobotTile) { applyDamage(((RobotTile)aheadCell).getId(), 1); // apply 1 damage @@ -228,8 +230,8 @@ private boolean laserStopped(ICell cell, Vector2 pos) { } return false; } - private void hide(List lasers, List laserPos) { + // hide all lasers in the list. for (int i = 0; i < laserPos.size(); i++) { Vector2 pos = (Vector2) laserPos.get(i); @@ -238,15 +240,15 @@ private void hide(List lasers, List laserPos) { board.removeCell(cell, pos); } } - } + } private void show(List lasers, List laserPos) { // show all lasers in the list. for (int i = 0; i < lasers.size(); i++) { Object cell = lasers.get(i); if (cell instanceof Laser) { - Laser laser = (Laser) cell; + Laser laser = (Laser) cell; if (!laser.isStartPosition()) { Vector2 pos = (Vector2) laserPos.get(i); board.addCell(laser, pos); @@ -255,9 +257,31 @@ private void show(List lasers, List laserPos) { } } - private void activatePushers() { - //TODO - render(50); + private void activatePushers(int phaseNr) { + for (int i = 0; i < board.getRobots().length; i++) { + for (ICell cell : board.getCell(board.getRobotPos()[i])) { + if(cell instanceof Pusher){ + if(((Pusher) cell).doActivate(phaseNr)){ + if(robotCanGo(board.getRobots()[i].getId(), board.getPushers().get(i).getDirection())){ + movePlayer(board.getRobots()[i].getId(), board.getPushers().get(i).getDirection()); + } + } + } + } + } + /* + for(int i=0; i