mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Quick fix so more than one game can be played in succession
This commit is contained in:
@@ -31,14 +31,18 @@ public class OnlineTurnBasedGame implements OnlineGame<TurnBasedGame> {
|
||||
private void notifyGameEnd(GameState state, int winner){
|
||||
if (state == GameState.DRAW){
|
||||
for (NettyClient client : clients) {
|
||||
client.send(String.format("SVR GAME DRAW {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"NettyClient disconnected\"}\n"));
|
||||
client.send(String.format("SVR GAME DRAW {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"<comment>\"}\n"));
|
||||
}
|
||||
}
|
||||
else{
|
||||
clients[winner].send(String.format("SVR GAME WIN {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"NettyClient disconnected\"}\n"));
|
||||
clients[(winner + 1)%2].send(String.format("SVR GAME LOSS {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"NettyClient disconnected\"}\n"));
|
||||
clients[winner].send(String.format("SVR GAME WIN {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"<comment>\"}\n"));
|
||||
clients[(winner + 1)%2].send(String.format("SVR GAME LOSS {PLAYERONESCORE: \"<score speler1>\", PLAYERTWOSCORE: \"<score speler2>\", COMMENT: \"<comment>\"}\n"));
|
||||
}
|
||||
|
||||
// Remove game fromt clients
|
||||
for(NettyClient client : clients) {
|
||||
client.clearGame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -142,7 +142,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
||||
|
||||
for (int i = 0; i < clients.length; i++) {
|
||||
players[i] = new ServerPlayer(clients[i]);
|
||||
clients[i].addGame(new ImmutablePair<>(game, players[i]));
|
||||
clients[i].setGame(new ImmutablePair<>(game, players[i]));
|
||||
}
|
||||
System.out.println("Starting OnlineTurnBasedGame");
|
||||
|
||||
@@ -207,6 +207,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
||||
if (userNames.size() < 2) continue;
|
||||
|
||||
while (userNames.size() > 1) {
|
||||
// TODO: Make sure users aren't currently in a game.
|
||||
int left = ran.nextInt(userNames.size());
|
||||
int right;
|
||||
do {
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface Client<G, P> {
|
||||
OnlineTurnBasedGame game();
|
||||
P player();
|
||||
|
||||
void addGame(Pair<G, P> gamePair);
|
||||
void setGame(Pair<G, P> gamePair);
|
||||
void clearGame();
|
||||
|
||||
void send(String message);
|
||||
|
||||
@@ -27,10 +27,8 @@ public class NettyClient implements Client<OnlineTurnBasedGame, ServerPlayer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGame(Pair<OnlineTurnBasedGame, ServerPlayer> gamePair) {
|
||||
if (this.gamePair == null) {
|
||||
this.gamePair = gamePair;
|
||||
}
|
||||
public void setGame(Pair<OnlineTurnBasedGame, ServerPlayer> gamePair) {
|
||||
this.gamePair = gamePair;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user