This commit is contained in:
Daniel Grigencha
2024-12-01 23:57:39 +01:00
15 changed files with 114 additions and 53 deletions

View File

@@ -71,4 +71,8 @@ public void update(float delta) {
} }
} }
} }
public NetworkSupport getNetwork(){
return network;
}
} }

View File

@@ -2,9 +2,7 @@
import com.jme3.network.*; import com.jme3.network.*;
import com.jme3.network.serializing.Serializer; import com.jme3.network.serializing.Serializer;
import pp.mdga.game.Game; import pp.mdga.game.*;
import pp.mdga.game.Player;
import pp.mdga.game.Statistic;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -138,6 +136,13 @@ private void initializeSerializables() {
Serializer.registerClass(WaitPieceMessage.class); Serializer.registerClass(WaitPieceMessage.class);
Serializer.registerClass(Player.class); Serializer.registerClass(Player.class);
Serializer.registerClass(Statistic.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() { private void registerListeners() {

View File

@@ -67,42 +67,6 @@ public void onEnter() {
app.getViewPort().addProcessor(fpp); app.getViewPort().addProcessor(fpp);
app.getAcousticHandler().playSound(MdgaSound.START); app.getAcousticHandler().playSound(MdgaSound.START);
//Test
List<UUID> 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<UUID> 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 @Override

View File

@@ -106,13 +106,10 @@ private void tryHost() {
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
// todo: implement
} }
hostDialog.connectServerAsClient(); hostDialog.connectServerAsClient();
try { while (hostDialog.getNetwork().isConnected()){
Thread.sleep(1000); int i = 2;
} catch (InterruptedException ignored) {
// todo: implement
} }
app.getModelSynchronize().setHost(port); app.getModelSynchronize().setHost(port);
//app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); //app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT);
@@ -142,9 +139,8 @@ private void tryJoin() {
app.getModelSynchronize().setName(startDialog.getName()); app.getModelSynchronize().setName(startDialog.getName());
joinDialog.setHostname(ip); joinDialog.setHostname(ip);
joinDialog.connectToServer(); joinDialog.connectToServer();
try { while (!joinDialog.getNetwork().isConnected()){
Thread.sleep(1000); int i = 2;
} catch (InterruptedException ignored) {
} }
app.getModelSynchronize().setJoin(ip, port); app.getModelSynchronize().setJoin(ip, port);
return; return;

View File

@@ -53,6 +53,10 @@ public void setOwnPlayerName(String ownPlayerName) {
this.ownPlayerName = ownPlayerName; this.ownPlayerName = ownPlayerName;
} }
public void setOwnPlayerId(int ownPlayerId) {
this.ownPlayerID = ownPlayerId;
}
public LobbyState getLobby() { public LobbyState getLobby() {
return lobbyState; return lobbyState;
} }

View File

@@ -8,6 +8,9 @@
public class GameState extends ClientState { public class GameState extends ClientState {
/**
* the current substate
*/
private GameStates state; private GameStates state;
private final AnimationState animationState = new AnimationState(this, logic); 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 TurnState turnState = new TurnState(this, logic);
private final WaitingState waitingState = new WaitingState(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) { public GameState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
state = determineStartPlayerState; state = determineStartPlayerState;
} }
/**
* The method to enter the state
*/
@Override @Override
public void enter() { public void enter() {
} }
/**
* the method to exit this state
*/
@Override @Override
public void exit() { 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){ public void setState(GameStates newState){
state.exit(); state.exit();
state.enter(); state.enter();

View File

@@ -26,19 +26,35 @@ public void enter() {
previousState = null; previousState = null;
} }
/**
* exits this state
*/
@Override @Override
public void exit() { public void exit() {
previousState = null; previousState = null;
} }
/**
* This method sets the stores the gamestate as previous state
*
* @param previousState
*/
public void setPreviousState(ClientState previousState) { public void setPreviousState(ClientState previousState) {
this.previousState = previousState; this.previousState = previousState;
} }
/**
* returns teh previous gamestate
*
* @return the previous gamestate
*/
public ClientState getPreviousState() { public ClientState getPreviousState() {
return previousState; return previousState;
} }
/**
* The host resumes the game
*/
@Override @Override
public void selectResume(){ public void selectResume(){
if(logic.isHost()){ 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) { public void received(ResumeGameMessage msg) {
//TODO: logic.addNotification(new ResumeNotification()); //TODO: logic.addNotification(new ResumeNotification());
logic.setState(previousState); logic.setState(previousState);

View File

@@ -11,10 +11,7 @@
import pp.mdga.message.server.ServerStartGameMessage; import pp.mdga.message.server.ServerStartGameMessage;
import pp.mdga.message.server.UpdateReadyMessage; import pp.mdga.message.server.UpdateReadyMessage;
import pp.mdga.message.server.UpdateTSKMessage; import pp.mdga.message.server.UpdateTSKMessage;
import pp.mdga.notification.LobbyReadyNotification; import pp.mdga.notification.*;
import pp.mdga.notification.StartDialogNotification;
import pp.mdga.notification.TskSelectNotification;
import pp.mdga.notification.TskUnselectNotification;
public class LobbyState extends DialogStates { public class LobbyState extends DialogStates {
@@ -74,12 +71,16 @@ public void selectStart(){
@Override @Override
public void received(ServerStartGameMessage msg){ public void received(ServerStartGameMessage msg){
logic.getGame().setBoard(msg.getBoard());
logic.addNotification(new GameNotification(logic.getGame().getPlayers().get(parent.getOwnPlayerId()).getColor()));
parent.startGame(); parent.startGame();
} }
@Override @Override
public void received(LobbyPlayerJoinedMessage msg){ 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.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId()));
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer()); logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
} }
@@ -99,6 +100,7 @@ public void received(LobbyPlayerLeaveMessage msg){
@Override @Override
public void received(UpdateReadyMessage msg){ 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.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady()));
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady()); logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
} }

View File

@@ -1,10 +1,13 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
import java.util.Map; import java.util.Map;
/** /**
* This class will be used to hold all Board relevant data. * This class will be used to hold all Board relevant data.
*/ */
@Serializable
public class Board { public class Board {
private Map<Color, PlayerData> playerData; private Map<Color, PlayerData> playerData;
private final Node[] infield; private final Node[] infield;

View File

@@ -1,7 +1,13 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* This class represents a BonusNode * This class represents a BonusNode
*/ */
@Serializable
public class BonusNode extends Node { public class BonusNode extends Node {
BonusNode(){
super();
}
} }

View File

@@ -1,7 +1,13 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* Represents a home node. * Represents a home node.
*/ */
@Serializable
public class HomeNode extends Node { public class HomeNode extends Node {
public HomeNode() {
super();
}
} }

View File

@@ -1,11 +1,18 @@
package pp.mdga.game; 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 * This class will be used the represent a Node on which the pieces can travel along
*/ */
@Serializable
public class Node { public class Node {
protected Piece occupant; protected Piece occupant;
public Node(){
}
/** /**
* This method is used to get an occupant of the Node. * This method is used to get an occupant of the Node.
* *

View File

@@ -1,10 +1,13 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
import java.util.UUID; import java.util.UUID;
/** /**
* This class will be used to hold all Piece relevant data. * This class will be used to hold all Piece relevant data.
*/ */
@Serializable
public class Piece { public class Piece {
/** /**
* The shield state of the piece. * The shield state of the piece.
@@ -38,6 +41,10 @@ public Piece(Color color, PieceState state, int id) {
shield = ShieldState.NONE; shield = ShieldState.NONE;
} }
private Piece() {
color = null;
}
/** /**
* This method is used to get the color of the piece * This method is used to get the color of the piece
* *

View File

@@ -1,8 +1,11 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* This class is used to represent PlayerData related to the board * This class is used to represent PlayerData related to the board
*/ */
@Serializable
public class PlayerData { public class PlayerData {
/** /**
* An array of HomeNode objects representing the home nodes of the player. * 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 * This method returns an Array of HomeNodes
* *

View File

@@ -1,8 +1,11 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* Represents a start node. * Represents a start node.
*/ */
@Serializable
public class StartNode extends Node { public class StartNode extends Node {
/** /**
* The color of the node. * The color of the node.
@@ -18,6 +21,10 @@ public StartNode(Color color) {
this.color = color; this.color = color;
} }
private StartNode() {
color = null;
}
/** /**
* This method is used to get the color of the node * This method is used to get the color of the node
* *