made all classes for ServerStartGameMEssage serializiable

This commit is contained in:
Fleischer Hanno
2024-12-01 23:42:32 +01:00
parent eaef4b20ba
commit c2b6e6e9e9
12 changed files with 103 additions and 12 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.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() {

View File

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

View File

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

View File

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

View File

@@ -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<Color, PlayerData> playerData;
private final Node[] infield;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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