added logic for incorrectRequest message and removed messages playerdata and startbriefing and created javadocs

This commit is contained in:
Fleischer Hanno
2024-12-02 19:02:00 +01:00
parent 294ecdc56f
commit 90a21087df
7 changed files with 613 additions and 14 deletions

View File

@@ -1,9 +1,9 @@
package pp.mdga.client;
import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings;
import com.simsilica.lemur.GuiGlobals;
import pp.mdga.client.acoustic.AcousticHandler;
import com.jme3.system.AppSettings;
import pp.mdga.client.dialog.JoinDialog;
import pp.mdga.client.view.*;

View File

@@ -12,21 +12,38 @@ public class CeremonyState extends ClientState {
private final PodiumState podiumState = new PodiumState(this, logic);
private final StatisticsState statisticsState = new StatisticsState(this, logic);
/**
* Creates a new CeremonyState
*
* @param parent the parent state
* @param logic the game logic
*/
public CeremonyState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
}
/**
* Enters the new state machine
*/
@Override
public void enter() {
setState(podiumState);
logic.addNotification(createCeremonyNotification());
}
/**
* exits this state
*/
@Override
public void exit() {
currentState.exit();
}
/**
* This method is used to set a new SubState
*
* @param state the state to be set
*/
public void setState(CeremonyStates state){
if(this.currentState != null){
this.currentState.exit();
@@ -35,14 +52,29 @@ public void setState(CeremonyStates state){
currentState = state;
}
/**
* This method get the PodiumState
*
* @return the PodiumState
*/
public PodiumState getPodiumState(){
return podiumState;
}
/**
* This method get the StatisticsState
*
* @return the StatisticsState
*/
public StatisticsState getStatisticsState(){
return statisticsState;
}
/**
* This method is used to get the current State
*
* @return the current State
*/
public CeremonyStates getState(){
return currentState;
}

View File

@@ -13,6 +13,10 @@
import java.util.Map;
import java.util.UUID;
/**
* The ClientGameLogic class is the main class for the client side of the game.
* It is responsible for handling the game logic on the client side.
*/
public class ClientGameLogic implements ServerInterpreter {
static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
@@ -28,6 +32,11 @@ public class ClientGameLogic implements ServerInterpreter {
private final InterruptState interruptState = new InterruptState(null, this);
private final SettingsState settingsState = new SettingsState(null, this);
/**
* Creates a new ClientGameLogic
*
* @param clientSender the client sender
*/
public ClientGameLogic(ClientSender clientSender) {
this.game = new Game();
this.clientSender = clientSender;
@@ -35,11 +44,21 @@ public ClientGameLogic(ClientSender clientSender) {
state = dialogsState;
}
/**
* This method is used to send a message to the server
*
* @param msg the message to be sent
*/
public void send(ClientMessage msg){
LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
clientSender.send(msg);
}
/**
* This method is used to get a piece by its id
* @param pieceId the UUID of the piece
* @return the piece
*/
private Piece getPiece(UUID pieceId){
for(Map.Entry<Color, PlayerData> entry : game.getBoard().getPlayerData().entrySet()){
for(Piece piece : entry.getValue().getPieces()){
@@ -51,216 +70,432 @@ private Piece getPiece(UUID pieceId){
return null;
}
/**
* This method returns the clientSender
*
* @return the clientSender
*/
public ClientSender getClientSender(){
return clientSender;
}
/**
* This method returns the game
*
* @return the game
*/
public Game getGame(){
return game;
}
/**
* This method returns the current State
*
* @return the current State
*/
public ClientState getState(){
return state;
}
/**
* This method returns if the client is a host
*
* @return if the client is a host
*/
public boolean isHost(){
return isHost;
}
/**
* This method returns the steps you can calculate steps
*
* @return the calculated moves as int
*/
public int getCalculatedMoves(){
return game.getDiceEyes() * game.getDiceModifier();
}
/**
* This method sets if the player is a host
*
* @param isHost the boolean value
*/
public void setHost(boolean isHost){
this.isHost = isHost;
}
/**
* This method calls the method received of the state
*
* @param msg the ActivePlayer message received
*/
@Override
public void received(ActivePlayerMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the AnyPiece message received
*/
@Override
public void received(AnyPieceMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the Briefing message received
*/
@Override
public void received(BriefingMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the Ceremony message received
*/
@Override
public void received(CeremonyMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the Dice message received
*/
@Override
public void received(DieMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the DiceAgain message received
*/
@Override
public void received(DiceAgainMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the DiceNow message received
*/
@Override
public void received(DiceNowMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the EndOfGame message received
*/
@Override
public void received(EndOfTurnMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the GameOver message received
*/
@Override
public void received(LobbyAcceptMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the LobbyDeny message received
*/
@Override
public void received(LobbyDenyMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the LobbyPlayerJoin message received
*/
@Override
public void received(LobbyPlayerJoinedMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the LobbyPlayerLeave message received
*/
@Override
public void received(LobbyPlayerLeaveMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the MoveMessage message received
*/
@Override
public void received(MoveMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the NoTurn message received
*/
@Override
public void received(NoTurnMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the PauseGame message received
*/
@Override
public void received(PauseGameMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the PlayCard message received
*/
@Override
public void received(PlayCardMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the PossibleCard message received
*/
@Override
public void received(PossibleCardMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the PossiblePiece message received
*/
@Override
public void received(PossiblePieceMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the RankingResponse message received
*/
@Override
public void received(RankingResponseMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the RankingRollAgain message received
*/
@Override
public void received(RankingRollAgainMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the ReconnectBriefing message received
*/
@Override
public void received(ReconnectBriefingMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the ResumeGame message received
*/
@Override
public void received(ResumeGameMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the ServerStartGame message received
*/
@Override
public void received(ServerStartGameMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the SelectTSK message received.
*/
@Override
public void received(ShutdownMessage msg) {state.received(msg);}
/**
* Handles a IncorrectRequest message received from the server.
*
* @param msg the IncorrectRequest message received.
*/
@Override
public void received(StartBriefingMessage msg) {
state.received(msg);
}
@Override
public void received(PlayerDataMessage msg) {
public void received(IncorrectRequestMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the StartPiece message received
*/
@Override
public void received(StartPieceMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the UpdateReady message received
*/
@Override
public void received(UpdateReadyMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the UpdateTSK message received
*/
@Override
public void received(UpdateTSKMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the WaitPiece message received
*/
@Override
public void received(WaitPieceMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the Spectator message received.
*/
@Override
public void received(SpectatorMessage msg) {
state.received(msg);
}
/**
* This method calls the method received of the state
*
* @param msg the SelectPiece message received.
*/
@Override
public void received(SelectPieceMessage msg) {
state.received(msg);
}
/**
* This method calls the method selectPiece
*
* @param pieceId the pieceID
*/
public void selectPiece(UUID pieceId){
state.selectPiece(getPiece(pieceId));
}
/**
* This method call the method selectNExt of the state
*/
public void selectNext(){
state.selectNext();
}
/**
* This method calls the method selectCard of the state
*
* @param card the BonusCard to selected
*/
public void selectCard(BonusCard card){
state.selectCard(card);
}
/**
* This method call the method selectTsk of the state
*
* @param color the Color to be selected
*/
public void selectTsk(Color color){
state.selectTSK(color);
}
/**
* The method calls the method deselectTsk of the state
*
* @param color the color to be deselcted
*/
public void deselectTSK(Color color){
state.deselectTSK(color);
}
/**
* This method calls the selectDice method of the state
*/
public void selectDice(){
state.selectDice();
}
/**
* This method calls the selectName method of the state
*
* @param name the name to be set
*/
public void selectName(String name){
state.setName(name);
}
/**
* This method calls a method of the state base on the parameter value
*
* @param ready the value if this method should ready or unready
*/
public void selectReady(boolean ready){
if(ready){
state.selectReady();
@@ -269,62 +504,122 @@ public void selectReady(boolean ready){
}
}
/**
* This method calls the selectHost method of the state
*
* @param name the name of the player hosting
*/
public void selectHost(String name){
state.selectHost(name);
}
/**
* This method calls the selectLeave method of the state
*/
public void selectLeave(){
state.selectLeave();
}
/**
* This method calls the selectJoin method of the state
*
* @param ip the ip to cennect to
*/
public void selectJoin(String ip){
state.selectJoin(ip);
}
/**
* This method calls the selectAnimationEnd method of the state
*/
public void selectAnimationEnd(){
state.selectAnimationEnd();
}
/**
* This method calls the selectStart method of the state
*/
public void selectStart(){
state.selectStart();
}
/**
* This method calls the selectResume method of the state
*/
public void selectResume(){
state.selectResume();
}
/**
* This method is used to transition between states
*
* @param state the new state
*/
public void setState(ClientState state){
this.state.exit();
state.enter();
this.state = state;
}
/**
* This method is used to enter the interrupt state and save the previous state
*/
public void enterInterrupt(){
interruptState.enter();
interruptState.setPreviousState(state);
this.state = interruptState;
}
/**
* This method is used to get the GameState
*
* @return the GameState
*/
public GameState getGameState(){
return gameState;
}
/**
* This method is used to get the CeremonyState
*
* @return the CeremonyState
*/
public CeremonyState getCeremony(){
return ceremonyState;
}
/**
* This method is used to get the InterruptState
*
* @return the InterruptState
*/
public InterruptState getInterrupt(){
return interruptState;
}
/**
* This method is used to get the DialogsState
*
* @return the DialogsState
*/
public DialogsState getDialogs(){
return dialogsState;
}
/**
* This method is used to get the SettingsState
*
* @return the SettingsState
*/
public SettingsState getSettings(){
return settingsState;
}
/**
* This method is used to get the next notification
*
* @return the next notification
*/
public Notification getNotification(){
if(!notifications.isEmpty()){
return notifications.remove(0);
@@ -333,6 +628,11 @@ public Notification getNotification(){
}
}
/**
* This method is used to add a notification
*
* @param notification the notification to be added
*/
public void addNotification(Notification notification){
notifications.add(notification);
}

View File

@@ -184,12 +184,8 @@ public void received(WaitPieceMessage msg) {
}
@Override
public void received(StartBriefingMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
}
public void received(PlayerDataMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
public void received(IncorrectRequestMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
}
public void selectPiece(Piece piece) {
@@ -252,6 +248,11 @@ public void selectResume(){
LOGGER.log(Level.DEBUG, "Resume not allowed");
}
/**
* This method is used to create a CeremonyNotification
*
* @return the created CeremonyNotification
*/
protected CeremonyNotification createCeremonyNotification(){
CeremonyNotification notification = new CeremonyNotification();
for (var player : logic.getGame().getPlayers().entrySet()){

View File

@@ -18,16 +18,27 @@ public class DialogsState extends ClientState {
private final NetworkDialogState networkDialogState = new NetworkDialogState(this, logic);
private final StartDialogState startDialogState = new StartDialogState(this, logic);
/**
* Creates a new DialogsState
*
* @param parent the parent state
* @param logic the game logic
*/
public DialogsState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
}
/**
* exits this state
*/
@Override
public void exit(){
currentState.exit();
}
/**
* Enters the new state machine
*/
@Override
public void enter(){
setState(startDialogState);
@@ -35,6 +46,11 @@ public void enter(){
ownPlayerName = null;
}
/**
* This method is used to set a new SubState
*
* @param newState the state to be set
*/
public void setState(DialogStates newState){
if(currentState != null){
currentState.exit();
@@ -43,114 +59,224 @@ public void setState(DialogStates newState){
currentState = newState;
}
/**
* This method is used to get the ownPlayerId
*
* @return the ownPlayerId
*/
public int getOwnPlayerId() {
return ownPlayerID;
}
/**
* This method is used to get the ownPlayerName
*
* @return the ownPlayerName
*/
public String getOwnPlayerName() {
return ownPlayerName;
}
/**
* This method is used to set the ownPlayerName
*
* @param ownPlayerName the ownPlayerName to be set
*/
public void setOwnPlayerName(String ownPlayerName) {
this.ownPlayerName = ownPlayerName;
}
/**
* This method is used to set the ownPlayerId
*
* @param ownPlayerId the ownPlayerId to be set
*/
public void setOwnPlayerId(int ownPlayerId) {
this.ownPlayerID = ownPlayerId;
}
/**
* This method is used to get the lobbyState
*
* @return the lobbyState
*/
public LobbyState getLobby() {
return lobbyState;
}
/**
* This method is used to get the networkDialogState
*
* @return the networkDialogState
*/
public NetworkDialogState getNetworkDialog() {
return networkDialogState;
}
/**
* This method is used to get the startDialogState
*
* @return the startDialogState
*/
public StartDialogState getStartDialog() {
return startDialogState;
}
/**
* This method is used to call the selectLeave method of the current state
*/
@Override
public void selectLeave(){
currentState.selectLeave();
}
/**
* This method is used to call the selectName method of the current state
*
* @param name the name to be set
*/
@Override
public void setName(String name){
currentState.setName(name);
}
/**
* This method is used to call the selectTSK method of the current state
*
* @param color the color to be set
*/
@Override
public void selectTSK(Color color){
currentState.selectTSK(color);
}
/**
* This method is used to call the deselectTSK method of the current state
*
* @param color the color to be deselected
*/
@Override
public void deselectTSK(Color color){
currentState.deselectTSK(color);
}
/**
* This method is used to call the selectReady method of the current state
*/
@Override
public void selectReady(){
currentState.selectReady();
}
/**
* This method is used to call the selectUnready method of the current state
*/
@Override
public void selectUnready(){
currentState.selectUnready();
}
/**
* This method is used to call the selectStart method of the current state
*/
@Override
public void selectStart(){
currentState.selectStart();
}
/**
* This method is used to call the selectJoin method of the current state
*
* @param string the string to be set
*/
@Override
public void selectJoin(String string){
currentState.selectJoin(string);
}
/**
* This method is used to call the selectHost method of the current state
*
* @param name the name to be set
*/
@Override
public void selectHost(String name){
currentState.selectHost(name);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the LobbyPlayerJoin message received
*/
@Override
public void received(LobbyPlayerJoinedMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the LobbyPlayerLeave message received
*/
@Override
public void received(LobbyPlayerLeaveMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the UpdateTSKMessage message received
*/
@Override
public void received(UpdateTSKMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the UpdateReady message received
*/
@Override
public void received(UpdateReadyMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the ServerStartGame message received
*/
@Override
public void received(ServerStartGameMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the ServerStartGame message received
*/
@Override
public void received(PlayerDataMessage msg){
currentState.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the StartBriefing message received
*/
@Override
public void received(StartBriefingMessage msg){
currentState.received(msg);
}
/**
* This method is used to get the current state
*/
public DialogStates getState() {
return currentState;
}

View File

@@ -58,132 +58,263 @@ public void setState(GameStates newState){
state = newState;
}
/**
* This method is used to call the selectAnimationEnd method of the current state
*/
@Override
public void selectAnimationEnd(){
state.selectAnimationEnd();
}
/**
* This method is used to call the selectDice method of the current state
*/
@Override
public void selectDice(){
state.selectDice();
}
/**
* This method is used to call the selectPiece method of the current state
*
* @param piece the piece to be selected
*/
@Override
public void selectPiece(Piece piece){
state.selectPiece(piece);
}
/**
* This method is used to call the selectCard method of the current state
*
* @param card the card to be selected
*/
@Override
public void selectCard(BonusCard card){
state.selectCard(card);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(PauseGameMessage msg){
logic.enterInterrupt();
logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor()));
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(DieMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(RankingRollAgainMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(RankingResponseMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(SelectPieceMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(WaitPieceMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(StartPieceMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(NoTurnMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(MoveMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(CeremonyMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(EndOfTurnMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(SpectatorMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(DiceAgainMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(PossibleCardMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(PlayCardMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(DiceNowMessage msg){
state.received(msg);
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override
public void received(ActivePlayerMessage msg){
state.received(msg);
}
/**
* This method returns the current state
*
* @return the current state
*/
public GameStates getState(){
return state;
}
/**
* This method returns the AnimationState
*
* @return the AnimationState
*/
public AnimationState getAnimation() {
return animationState;
}
/**
* This method returns the DetermineStartPlayerState
*
* @return the DetermineStartPlayerState
*/
public DetermineStartPlayerState getDetermineStartPlayer() {
return determineStartPlayerState;
}
/**
* This method returns the SpectatorState
*
* @return the SpectatorState
*/
public SpectatorState getSpectator() {
return spectatorState;
}
/**
* This method returns the TurnState
*
* @return the TurnState
*/
public TurnState getTurn() {
return turnState;
}
/**
* This method returns the WaitingState
*
* @return the WaitingState
*/
public WaitingState getWaiting() {
return waitingState;
}

View File

@@ -49,14 +49,23 @@ public SettingStates getState(){
return currentState;
}
/**
* Returns the main settings state
*/
public MainSettingsState getMainSettingsState(){
return mainSettingsState;
}
/**
* Returns the audio settings state
*/
public AudioSettingsState getAudioSettingsState(){
return audioSettingsState;
}
/**
* Returns the video settings state
*/
public VideoSettingsState getVideoSettingsState(){
return videoSettingsState;
}