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

opponentHasLeftGame + refacto popup

parent d55ba504
......@@ -5,6 +5,7 @@
*/
package com.utclo23.ihmtable;
import com.utclo23.data.facade.DataFacade;
import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.StatGame;
import com.utclo23.data.facade.IDataIHMTable;
......@@ -205,11 +206,21 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
/**
* Display the new stats of the player.
* @param stGame : ths stats
* @param stGame : the stats
*/
@Override
public void finishGame(StatGame stGame) {
controller.displayFinishPopup(stGame.getWinner().getPlayerName());
String sMessage;
// Game lost.
if(!stGame.getWinner().getPlayerName().equals(facadeData.getMyPublicUserProfile().getPlayerName()))
{
sMessage = "Defeat! You should train against AI! Hahahah!";
} else {
// Game won.
sMessage = "Victory! I'm proud of you General!";
}
// Display popup.
controller.displayFinishPopup(sMessage);
}
/**
......@@ -217,7 +228,8 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
*/
@Override
public void opponentHasLeftGame() {
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
// Display popup.
controller.displayFinishPopup("Your opponent has left this game!");
}
/**
......@@ -225,7 +237,7 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
*/
@Override
public void connectionLostWithOpponent() {
controller.popupConnectionLost();
controller.displayFinishPopup("Connection has been lost with your opponent");
}
/**
......
......@@ -671,19 +671,14 @@ public class InGameGUIController {
placeMine(m.getCoord(), p);
}
/**
* Method to display popup asking the player to save the game !
* @param winner
* Method to display popup asking the player to save the game.
* @param sMessage
*/
public void displayFinishPopup(String winner) {
String sMessage = "Victory! I'm proud of you General!";
if(!winner.equals(facade.getFacadeData().getMyPublicUserProfile().getPlayerName()))
{
sMessage = "Defeat! You should train against AI! Hahahah!";
}
public void displayFinishPopup(String sMessage) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("End of the Game");
alert.setHeaderText(sMessage + "\n" + winner +"wins this one!!!\n");
alert.setHeaderText(sMessage);
alert.setContentText("Do you want to save this game?");
Optional<ButtonType> result = alert.showAndWait();
......@@ -693,6 +688,7 @@ public class InGameGUIController {
}
try {
// Go back to the menu.
facade.getFacadeIHMMain().toMenu();
} catch (IOException ex) {
Logger.getLogger(InGameGUIController.class.getName()).log(Level.SEVERE, null, ex);
......@@ -1152,28 +1148,4 @@ public class InGameGUIController {
node.getStyleClass().add("inGameGUI_destroyed_cell");
}
}
/**
* Popup displayed when the opponent lost his connection.
*/
public void popupConnectionLost() {
// Create the popup.
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Connection lost");
alert.setHeaderText("Connection has been lost with your opponent");
alert.setContentText("Do you want to save this game?");
Optional<ButtonType> result = alert.showAndWait();
// Click on OK.
if (result.get() == ButtonType.OK){
// TODO: save the game.
}
try {
// Go back to the menu.
facade.getFacadeIHMMain().toMenu();
} catch (IOException ex) {
Logger.getLogger(InGameGUIController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
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