start game stuff - both online and offline #13

Merged
lgc merged 24 commits from start-game into main 2024-12-13 16:27:43 +00:00
3 changed files with 22 additions and 6 deletions
Showing only changes of commit dfbe4b3c53 - Show all commits

View File

@ -68,11 +68,18 @@ public class GameController {
throw new RuntimeException("Unable to instantiate players");
}
localPlayer.isServer = localPlayerIsServer;
onlinePlayer.isServer = !localPlayerIsServer;
localPlayer.setName(localPlayerName);
startGameWithInstancedPlayers(localPlayer, onlinePlayer, size);
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

View File

@ -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

View File

@ -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()));