mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +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){
|
private void notifyGameEnd(GameState state, int winner){
|
||||||
if (state == GameState.DRAW){
|
if (state == GameState.DRAW){
|
||||||
for (NettyClient client : clients) {
|
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{
|
else{
|
||||||
clients[winner].send(String.format("SVR GAME WIN {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: \"NettyClient disconnected\"}\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
|
@Override
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
|||||||
|
|
||||||
for (int i = 0; i < clients.length; i++) {
|
for (int i = 0; i < clients.length; i++) {
|
||||||
players[i] = new ServerPlayer(clients[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");
|
System.out.println("Starting OnlineTurnBasedGame");
|
||||||
|
|
||||||
@@ -207,6 +207,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
|||||||
if (userNames.size() < 2) continue;
|
if (userNames.size() < 2) continue;
|
||||||
|
|
||||||
while (userNames.size() > 1) {
|
while (userNames.size() > 1) {
|
||||||
|
// TODO: Make sure users aren't currently in a game.
|
||||||
int left = ran.nextInt(userNames.size());
|
int left = ran.nextInt(userNames.size());
|
||||||
int right;
|
int right;
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public interface Client<G, P> {
|
|||||||
OnlineTurnBasedGame game();
|
OnlineTurnBasedGame game();
|
||||||
P player();
|
P player();
|
||||||
|
|
||||||
void addGame(Pair<G, P> gamePair);
|
void setGame(Pair<G, P> gamePair);
|
||||||
void clearGame();
|
void clearGame();
|
||||||
|
|
||||||
void send(String message);
|
void send(String message);
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ public class NettyClient implements Client<OnlineTurnBasedGame, ServerPlayer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGame(Pair<OnlineTurnBasedGame, ServerPlayer> gamePair) {
|
public void setGame(Pair<OnlineTurnBasedGame, ServerPlayer> gamePair) {
|
||||||
if (this.gamePair == null) {
|
|
||||||
this.gamePair = gamePair;
|
this.gamePair = gamePair;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearGame() {
|
public void clearGame() {
|
||||||
|
|||||||
Reference in New Issue
Block a user