Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Quentin DRUAULT-AUBIN
lo23-project
Commits
d1b43e89
Commit
d1b43e89
authored
Dec 19, 2017
by
Theo Boulaire
Browse files
Working with game's replay : saving.
parent
1271aa47
Changes
5
Hide whitespace changes
Inline
Side-by-side
Battleship/src/main/java/com/utclo23/data/facade/DataFacade.java
View file @
d1b43e89
...
...
@@ -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
()
{
}
}
Battleship/src/main/java/com/utclo23/data/module/UserMediator.java
View file @
d1b43e89
...
...
@@ -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
*
...
...
Battleship/src/main/java/com/utclo23/data/structure/Game.java
View file @
d1b43e89
...
...
@@ -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
();
}
}
Battleship/src/main/java/com/utclo23/data/structure/Owner.java
View file @
d1b43e89
...
...
@@ -145,6 +145,16 @@ public class Owner extends SerializableEntity{
public
void
setSavedGamesList
(
List
<
Game
>
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
()
{
return
playedGamesList
;
...
...
@@ -166,7 +176,9 @@ public class Owner extends SerializableEntity{
this
.
playedGamesList
.
add
(
game
);
}
public
void
addSavedGame
(
Game
game
)
{
this
.
savedGamesList
.
add
(
game
);
}
}
Battleship/src/main/java/com/utclo23/data/structure/Player.java
View file @
d1b43e89
...
...
@@ -59,5 +59,8 @@ public class Player extends SerializableEntity{
this
.
computer
=
computer
;
}
public
void
clearMines
()
{
this
.
mines
.
clear
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment