diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java index a234fa75..15c680e9 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java @@ -71,4 +71,8 @@ public void update(float delta) { } } } + + public NetworkSupport getNetwork(){ + return network; + } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java index 02d057e7..7f8d74f2 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java @@ -2,9 +2,7 @@ import com.jme3.network.*; import com.jme3.network.serializing.Serializer; -import pp.mdga.game.Game; -import pp.mdga.game.Player; -import pp.mdga.game.Statistic; +import pp.mdga.game.*; import pp.mdga.message.client.*; import pp.mdga.message.server.*; import pp.mdga.server.ServerGameLogic; @@ -138,6 +136,13 @@ private void initializeSerializables() { Serializer.registerClass(WaitPieceMessage.class); Serializer.registerClass(Player.class); Serializer.registerClass(Statistic.class); + Serializer.registerClass(Board.class); + Serializer.registerClass(Node.class); + Serializer.registerClass(Piece.class); + Serializer.registerClass(BonusNode.class); + Serializer.registerClass(StartNode.class); + Serializer.registerClass(PlayerData.class); + Serializer.registerClass(HomeNode.class); } private void registerListeners() { diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java index a6a9ffb5..c528092d 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java @@ -67,42 +67,6 @@ public void onEnter() { app.getViewPort().addProcessor(fpp); app.getAcousticHandler().playSound(MdgaSound.START); - - - //Test - List uuid1 = new ArrayList<>(); - UUID p1 = UUID.randomUUID(); - UUID p2 = UUID.randomUUID(); - uuid1.add(p1); - uuid1.add(p2); - uuid1.add(UUID.randomUUID()); - uuid1.add(UUID.randomUUID()); - List uuid2 = new ArrayList<>(); - UUID p1_2 = UUID.randomUUID(); - UUID p2_2 = UUID.randomUUID(); - uuid2.add(p1_2); - uuid2.add(p2_2); - uuid2.add(UUID.randomUUID()); - uuid2.add(UUID.randomUUID()); - - app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, uuid1, "Cedric")); - app.getNotificationSynchronizer().addTestNotification(new PlayerInGameNotification(Color.NAVY, uuid2, "Test")); - app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1, 0, true)); - app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification(p1_2, 20, true)); -// app.getNotificationSynchronizer().addTestNotification(new SelectableMoveNotification(List.of(p1), List.of(4), List.of(false))); -// app.getNotificationSynchronizer().addTestNotification(new AcquireCardNotification(BonusCard.SHIELD)); - app.getNotificationSynchronizer().addTestNotification(new SelectableSwapNotification(List.of(p1), List.of(p1_2))); - -// app.getNotificationSynchronizer().addTestNotification(new SelectableCardsNotification(List.of(BonusCard.SHIELD))); -// app.getNotificationSynchronizer().addTestNotification(new ShieldActiveNotification(p1)); -// app.getNotificationSynchronizer().addTestNotification(new ActivePlayerNotification(Color.NAVY)); - -// app.getNotificationSynchronizer().addTestNotification(new DiceNowNotification()); -// app.getNotificationSynchronizer().addTestNotification(new RollDiceNotification(Color.AIRFORCE, 5, true, 2)); - - //p1 = p1; - - } @Override diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java index 6aefa85f..4eb4c14d 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java @@ -106,13 +106,10 @@ private void tryHost() { try { Thread.sleep(1000); } catch (InterruptedException ignored) { - // todo: implement } hostDialog.connectServerAsClient(); - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - // todo: implement + while (hostDialog.getNetwork().isConnected()){ + int i = 2; } app.getModelSynchronize().setHost(port); //app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); @@ -142,9 +139,8 @@ private void tryJoin() { app.getModelSynchronize().setName(startDialog.getName()); joinDialog.setHostname(ip); joinDialog.connectToServer(); - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { + while (!joinDialog.getNetwork().isConnected()){ + int i = 2; } app.getModelSynchronize().setJoin(ip, port); return; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java index b72c1294..5f7cf182 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java @@ -53,6 +53,10 @@ public void setOwnPlayerName(String ownPlayerName) { this.ownPlayerName = ownPlayerName; } + public void setOwnPlayerId(int ownPlayerId) { + this.ownPlayerID = ownPlayerId; + } + public LobbyState getLobby() { return lobbyState; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java index 7f04f8a8..af449db8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java @@ -8,6 +8,9 @@ public class GameState extends ClientState { + /** + * the current substate + */ private GameStates state; private final AnimationState animationState = new AnimationState(this, logic); @@ -16,21 +19,38 @@ public class GameState extends ClientState { private final TurnState turnState = new TurnState(this, logic); private final WaitingState waitingState = new WaitingState(this, logic); + /** + * Constructor for GameState + * + * @param parent the parent of this state + * @param logic the ClientGameLogic + */ public GameState(ClientState parent, ClientGameLogic logic) { super(parent, logic); state = determineStartPlayerState; } + /** + * The method to enter the state + */ @Override public void enter() { } + /** + * the method to exit this state + */ @Override public void exit() { - + state.exit(); } + /** + * This method is used to set a new SubState + * + * @param newState the state to be set + */ public void setState(GameStates newState){ state.exit(); state.enter(); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java index 8c8d35d8..33ec5a4f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java @@ -26,19 +26,35 @@ public void enter() { previousState = null; } + /** + * exits this state + */ @Override public void exit() { previousState = null; } + /** + * This method sets the stores the gamestate as previous state + * + * @param previousState + */ public void setPreviousState(ClientState previousState) { this.previousState = previousState; } + /** + * returns teh previous gamestate + * + * @return the previous gamestate + */ public ClientState getPreviousState() { return previousState; } + /** + * The host resumes the game + */ @Override public void selectResume(){ if(logic.isHost()){ @@ -46,6 +62,11 @@ public void selectResume(){ } } + /** + * The server resumes the game + * + * @param msg the ResumeGame message received + */ public void received(ResumeGameMessage msg) { //TODO: logic.addNotification(new ResumeNotification()); logic.setState(previousState); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java index d310436e..92118173 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java @@ -11,10 +11,7 @@ import pp.mdga.message.server.ServerStartGameMessage; import pp.mdga.message.server.UpdateReadyMessage; import pp.mdga.message.server.UpdateTSKMessage; -import pp.mdga.notification.LobbyReadyNotification; -import pp.mdga.notification.StartDialogNotification; -import pp.mdga.notification.TskSelectNotification; -import pp.mdga.notification.TskUnselectNotification; +import pp.mdga.notification.*; public class LobbyState extends DialogStates { @@ -74,12 +71,16 @@ public void selectStart(){ @Override public void received(ServerStartGameMessage msg){ - + logic.getGame().setBoard(msg.getBoard()); + logic.addNotification(new GameNotification(logic.getGame().getPlayers().get(parent.getOwnPlayerId()).getColor())); parent.startGame(); } @Override public void received(LobbyPlayerJoinedMessage msg){ + if(msg.getPlayer().getName().equals(parent.getOwnPlayerName())){ + parent.setOwnPlayerId(msg.getId()); + } logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId())); logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer()); } @@ -99,6 +100,7 @@ public void received(LobbyPlayerLeaveMessage msg){ @Override public void received(UpdateReadyMessage msg){ + //TODO server sendet kein update on UNready logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady())); logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java index 730c9f45..d7227511 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java @@ -1,10 +1,13 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + import java.util.Map; /** * This class will be used to hold all Board relevant data. */ +@Serializable public class Board { private Map playerData; private final Node[] infield; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java index 157be2a1..c12f7cab 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java @@ -1,7 +1,13 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * This class represents a BonusNode */ +@Serializable public class BonusNode extends Node { + BonusNode(){ + super(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/HomeNode.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/HomeNode.java index 8faa06b1..814abaa5 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/HomeNode.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/HomeNode.java @@ -1,7 +1,13 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * Represents a home node. */ +@Serializable public class HomeNode extends Node { + public HomeNode() { + super(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java index 6d42092b..de6530ca 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java @@ -1,11 +1,18 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * This class will be used the represent a Node on which the pieces can travel along */ +@Serializable public class Node { protected Piece occupant; + public Node(){ + + } + /** * This method is used to get an occupant of the Node. * diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Piece.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Piece.java index 15f00498..64b671db 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Piece.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Piece.java @@ -1,10 +1,13 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + import java.util.UUID; /** * This class will be used to hold all Piece relevant data. */ +@Serializable public class Piece { /** * The shield state of the piece. @@ -38,6 +41,10 @@ public Piece(Color color, PieceState state, int id) { shield = ShieldState.NONE; } + private Piece() { + color = null; + } + /** * This method is used to get the color of the piece * diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java index f03559fa..818abeb2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java @@ -1,8 +1,11 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * This class is used to represent PlayerData related to the board */ +@Serializable public class PlayerData { /** * An array of HomeNode objects representing the home nodes of the player. @@ -39,6 +42,12 @@ public PlayerData(Color color) { } } + private PlayerData() { + homeNodes = null; + waitingArea = null; + pieces = null; + } + /** * This method returns an Array of HomeNodes * diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/StartNode.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/StartNode.java index 4d2de491..bb203084 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/StartNode.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/StartNode.java @@ -1,8 +1,11 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * Represents a start node. */ +@Serializable public class StartNode extends Node { /** * The color of the node. @@ -18,6 +21,10 @@ public StartNode(Color color) { this.color = color; } + private StartNode() { + color = null; + } + /** * This method is used to get the color of the node *