Commit 576670ee authored by Anthony ROZEN's avatar Anthony ROZEN Committed by Antoine Guérin
Browse files

ajout des modifications du projet initial

parent 33b253e7
namespace java fr.univnantes.alma.thrift
namespace js common
namespace js core
exception InvalidOperationException {
1: i32 code,
......
......@@ -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 :*
......
......@@ -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
}
----
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");
}
}
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);
}
......@@ -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;
......
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);
}
}
......@@ -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;
......
......@@ -24,6 +24,7 @@ class NotAloneApplicationTest {
@LocalServerPort
protected int port;
protected GameService.Iface client;
@BeforeEach
......
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