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 { ...@@ -747,4 +747,22 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
public int getNumberAbandons() throws DataException { public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons() ; 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 { ...@@ -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. * Add a played game to the owner's played games list.
* *
...@@ -576,6 +580,18 @@ public class UserMediator { ...@@ -576,6 +580,18 @@ public class UserMediator {
this.owner.addPlayedGame(game); 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 * Update user
* *
......
...@@ -529,4 +529,10 @@ public abstract class Game extends SerializableEntity { ...@@ -529,4 +529,10 @@ public abstract class Game extends SerializableEntity {
} }
return null; return null;
} }
public void init() {
this.messages.clear();
this.players.get(0).clearMines();
this.players.get(1).clearMines();
}
} }
...@@ -145,6 +145,16 @@ public class Owner extends SerializableEntity{ ...@@ -145,6 +145,16 @@ public class Owner extends SerializableEntity{
public void setSavedGamesList(List<Game> savedGamesList) { public void setSavedGamesList(List<Game> savedGamesList) {
this.savedGamesList = savedGamesList; 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() { public List<StatGame> getPlayedGamesList() {
return playedGamesList; return playedGamesList;
...@@ -166,7 +176,9 @@ public class Owner extends SerializableEntity{ ...@@ -166,7 +176,9 @@ public class Owner extends SerializableEntity{
this.playedGamesList.add(game); this.playedGamesList.add(game);
} }
public void addSavedGame(Game game) {
this.savedGamesList.add(game);
}
} }
...@@ -59,5 +59,8 @@ public class Player extends SerializableEntity{ ...@@ -59,5 +59,8 @@ public class Player extends SerializableEntity{
this.computer = computer; 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