Commit 6dd41f8c authored by Quentin DRUAULT-AUBIN's avatar Quentin DRUAULT-AUBIN
Browse files

[Table] Fix reset

parent 8c926837
...@@ -73,16 +73,16 @@ public class InGameGUIController { ...@@ -73,16 +73,16 @@ public class InGameGUIController {
//association ship <=> image //association ship <=> image
Map<Ship, Button> listOfShipsOnTheGrid = new HashMap<Ship, Button>(); Map<Ship, Button> listOfShipsOnTheGrid = new HashMap<Ship, Button>();
//Memorize destroyed ships so that spectators don't count their destruction multiple times while replaying an ongoing game //Memorize destroyed ships so that spectators don't count their destruction multiple times while replaying an ongoing game
ArrayList<Ship> listOfDestroyedShips = new ArrayList<Ship>(); ArrayList<Ship> listOfDestroyedShips = new ArrayList<Ship>();
//Associative Map (not HashMap because hashcode different with Coordinate) foreach grid //Associative Map (not HashMap because hashcode different with Coordinate) foreach grid
ArrayList<Coordinate> minesCoordinatesGrid1 = new ArrayList<Coordinate>(); ArrayList<Coordinate> minesCoordinatesGrid1 = new ArrayList<Coordinate>();
ArrayList<AnchorPane> minesAnchorPaneGrid1 = new ArrayList<AnchorPane>(); ArrayList<AnchorPane> minesAnchorPaneGrid1 = new ArrayList<AnchorPane>();
ArrayList<Coordinate> minesCoordinatesGrid2 = new ArrayList<Coordinate>(); ArrayList<Coordinate> minesCoordinatesGrid2 = new ArrayList<Coordinate>();
ArrayList<AnchorPane> minesAnchorPaneGrid2 = new ArrayList<AnchorPane>(); ArrayList<AnchorPane> minesAnchorPaneGrid2 = new ArrayList<AnchorPane>();
/** /**
* IHMTable façade * IHMTable façade
...@@ -461,8 +461,8 @@ public class InGameGUIController { ...@@ -461,8 +461,8 @@ public class InGameGUIController {
nbTotalPassedTurns = 0; nbTotalPassedTurns = 0;
} }
// Init current player's stats of the match // Init current player's stats of the match
currentPlayerStats = new InGameStats(); currentPlayerStats = new InGameStats();
// Init opponent's stats of the match // Init opponent's stats of the match
...@@ -574,8 +574,8 @@ public class InGameGUIController { ...@@ -574,8 +574,8 @@ public class InGameGUIController {
} }
} }
} }
/** /**
* Function to place a ship on the grid with its corresponding image * Function to place a ship on the grid with its corresponding image
* @param ship : the ship to place * @param ship : the ship to place
...@@ -801,13 +801,13 @@ void onClickFire(MouseEvent event) { ...@@ -801,13 +801,13 @@ void onClickFire(MouseEvent event) {
return result; return result;
} }
/** /**
* Get the Node in the grid according to its positions * Get the Node in the grid according to its positions
* @param row * @param row
* @param column * @param column
* @param gridPane * @param gridPane
* @param cssClass * @param cssClass
* @return * @return
*/ */
private Node getNodeByRowColumnIndexAndCSSClass(final int row, final int column, GridPane gridPane, String cssClass) private Node getNodeByRowColumnIndexAndCSSClass(final int row, final int column, GridPane gridPane, String cssClass)
...@@ -827,10 +827,10 @@ void onClickFire(MouseEvent event) { ...@@ -827,10 +827,10 @@ void onClickFire(MouseEvent event) {
return result; return result;
} }
/** /**
* Place a mine graphically * Place a mine graphically
* @param x * @param x
* @param y * @param y
* @param class : css class associated * @param class : css class associated
...@@ -850,7 +850,7 @@ void onClickFire(MouseEvent event) { ...@@ -850,7 +850,7 @@ void onClickFire(MouseEvent event) {
minesCoordinates = minesCoordinatesGrid2; minesCoordinates = minesCoordinatesGrid2;
minesAnchorPane = minesAnchorPaneGrid2; minesAnchorPane = minesAnchorPaneGrid2;
} }
//Si une mine est déjà présente (cas spectateur rejoint en cours) //Si une mine est déjà présente (cas spectateur rejoint en cours)
Coordinate coord = new Coordinate(x,y); Coordinate coord = new Coordinate(x,y);
if(minesCoordinates.contains(coord)) if(minesCoordinates.contains(coord))
...@@ -868,14 +868,14 @@ void onClickFire(MouseEvent event) { ...@@ -868,14 +868,14 @@ void onClickFire(MouseEvent event) {
minesCoordinates.remove(index); minesCoordinates.remove(index);
minesAnchorPane.remove(index); minesAnchorPane.remove(index);
} }
} }
//Ajout d'une mine (image d'une mine dans un bouton) //Ajout d'une mine (image d'une mine dans un bouton)
Button b = new Button(); Button b = new Button();
b.setStyle("-fx-background-color: none;" b.setStyle("-fx-background-color: none;"
+ "-fx-background-repeat: stretch;" + "-fx-background-repeat: stretch;"
+ "-fx-background-position: center center;" + "-fx-background-position: center center;"
...@@ -896,8 +896,8 @@ void onClickFire(MouseEvent event) { ...@@ -896,8 +896,8 @@ void onClickFire(MouseEvent event) {
minesCoordinates.add(coord); minesCoordinates.add(coord);
minesAnchorPane.add(wrapper); minesAnchorPane.add(wrapper);
} }
/** /**
* Generic method for placing a mine on the grid just with the coordinates * Generic method for placing a mine on the grid just with the coordinates
* @param coord : where to place the mine * @param coord : where to place the mine
...@@ -908,13 +908,15 @@ void onClickFire(MouseEvent event) { ...@@ -908,13 +908,15 @@ void onClickFire(MouseEvent event) {
//System.out.println("TABLE: ON PLACE UNE MINE EN " + coord.getX() + " " + coord.getY()); //System.out.println("TABLE: ON PLACE UNE MINE EN " + coord.getX() + " " + coord.getY());
// Select the right grid which depends on the player // Select the right grid which depends on the player
GridPane grid; GridPane grid;
//Cas non spectateur (J1 ou J2) //Cas non spectateur (J1 ou J2)
if(!isSpectator) if(!isSpectator)
{ {
System.out.println("Je suis pas un spectateur"); System.out.println("Je suis pas un spectateur");
if(player.getLightPublicUser().getId().equals(facade.getFacadeData().getMyPublicUserProfile().getId())) { if(player.getLightPublicUser().getId().equals(facade.getFacadeData().getMyPublicUserProfile().getId())) {
grid = opponentGrid; grid = opponentGrid;
// Reset the number of turns passed for J1.
nbPassedTurns = 0;
} else { } else {
grid = playerGrid; grid = playerGrid;
} }
...@@ -922,7 +924,7 @@ void onClickFire(MouseEvent event) { ...@@ -922,7 +924,7 @@ void onClickFire(MouseEvent event) {
//Cas spectateur //Cas spectateur
else else
{ {
System.out.println("Je suis un spectateur"); System.out.println("Je suis un spectateur");
if(player.equals(facade.getFacadeData().getGame().getPlayers().get(0))) //Current Player is J1 (cf Slack) if(player.equals(facade.getFacadeData().getGame().getPlayers().get(0))) //Current Player is J1 (cf Slack)
{ {
...@@ -944,16 +946,16 @@ void onClickFire(MouseEvent event) { ...@@ -944,16 +946,16 @@ void onClickFire(MouseEvent event) {
{ {
throw new UnsupportedOperationException("ERROR: attack returned null "); throw new UnsupportedOperationException("ERROR: attack returned null ");
} }
//data from attack //data from attack
boolean touched = attack_result.getKey() == 1; boolean touched = attack_result.getKey() == 1;
boolean newShipDestroyed = attack_result.getValue() != null && !listOfDestroyedShips.contains(attack_result.getValue()); boolean newShipDestroyed = attack_result.getValue() != null && !listOfDestroyedShips.contains(attack_result.getValue());
//If a mine did touch //If a mine did touch
if (touched) { if (touched) {
// Ship Touched! // Ship Touched!
placeMineGraphics(grid, coord.getX(), coord.getY(), "inGameGUI_touched_cell"); placeMineGraphics(grid, coord.getX(), coord.getY(), "inGameGUI_touched_cell");
// Check if the ship is destroyed. // Check if the ship is destroyed.
Ship destroyedShip = attack_result.getValue(); Ship destroyedShip = attack_result.getValue();
if(destroyedShip != null) { if(destroyedShip != null) {
...@@ -966,14 +968,12 @@ void onClickFire(MouseEvent event) { ...@@ -966,14 +968,12 @@ void onClickFire(MouseEvent event) {
destroyShip(destroyedShip, grid); destroyShip(destroyedShip, grid);
} }
// Reset the number of turns passed.
nbPassedTurns = 0;
} else { } else {
placeMineGraphics(grid,coord.getX(), coord.getY(), "inGameGUI_missed_cell"); placeMineGraphics(grid,coord.getX(), coord.getY(), "inGameGUI_missed_cell");
} }
hitCell.toFront(); hitCell.toFront();
// Update stats pannel // Update stats pannel
InGameStats statsToUpdate = null; InGameStats statsToUpdate = null;
if(grid == opponentGrid){ if(grid == opponentGrid){
...@@ -1217,7 +1217,7 @@ void onClickFire(MouseEvent event) { ...@@ -1217,7 +1217,7 @@ void onClickFire(MouseEvent event) {
if(timer!=null){ if(timer!=null){
timer.playFromStart(); timer.playFromStart();
} }
} }
/** /**
...@@ -1511,7 +1511,7 @@ void onClickFire(MouseEvent event) { ...@@ -1511,7 +1511,7 @@ void onClickFire(MouseEvent event) {
// Put the image on the board // Put the image on the board
putShipOnBoard(ship, playerGrid); putShipOnBoard(ship, playerGrid);
// ATTENTION! Grid size is out of control! // ATTENTION! Grid size is out of control!
// setShip didn't return any exception so the ship is correctly placed -> Update the label on the left panel // setShip didn't return any exception so the ship is correctly placed -> Update the label on the left panel
...@@ -1568,7 +1568,7 @@ void onClickFire(MouseEvent event) { ...@@ -1568,7 +1568,7 @@ void onClickFire(MouseEvent event) {
public void loadGame(Game game) public void loadGame(Game game)
{ {
System.out.println("TABLE: ON LIT UNE GAME PAR UN SPECTATEUR"); System.out.println("TABLE: ON LIT UNE GAME PAR UN SPECTATEUR");
// Place ships (disabled to avoid cheating) // Place ships (disabled to avoid cheating)
/*for (Player player : game.getPlayers()) { /*for (Player player : game.getPlayers()) {
for (Ship ship : player.getShips()) { for (Ship ship : player.getShips()) {
...@@ -1609,7 +1609,7 @@ void onClickFire(MouseEvent event) { ...@@ -1609,7 +1609,7 @@ void onClickFire(MouseEvent event) {
cell.getStyleClass().add("inGameGUI_missed_cell"); cell.getStyleClass().add("inGameGUI_missed_cell");
} }
cell.toFront(); cell.toFront();
// Ship destroyed. // Ship destroyed.
if (destroyedShip != null) { if (destroyedShip != null) {
// Change the CSS class of the cells. // Change the CSS class of the cells.
...@@ -1639,6 +1639,6 @@ void onClickFire(MouseEvent event) { ...@@ -1639,6 +1639,6 @@ void onClickFire(MouseEvent event) {
} }
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment