Commit c763b5f5 authored by Gabrielle Spielmann's avatar Gabrielle Spielmann
Browse files

'add_get_stats_methods'

parent f1ca34be
......@@ -674,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
......@@ -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 ;
}
}
......@@ -218,7 +218,7 @@ public class AttackTest {
playerB.setShips(shipsB);
//Coordinate of A's mines
Coordinate coorMineA1 = new Coordinate(11,2);
Coordinate coorMineA1 = new Coordinate(11,12);
Mine mineA1 = new Mine(playerA, coorMineA1);
Coordinate coorMineA2 = new Coordinate(12,2);
Mine mineA2 = new Mine(playerA, coorMineA2);
......@@ -242,8 +242,15 @@ public class AttackTest {
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(mineA3);
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