Commit d1b43e89 authored by Theo Boulaire's avatar Theo Boulaire
Browse files

Working with game's replay : saving.

parent 1271aa47
......@@ -747,4 +747,22 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons() ;
}
/**
* Saves the current game.
*
* @throws DataException
*/
public void saveGame() throws DataException {
this.userMediator.addSavedGame(this.gameMediator.getCurrentGame());
}
public void replayGame(String idGame) {
Game game = this.userMediator.getSavedGame(idGame);
this.gameMediator.setCurrentGame(game);
}
public void replayNextTurn() {
}
}
......@@ -567,6 +567,10 @@ public class UserMediator {
}
}
public Game getSavedGame(String id) {
return this.owner.getSavedGame(id);
}
/**
* Add a played game to the owner's played games list.
*
......@@ -576,6 +580,18 @@ public class UserMediator {
this.owner.addPlayedGame(game);
}
/**
* Add a saved game to the owner's saved games list and save the owner.
*
* @param game Game
* @throws DataException
*/
public void addSavedGame(Game game) throws DataException {
game.init();
this.owner.addSavedGame(game);
this.save();
}
/**
* Update user
*
......
......@@ -529,4 +529,10 @@ public abstract class Game extends SerializableEntity {
}
return null;
}
public void init() {
this.messages.clear();
this.players.get(0).clearMines();
this.players.get(1).clearMines();
}
}
......@@ -146,6 +146,16 @@ public class Owner extends SerializableEntity{
this.savedGamesList = savedGamesList;
}
public Game getSavedGame(String id) {
Game ret = null;
for(Game g : this.savedGamesList) {
if(g.getId().equals(id)) {
ret = g;
}
}
return ret;
}
public List<StatGame> getPlayedGamesList() {
return playedGamesList;
}
......@@ -166,7 +176,9 @@ public class Owner extends SerializableEntity{
this.playedGamesList.add(game);
}
public void addSavedGame(Game game) {
this.savedGamesList.add(game);
}
}
......@@ -59,5 +59,8 @@ public class Player extends SerializableEntity{
this.computer = computer;
}
public void clearMines() {
this.mines.clear();
}
}
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