Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anthony ROZEN
Not Alone
Commits
576670ee
Commit
576670ee
authored
Nov 18, 2020
by
Anthony ROZEN
Committed by
Antoine Guérin
Dec 11, 2020
Browse files
ajout des modifications du projet initial
parent
33b253e7
Changes
9
Hide whitespace changes
Inline
Side-by-side
not-alone-core/src/main/thrift/common.thrift
View file @
576670ee
namespace java fr.univnantes.alma.thrift
namespace js common
namespace js core
exception InvalidOperationException {
1: i32 code,
...
...
not-alone-doc/src/doc/asciidoc/_sections/composants.adoc
View file @
576670ee
...
...
@@ -2,6 +2,44 @@
== Création d'une partie
.Join game
[plantuml]
....
participant "__one:Player__" as player1
participant "__two:Player__" as player2
participant "__three:Player__" as player3
participant "__four:Player__" as player4
participant "__five:Player__" as player5
participant "__six:Player__" as player6
participant "__game:GameServer__" as game
player1 -> game : id := createGame(6)
par
player1 -> game : playerId := join(id, one)
player2 -> game : playerId := join(id, two)
player3 -> game : playerId := join(id, three)
player4 -> game : playerId := join(id, four)
player5 -> game : playerId := join(id, five)
player6 -> game : playerId := join(id, six)
end
....
.Questions ouveres (à faire)
- Les joeurs ne peuvent pas envcoyer juste une `id`, ils doivent aussi envoyer une adress/port pour que le serveur puisse les contacter
- Le serveur doit prévenir les joueurs du début de la partie.
.L'interface GameServer
[plantuml]
....
interface GameServer {
createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer
}
....
notre conception
[.lead]
*Diagramme de séquence de la connexion des joueurs à une partie :*
...
...
not-alone-doc/src/doc/asciidoc/_sections/conception.adoc
View file @
576670ee
...
...
@@ -96,3 +96,81 @@ partition Game::run() {
}
----
==
Game
Server
.
GameSever
[
plantuml
]
....
interface
GameServer
{
createGame
(
numberOfPlayers
:
Integer
):
Integer
join
(
gameId
:
Integer
):
Integer
}
package
game
{
class
"GameServerController"
as
controller
{
createGame
(
numberOfPlayers
:
Integer
):
Integer
join
(
gameId
:
Integer
):
Integer
}
class
"Game
\n
[Thread]"
as
game
{
id
:
Integer
{
id
}
numberOfPlayers
:
Integer
}
class
"Player"
as
player
{
id
:
Integer
{
id
}
}
GameServer
<|--
controller
controller
*-
"[*] games"
game
:
\
t
\
t
\
t
game
*--
"[0..7] players"
player
}
note
right
of
game
:
Uncompleted
!
....
[
plantuml
]
....
state
Game
{
[*]
-->
Created
Created
->
Started
:
start
()
Started
->
Phase1
:
\
t
Phase1
-->
[*]
}
note
right
of
Game
:
Uncompleted
!
....
===
Op
é
rations
du
GameServerController
.
Create
Game
[
source
,
OCL
]
----
GameServerController
::
createGame
(
numberOfPlayers
:
Integer
):
Integer
pre
:
numberOfPlayers
>
1
and
numberOfPlayers
<=
7
post
:
self
.
games
->
exists
(
each
|
each
.
isOclNew
())
and
game
.
oclinState
(
Created
)
----
.
Join
Game
[
source
,
OCL
]
----
GameServerController
::
join
(
gameId
:
Integer
):
Integer
pre
:
self
.
games
->
exists
(
each
|
each
.
id
=
gameId
)
post
:
let
game
=
self
.
games
->
select
(
id
=
gameId
)->
first
()
in
game
.
players
->
exists
(
each
|
each
.
isOclNew
())
----
.
Start
Game
[
plantuml
]
----
partition
Game
::
run
()
{
start
while
(
enough
players
?)
:
JoinRequest
<
:
handleRequest
();
endwhile
:
Game
Start
>
stop
}
----
not-alone-server/src/main/java/fr/univnantes/alma/NotAloneApplication.java
View file @
576670ee
package
fr.univnantes.alma
;
import
fr.univnantes.alma.thrift.GameService
;
import
fr.univnantes.alma.handler.GameServiceHandler
;
import
org.apache.thrift.protocol.TBinaryProtocol
;
import
org.apache.thrift.protocol.TProtocolFactory
;
...
...
@@ -30,8 +32,8 @@ public class NotAloneApplication {
@Bean
public
ServletRegistrationBean
gameServer
(
TProtocolFactory
protocolFactory
,
GameServiceHandler
handler
)
{
TServlet
tServlet
=
new
TServlet
(
new
GameService
.
Processor
<
GameServiceHandler
>(
handler
),
protocolFactory
);
TServlet
tServlet
=
new
TServlet
(
new
GameService
.
Processor
<
GameServiceHandler
>(
handler
),
protocolFactory
);
return
new
ServletRegistrationBean
(
tServlet
,
"/api"
);
}
}
not-alone-server/src/main/java/fr/univnantes/alma/common/GameService.java
0 → 100644
View file @
576670ee
package
fr.univnantes.alma.common
;
import
fr.univnantes.alma.common.GameJoinRequest
;
public
interface
GameService
{
/**
* Creates a game for a number of players
* @param expectedPlayers The number of expected players, between 2 and 7
*
* @return an int, the game identification
*/
int
createGame
(
int
expectedPlayers
);
/**
*
* @param gameId
* @param request
* @return
*/
int
join
(
int
gameId
,
GameJoinRequest
request
);
}
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
View file @
576670ee
...
...
@@ -30,7 +30,7 @@ public class Game {
play
.
start
();
}
public
int
join
(
GameJoinRequest
request
)
{
public
int
join
(
GameJoinRequest
request
)
{
int
id
=
idCounter
.
getAndIncrement
();
requests
.
offer
(
request
);
return
id
;
...
...
not-alone-server/src/main/java/fr/univnantes/alma/game/GameServiceController.java
0 → 100644
View file @
576670ee
package
fr.univnantes.alma.game
;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.common.GameService
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
org
.
atlanmod
.
commons
.
Preconditions
.
checkArgument
;
@Component
public
class
GameServiceController
implements
GameService
{
private
final
AtomicInteger
idCounter
=
new
AtomicInteger
(
0
);
private
final
Map
<
Integer
,
Game
>
games
=
new
HashMap
<>();
@Override
public
int
createGame
(
int
expectedPlayers
)
{
checkArgument
(
expectedPlayers
>
1
&&
expectedPlayers
<=
7
,
"A game must have between 2 and 7 players"
);
int
newId
=
idCounter
.
incrementAndGet
();
Game
newGame
=
new
Game
(
expectedPlayers
);
games
.
put
(
newId
,
newGame
);
return
newId
;
}
@Override
public
int
join
(
int
gameId
,
GameJoinRequest
request
)
{
Game
game
=
games
.
get
(
gameId
);
return
game
.
join
(
request
);
}
}
not-alone-server/src/main/java/fr/univnantes/alma/handler/GameServiceHandler.java
View file @
576670ee
...
...
@@ -4,6 +4,8 @@ import fr.univnantes.alma.common.GameInterface;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.thrift.GameService
;
import
fr.univnantes.alma.thrift.JoinRequest
;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.thrift.GameNotFound
;
import
org.apache.thrift.TException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
not-alone-server/src/test/java/fr/univnantes/alma/NotAloneApplicationTest.java
View file @
576670ee
...
...
@@ -24,6 +24,7 @@ class NotAloneApplicationTest {
@LocalServerPort
protected
int
port
;
protected
GameService
.
Iface
client
;
@BeforeEach
...
...
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