Commit 10313d83 authored by Gerson Sunyé's avatar Gerson Sunyé

Back to Java 1.8

parent d2e991fd
......@@ -11,6 +11,4 @@ service GameServerService {
i32 createGame(i32 numberOfPlayers)
i32 join(i32 gameId, JoinRequest request) throws (1:common.GameNotFound e)
void start(i32 gameId) throws (1:common.GameNotFound e)
}
......@@ -22,7 +22,6 @@ par
player5 -> game : playerId := join(id, five)
player6 -> game : playerId := join(id, six)
end
game -> game : start()
....
.Questions ouveres (à faire)
......@@ -35,6 +34,5 @@ game -> game : start()
interface GameServer {
createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer
satrt()
}
....
......@@ -9,16 +9,14 @@
interface GameServer {
createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer
start()
}
package game {
class "GameServerController" as controller {
createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer
start()
}
class "Game" as game {
class "Game \n[Thread]" as game {
id : Integer {id}
numberOfPlayers : Integer
}
......@@ -27,7 +25,7 @@ package game {
}
GameServer <|-- controller
controller *- "[*] games" game : \t\t\t
controller *-- "[0..7] players" player
game *-- "[0..7] players" player
}
note right of game: Uncompleted!
....
......@@ -71,7 +69,7 @@ post:
.Start Game
[plantuml]
----
partition GameServerController::start() {
partition Game::run() {
start
while (enough players?)
:JoinRequest<
......
......@@ -16,10 +16,6 @@
<name>Not Alone Server</name>
<description>Spring Boot Not Alone server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>fr.univnantes.alma</groupId>
......
......@@ -20,5 +20,4 @@ public interface GameService {
*/
int join(int gameId, GameJoinRequest request);
void start(int gameId) throws InterruptedException;
}
......@@ -20,9 +20,14 @@ public class Game {
private final AtomicInteger expectedPlayers;
private Thread play;
public Game(int expectedPlayers) {
this.expectedPlayers = new AtomicInteger(expectedPlayers);
this.requests = new ArrayBlockingQueue<GameJoinRequest>(expectedPlayers);
play = new Thread(() -> this.start());
play.start();
}
public int join(GameJoinRequest request) {
......@@ -31,13 +36,10 @@ public class Game {
return id;
}
public void start() {
Thread t = new Thread(() -> {
this.waitForPlayers();
Log.info("We can start !");
}
);
t.start();
private void start() {
this.waitForPlayers();
Log.info("We can start !");
}
private void waitForPlayers() {
......
......@@ -34,10 +34,4 @@ public class GameServiceController implements GameService {
return game.join(request);
}
@Override
public void start(int gameId) throws InterruptedException {
Game game = games.get(gameId);
game.start();
}
}
......@@ -22,16 +22,8 @@ public class GameServiceHandler implements GameServerService.Iface {
@Override
public int join(int gameId, JoinRequest request) throws TException {
//TODO: translate JoinRequest into GameJoinRequest
return service.join(gameId, new GameJoinRequest());
}
@Override
public void start(int gameId) throws GameNotFound, TException {
try {
service.start(gameId);
} catch (InterruptedException e) {
throw new GameNotFound();
}
}
}
......@@ -50,7 +50,7 @@ class NotAloneApplicationTest {
client.join(id, new JoinRequest("two"));
client.join(id, new JoinRequest("three"));
client.join(id, new JoinRequest("four"));
client.start(id);
Thread.sleep(1000);
}
......
......@@ -12,8 +12,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<commons.version>1.0.5</commons.version>
</properties>
......
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