fix online game start
This commit is contained in:
parent
5ba5919775
commit
dfbe4b3c53
|
@ -68,11 +68,18 @@ public class GameController {
|
|||
throw new RuntimeException("Unable to instantiate players");
|
||||
}
|
||||
|
||||
|
||||
localPlayer.isServer = localPlayerIsServer;
|
||||
onlinePlayer.isServer = !localPlayerIsServer;
|
||||
|
||||
startGameWithInstancedPlayers(localPlayer, onlinePlayer, size);
|
||||
localPlayer.setName(localPlayerName);
|
||||
|
||||
localPlayer.setEnemy(onlinePlayer);
|
||||
onlinePlayer.setEnemy(localPlayer);
|
||||
|
||||
onlinePlayer.sendIAM();
|
||||
|
||||
// Start game only after IAM Package was exchanged
|
||||
} else {
|
||||
throw new RuntimeException("Unexpected Package received before game initialisation");
|
||||
}
|
||||
|
@ -156,13 +163,13 @@ public class GameController {
|
|||
localPlayer.createBoard(size);
|
||||
aiPlayer.createBoard(size);
|
||||
|
||||
localPlayer.setEnemy(aiPlayer);
|
||||
aiPlayer.setEnemy(localPlayer);
|
||||
|
||||
startGameWithInstancedPlayers(localPlayer, aiPlayer, size);
|
||||
}
|
||||
|
||||
private static void startGameWithInstancedPlayers(LocalPlayer p1, Player p2, int boardSize) {
|
||||
p1.setEnemy(p2);
|
||||
p2.setEnemy(p1);
|
||||
|
||||
public static void startGameWithInstancedPlayers(LocalPlayer p1, Player p2, int boardSize) {
|
||||
mainFrame.showPanelSLG("GameBoard", boardSizeToSemester(boardSize), p1, p2);
|
||||
|
||||
// TODO: frontend configuration
|
||||
|
|
|
@ -11,6 +11,8 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener
|
|||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public abstract void sendIAM();
|
||||
|
||||
public abstract void receive(String message);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(String message) {
|
||||
SocketPackage p = new SocketPackage(message);
|
||||
|
@ -26,6 +25,8 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
this.createBoard(usedBoardSize);
|
||||
this.enemy.createBoard(usedBoardSize);
|
||||
|
||||
GameController.startGameWithInstancedPlayers((LocalPlayer)this.enemy, (Player)this, usedBoardSize);
|
||||
|
||||
break;
|
||||
|
||||
// TODO: IAMU
|
||||
|
@ -66,6 +67,12 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void sendIAM() {
|
||||
if (this.enemy == null) throw new RuntimeException("enemy has not yet been defined");
|
||||
socket.send(new SocketPackage("IAM", GameController.boardSizeToSemester(this.wantedBoardSize) + " " + this.enemy.name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point){
|
||||
super.socket.send(new SocketPackage("SHOOT",point.toString()));
|
||||
|
|
Loading…
Reference in New Issue