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
0f26b285
Commit
0f26b285
authored
Jan 02, 2018
by
dkonam
Browse files
Data | fix remove game
parent
9753b18e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Battleship/src/main/java/com/utclo23/data/module/GameMediator.java
View file @
0f26b285
...
...
@@ -98,9 +98,8 @@ public class GameMediator {
//creat Game for realGame
Game
game
=
this
.
gameFactory
.
createGame
(
name
,
creator
,
computerMode
,
spectator
,
spectatorChat
,
type
);
this
.
addNewGame
(
game
.
getStatGame
());
this
.
addNewGame
(
game
.
getStatGame
());
//to Com : notify a new game
ComFacade
comFacade
=
this
.
dataFacade
.
getComfacade
();
if
(
comFacade
!=
null
&&
game
!=
null
)
{
...
...
@@ -249,6 +248,15 @@ public class GameMediator {
if
(
this
.
currentGame
.
isComputerGame
()
&&
this
.
currentGame
.
isGameFinishedByCurrentPlayer
())
{
this
.
dataFacade
.
getUserMediator
().
addPlayedGame
(
this
.
currentGame
.
getStatGame
());
this
.
dataFacade
.
getIhmTablefacade
().
finishGame
(
this
.
currentGame
.
getStatGame
());
//if creator => delete game
if
(
this
.
currentGame
.
getStatGame
().
getCreator
().
getId
().
equals
(
this
.
dataFacade
.
getMyPublicUserProfile
().
getId
()))
{
Logger
.
getLogger
(
GameMediator
.
class
.
getName
()).
info
(
"delete game by creator after leave game"
);
this
.
dataFacade
.
getComfacade
().
removeGame
(
this
.
currentGame
.
getId
());
this
.
removeGame
(
this
.
getCurrentGame
().
getId
());
}
return
null
;
}
...
...
@@ -430,17 +438,16 @@ public class GameMediator {
if
(
this
.
currentGame
.
getStatGame
().
getWinner
()
==
null
)
{
this
.
giveUp
();
}
//if creator => delete game
if
(
this
.
currentGame
.
getStatGame
().
getCreator
().
getId
().
equals
(
this
.
dataFacade
.
getMyPublicUserProfile
().
getId
()))
{
if
(
this
.
currentGame
.
getStatGame
().
getCreator
().
getId
().
equals
(
this
.
dataFacade
.
getMyPublicUserProfile
().
getId
()))
{
Logger
.
getLogger
(
GameMediator
.
class
.
getName
()).
info
(
"delete game by creator after leave game"
);
this
.
dataFacade
.
getComfacade
().
removeGame
(
this
.
currentGame
.
getId
());
this
.
removeGame
(
this
.
getCurrentGame
().
getId
());
}
}
}
...
...
@@ -526,6 +533,14 @@ public class GameMediator {
}
this
.
dataFacade
.
getIhmTablefacade
().
finishGame
(
this
.
currentGame
.
getStatGame
());
//if creator => delete game
if
(
this
.
currentGame
.
getStatGame
().
getCreator
().
getId
().
equals
(
this
.
dataFacade
.
getMyPublicUserProfile
().
getId
()))
{
Logger
.
getLogger
(
GameMediator
.
class
.
getName
()).
info
(
"delete game by creator after leave game"
);
this
.
dataFacade
.
getComfacade
().
removeGame
(
this
.
currentGame
.
getId
());
this
.
removeGame
(
this
.
getCurrentGame
().
getId
());
}
}
}
...
...
@@ -535,20 +550,19 @@ public class GameMediator {
private
void
giveUp
()
{
String
ownerID
=
this
.
dataFacade
.
getUserMediator
().
getMyPublicUserProfile
().
getId
();
Player
opponent
=
this
.
currentGame
.
ennemyOf
(
this
.
currentGame
.
getPlayer
(
ownerID
));
if
(
opponent
!=
null
)
this
.
currentGame
.
getStatGame
().
setWinner
(
opponent
.
getLightPublicUser
());
if
(
opponent
!=
null
)
{
this
.
currentGame
.
getStatGame
().
setWinner
(
opponent
.
getLightPublicUser
());
}
}
public
void
removeGame
(
String
id
)
{
if
(
this
.
gamesMap
.
containsKey
(
id
))
{
public
void
removeGame
(
String
id
)
{
if
(
this
.
gamesMap
.
containsKey
(
id
))
{
this
.
gamesMap
.
remove
(
id
);
Logger
.
getLogger
(
"GameMediator"
).
info
(
"delete "
+
id
);
Logger
.
getLogger
(
"GameMediator"
).
info
(
"delete "
+
id
);
}
}
/**
* Win if the game has no winner yet.
*
...
...
Write
Preview
Supports
Markdown
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