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

[Ship] Feedback on the grid

parent 7d1f4a1e
...@@ -10,6 +10,7 @@ import com.utclo23.data.structure.StatGame; ...@@ -10,6 +10,7 @@ import com.utclo23.data.structure.StatGame;
import com.utclo23.data.facade.IDataIHMTable; import com.utclo23.data.facade.IDataIHMTable;
import com.utclo23.data.structure.Game; import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.LightPublicUser; import com.utclo23.data.structure.LightPublicUser;
import com.utclo23.data.structure.Ship;
import com.utclo23.ihmmain.controller.AbstractController; import com.utclo23.ihmmain.controller.AbstractController;
import com.utclo23.ihmmain.facade.IHMMainToIhmTable; import com.utclo23.ihmmain.facade.IHMMainToIhmTable;
import com.utclo23.ihmtable.controller.InGameGUIController; import com.utclo23.ihmtable.controller.InGameGUIController;
...@@ -193,10 +194,12 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData { ...@@ -193,10 +194,12 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
/** /**
* Show on the board if the shot has hit or not a ship. * Show on the board if the shot has hit or not a ship.
* @param coord : the coordinates of the hit. * @param coord : the coordinates of the hit.
* @param bool : true if a ship is hit. * @param touched : true if a ship is hit.
* @param destroyedShip : destroyed ship or null.
*/ */
@Override @Override
public void feedBack(Coordinate coord, boolean bool) { public void feedBack(Coordinate coord, boolean touched, Ship destroyedShip) {
controller.displayOpponentAttack(coord, touched, destroyedShip);
controller.timeToAttack(); controller.timeToAttack();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package com.utclo23.ihmtable; package com.utclo23.ihmtable;
import com.utclo23.data.structure.Coordinate; import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.Ship;
import com.utclo23.data.structure.StatGame; import com.utclo23.data.structure.StatGame;
/** /**
...@@ -15,7 +16,7 @@ import com.utclo23.data.structure.StatGame; ...@@ -15,7 +16,7 @@ import com.utclo23.data.structure.StatGame;
public interface IIHMTableToData { public interface IIHMTableToData {
public void notifyGameReady(); public void notifyGameReady();
public void printMessage(String message); public void printMessage(String message);
public void feedBack(Coordinate coord, boolean bool); public void feedBack(Coordinate coord, boolean bool, Ship destroyedShip);
public void finishGame(StatGame stGame); public void finishGame(StatGame stGame);
public void opponentHasLeftGame(); public void opponentHasLeftGame();
public void connectionLostWithOpponent(); public void connectionLostWithOpponent();
......
...@@ -1017,4 +1017,35 @@ public class InGameGUIController { ...@@ -1017,4 +1017,35 @@ public class InGameGUIController {
} }
} }
} }
/**
* Display the opponent attack on the player grid.
* @param coord : attacked cell
* @param touched : true if touched
* @param destroyedShip : the destroyed ship or null.
*/
public void displayOpponentAttack(Coordinate coord, boolean touched, Ship destroyedShip) {
// Get the cell.
Node cell = getNodeByRowColumnIndex(coord.getX(), coord.getY(), playerGrid);
// The opponent has touched my ship.
if (touched) {
// Add the CSS class.
cell.getStyleClass().add("inGameGUI_touched_cell");
} else {
// The opponent has missed.
cell.getStyleClass().add("inGameGUI_missed_cell");
}
// Ship destroyed.
if (destroyedShip != null) {
// Change the opacity.
listOfShipsOnTheGrid.get(destroyedShip).setOpacity(0.5);
// Change the CSS class of the cells.
for (Coordinate coordinate : destroyedShip.getListCoord()) {
Node node = getNodeByRowColumnIndex(coordinate.getY(), coordinate.getX(), playerGrid);
node.getStyleClass().removeAll("inGameGUI_touched_cell");
node.getStyleClass().add("inGameGUI_destroyed_cell");
}
}
}
} }
Supports Markdown
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