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

Merge branch 'IHM-Table/fix-fake-attack' into 'develop'

Ihm table/fix fake attack

See merge request !164
parents 300cd316 d9335c99
......@@ -292,7 +292,7 @@ public class GameMediator {
if (this.currentGame.getComputerPlayer().getFocus() != null) {
}
}
Random r = new Random();
if(r.nextInt(6)==1){
this.sendMessageIA();
......@@ -301,7 +301,7 @@ public class GameMediator {
} else {
// In the case of a test, that's possible that the current player is not
// the right player to test the mine (that means the enemy of the player
// the right player to test the mine (that means the enemy of the player
// is the right person to test the mine)
if (playerWhoPutTheMine != null) {
pairReturn = this.currentGame.attack(playerWhoPutTheMine, coordinate, isTrueAttack);
......@@ -432,32 +432,32 @@ public class GameMediator {
punchlines.add("Aie...");
punchlines.add("><");
punchlines.add("Je t'aurais un de ces jours.");
Random r = new Random();
int i = r.nextInt(punchlines.size());
String text = punchlines.get(i);
//get information of sender
LightPublicUser sender = this.currentGame.getComputerPlayer().getLightPublicUser();
//check if sender is spectator and if chat is allowed for spectators
if (!this.currentGame.getStatGame().isSpectatorChat()) {
return;
}
Message msg = new Message(sender, text, this.currentGame.getRecipients(this.dataFacade.getMyPublicUserProfile().getPlayerName()));
ComFacade comFacade = this.dataFacade.getComfacade();
if (comFacade != null) {
comFacade.notifyNewMessage(msg);
}
this.forwardMessage(msg);
System.out.println("IA send message end");
}
/**
* Forward a message
*
......
......@@ -161,7 +161,10 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
LightPublicUser user = facadeData.getMyPublicUserProfile().getLightPublicUser();
for(int i=0;i<game.getPlayers().size() && startSpectateur;++i)
if(game.getPlayers().get(i).getLightPublicUser().getId().equals(user.getId()))
startSpectateur = false;
{
System.out.println(game.getPlayers().get(i).getLightPublicUser().getId() + " " + user.getId());
startSpectateur = false;
}
System.out.println(startSpectateur);
if(startSpectateur && controller != null)
{
......
......@@ -73,16 +73,16 @@ public class InGameGUIController {
//association ship <=> image
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
ArrayList<Ship> listOfDestroyedShips = new ArrayList<Ship>();
//Associative Map (not HashMap because hashcode different with Coordinate) foreach grid
ArrayList<Coordinate> minesCoordinatesGrid1 = new ArrayList<Coordinate>();
ArrayList<AnchorPane> minesAnchorPaneGrid1 = new ArrayList<AnchorPane>();
ArrayList<Coordinate> minesCoordinatesGrid2 = new ArrayList<Coordinate>();
ArrayList<AnchorPane> minesAnchorPaneGrid2 = new ArrayList<AnchorPane>();
/**
* IHMTable façade
......@@ -461,8 +461,8 @@ public class InGameGUIController {
nbTotalPassedTurns = 0;
}
// Init current player's stats of the match
currentPlayerStats = new InGameStats();
// Init opponent's stats of the match
......@@ -574,8 +574,8 @@ public class InGameGUIController {
}
}
}
/**
* Function to place a ship on the grid with its corresponding image
* @param ship : the ship to place
......@@ -801,13 +801,13 @@ void onClickFire(MouseEvent event) {
return result;
}
/**
* Get the Node in the grid according to its positions
* @param row
* @param column
* @param gridPane
* @param cssClass
* @param cssClass
* @return
*/
private Node getNodeByRowColumnIndexAndCSSClass(final int row, final int column, GridPane gridPane, String cssClass)
......@@ -827,10 +827,10 @@ void onClickFire(MouseEvent event) {
return result;
}
/**
* Place a mine graphically
* Place a mine graphically
* @param x
* @param y
* @param class : css class associated
......@@ -850,7 +850,7 @@ void onClickFire(MouseEvent event) {
minesCoordinates = minesCoordinatesGrid2;
minesAnchorPane = minesAnchorPaneGrid2;
}
//Si une mine est déjà présente (cas spectateur rejoint en cours)
Coordinate coord = new Coordinate(x,y);
if(minesCoordinates.contains(coord))
......@@ -868,14 +868,14 @@ void onClickFire(MouseEvent event) {
minesCoordinates.remove(index);
minesAnchorPane.remove(index);
}
}
//Ajout d'une mine (image d'une mine dans un bouton)
Button b = new Button();
b.setStyle("-fx-background-color: none;"
+ "-fx-background-repeat: stretch;"
+ "-fx-background-position: center center;"
......@@ -896,8 +896,8 @@ void onClickFire(MouseEvent event) {
minesCoordinates.add(coord);
minesAnchorPane.add(wrapper);
}
/**
* Generic method for placing a mine on the grid just with the coordinates
* @param coord : where to place the mine
......@@ -908,13 +908,15 @@ void onClickFire(MouseEvent event) {
//System.out.println("TABLE: ON PLACE UNE MINE EN " + coord.getX() + " " + coord.getY());
// Select the right grid which depends on the player
GridPane grid;
//Cas non spectateur (J1 ou J2)
if(!isSpectator)
{
System.out.println("Je suis pas un spectateur");
if(player.getLightPublicUser().getId().equals(facade.getFacadeData().getMyPublicUserProfile().getId())) {
grid = opponentGrid;
// Reset the number of turns passed for J1.
nbPassedTurns = 0;
} else {
grid = playerGrid;
}
......@@ -922,7 +924,7 @@ void onClickFire(MouseEvent event) {
//Cas spectateur
else
{
System.out.println("Je suis un spectateur");
if(player.equals(facade.getFacadeData().getGame().getPlayers().get(0))) //Current Player is J1 (cf Slack)
{
......@@ -944,16 +946,16 @@ void onClickFire(MouseEvent event) {
{
throw new UnsupportedOperationException("ERROR: attack returned null ");
}
//data from attack
boolean touched = attack_result.getKey() == 1;
boolean newShipDestroyed = attack_result.getValue() != null && !listOfDestroyedShips.contains(attack_result.getValue());
//If a mine did touch
if (touched) {
// Ship Touched!
placeMineGraphics(grid, coord.getX(), coord.getY(), "inGameGUI_touched_cell");
// Check if the ship is destroyed.
Ship destroyedShip = attack_result.getValue();
if(destroyedShip != null) {
......@@ -966,14 +968,12 @@ void onClickFire(MouseEvent event) {
destroyShip(destroyedShip, grid);
}
// Reset the number of turns passed.
nbPassedTurns = 0;
} else {
placeMineGraphics(grid,coord.getX(), coord.getY(), "inGameGUI_missed_cell");
}
hitCell.toFront();
// Update stats pannel
InGameStats statsToUpdate = null;
if(grid == opponentGrid){
......@@ -1185,10 +1185,6 @@ void onClickFire(MouseEvent event) {
* Function for initialize chrono
*/
private void chronoTimeInit() {
// Stop the timer.
if (timer != null) {
timer.stop();
}
switch (nbPassedTurns) {
case 0:
countdown = 30;
......@@ -1217,7 +1213,7 @@ void onClickFire(MouseEvent event) {
if(timer!=null){
timer.playFromStart();
}
}
/**
......@@ -1246,7 +1242,7 @@ void onClickFire(MouseEvent event) {
nbTotalPassedTurns--;
// Fake an attack.
facade.getFacadeData().attack(new Coordinate(nbTotalPassedTurns, nbTotalPassedTurns), true, null);
facade.getFacadeData().attack(new Coordinate(nbTotalPassedTurns, nbTotalPassedTurns), true, myPlayer);
// Reinitialize chrono for the next turn
chronoTimeInit();
......@@ -1511,7 +1507,7 @@ void onClickFire(MouseEvent event) {
// Put the image on the board
putShipOnBoard(ship, playerGrid);
// 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
......@@ -1568,7 +1564,7 @@ void onClickFire(MouseEvent event) {
public void loadGame(Game game)
{
System.out.println("TABLE: ON LIT UNE GAME PAR UN SPECTATEUR");
// Place ships (disabled to avoid cheating)
/*for (Player player : game.getPlayers()) {
for (Ship ship : player.getShips()) {
......@@ -1609,7 +1605,7 @@ void onClickFire(MouseEvent event) {
cell.getStyleClass().add("inGameGUI_missed_cell");
}
cell.toFront();
// Ship destroyed.
if (destroyedShip != null) {
// Change the CSS class of the cells.
......@@ -1639,6 +1635,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