Commit 69562b53 authored by dkonam's avatar dkonam
Browse files

Merge branch 'Data/testEndGame' into Data/develop

parents f208f789 c763b5f5
......@@ -299,6 +299,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
@Override
public void connectionLostWithOpponent() {
this.gameMediator.setWinner(null);
this.gameMediator.getCurrentGame().getStatGame().setGameAbandonned(true);
this.gameMediator.leaveGame();
this.ihmTablefacade.connectionLostWithOpponent();
}
......@@ -673,4 +674,39 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
/**
*
* send number of victories
*
* @return int number of victories
* @throws DataException
*/
@Override
public int getNumberVictories() throws DataException {
return this.userMediator.getNumberVictories() ;
}
/**
*
* send number of defeats
*
* @return int number of defeats
* @throws DataException
*/
@Override
public int getNumberDefeats() throws DataException {
return this.userMediator.getNumberDefeats() ;
}
/**
*
* send number of abandons
*
* @return int number of abandons
* @throws DataException
*/
@Override
public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons() ;
}
}
......@@ -47,6 +47,8 @@ public interface IDataIHMMain {
public void updateFileImage(String fileImage) throws DataException;
public void updatePassword(String password) throws DataException;
public int getNumberVictories() throws DataException;
public int getNumberDefeats() throws DataException;
public int getNumberAbandons() throws DataException;
}
\ No newline at end of file
......@@ -350,7 +350,7 @@ public class GameMediator {
public void forwardMessage(Message msg) {
IIHMTableToData ihmTablefacade = this.dataFacade.getIhmTablefacade();
if (ihmTablefacade != null) {
ihmTablefacade.printMessage(msg.getContent());
ihmTablefacade.printMessage(msg);
}
}
......@@ -419,11 +419,10 @@ public class GameMediator {
}
if (this.dataFacade.getIhmTablefacade() != null) {
//this.dataFacade.getIhmTablefacade().feedback(mine.getCoord(),touched,shipDestroyed) ;
this.dataFacade.getIhmTablefacade().feedback(mine,touched,shipDestroyed) ;
}
if (this.currentGame.isGameFinishedByEnnemy()) {
// a faire
//Sauvegarde à ajouter, que l'owner soit joueur ou pas.
String status = this.getOwnerStatus();
if(status == "player") {
......@@ -432,7 +431,7 @@ public class GameMediator {
}
this.dataFacade.getUserMediator().addPlayedGame(this.currentGame.getStatGame());
this.currentGame = null;
this.currentGame = null;
}
}
......
......@@ -766,5 +766,60 @@ public class UserMediator {
}
/**
*
* send number of victories
*
* @return int number of victories
* @throws DataException
*/
public int getNumberVictories() throws DataException {
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
return nbVictories ;
}
/**
*
* send number of defeats
*
* @return int number of defeats
* @throws DataException
*/
public int getNumberDefeats() throws DataException {
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
return nbDefeats ;
}
/**
*
* send number of abandons
*
* @return int number of abandons
* @throws DataException
*/
public int getNumberAbandons() throws DataException {
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
return nbAbandons ;
}
}
......@@ -165,4 +165,92 @@ public class AttackTest {
}
@org.junit.Test
public void testEndGame() throws DataException {
DataFacade df = new DataFacade();
df.setTestMode(true);
try {
df.createUser("Xiaodan", "123", "", "", new Date(), "");
} catch (Exception e) {
e.printStackTrace();
df.signin("Xiaodan", "123");
}
df.createGame("TestAttack", false, true, true, GameType.CLASSIC);
//Add another player
LightPublicUser lightPublicUserB = new LightPublicUser("456", "Toto");
df.getGameMediator().getCurrentGame().addUser(lightPublicUserB, "player");
//Coordinate of A's ship
Coordinate coorShipA11 = new Coordinate(1,1);
Coordinate coorShipA12 = new Coordinate(2,1);
Coordinate coorShipA13 = new Coordinate(3,1);
List<Coordinate> coordShipA1 = new ArrayList<>();
coordShipA1.add(coorShipA11);
coordShipA1.add(coorShipA12);
coordShipA1.add(coorShipA13);
//set A's ship
Player playerA = df.getGameMediator().getCurrentGame().getPlayer(df.getUserMediator().getMyPublicUserProfile().getId());
Player playerB = df.getGameMediator().getCurrentGame().ennemyOf(playerA);
Ship shipA1 = new Ship(ShipType.SUBMARINE, playerA, coordShipA1, 3);
List<Ship> shipsA = new ArrayList<>();
shipsA.add(shipA1);
playerA.setShips(shipsA);
//Coordinate of B's ship
Coordinate coorShipB11 = new Coordinate(11,2);
Coordinate coorShipB12 = new Coordinate(12,2);
Coordinate coorShipB13 = new Coordinate(13,2);
List<Coordinate> coordShipB1 = new ArrayList<>();
coordShipB1.add(coorShipB11);
coordShipB1.add(coorShipB12);
coordShipB1.add(coorShipB13);
//set B's ship
Ship shipB1 = new Ship(ShipType.SUBMARINE, playerB, coordShipB1, 3);
List<Ship> shipsB = new ArrayList<>();
shipsB.add(shipB1);
playerB.setShips(shipsB);
//Coordinate of A's mines
Coordinate coorMineA1 = new Coordinate(11,12);
Mine mineA1 = new Mine(playerA, coorMineA1);
Coordinate coorMineA2 = new Coordinate(12,2);
Mine mineA2 = new Mine(playerA, coorMineA2);
Coordinate coorMineA3 = new Coordinate(13,2);
Mine mineA3 = new Mine(playerA, coorMineA3);
//Coordinate of B's mines
Coordinate coorMineB1 = new Coordinate(1,1);
Mine mineB1 = new Mine(playerB, coorMineB1);
Coordinate coorMineB2 = new Coordinate(2,1);
Mine mineB2 = new Mine(playerB, coorMineB2);
Coordinate coorMineB3 = new Coordinate(3,1);
Mine mineB3 = new Mine(playerB, coorMineB3);
df.attack(coorMineA1, true);
df.forwardCoordinates(mineA1);
df.attack(coorMineB1, true);
df.forwardCoordinates(mineB1);
df.attack(coorMineA2, true);
df.forwardCoordinates(mineA2);
df.attack(coorMineB2, true);
df.forwardCoordinates(mineB2);
df.attack(coorMineA3, true);
df.forwardCoordinates(mineA3);
df.attack(coorMineB3, true);
boolean b = df.getGameMediator().getCurrentGame().isGameFinishedByEnnemy() ;
df.forwardCoordinates(mineB3);
int nbVict = df.getNumberVictories() ;
int nbDefeats = df.getNumberDefeats();
int nbAbandons = df.getNumberAbandons() ;
}
}
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