Updated client states.

Updated the client states by removing all references to the 'PlayerData' class.
This commit is contained in:
Daniel Grigencha
2024-12-04 01:47:31 +01:00
parent 7053b163e5
commit 964ff87b11
7 changed files with 99 additions and 295 deletions

View File

@@ -5,13 +5,13 @@
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Game; import pp.mdga.game.Game;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.PlayerData;
import pp.mdga.message.client.ClientMessage; import pp.mdga.message.client.ClientMessage;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.*; import pp.mdga.notification.InfoNotification;
import pp.mdga.notification.Notification;
import pp.mdga.notification.StartDialogNotification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
@@ -52,20 +52,21 @@ public ClientGameLogic(ClientSender clientSender) {
* *
* @param msg the message to be sent * @param msg the message to be sent
*/ */
public void send(ClientMessage msg){ public void send(ClientMessage msg) {
LOGGER.log(System.Logger.Level.INFO, "send {0}", msg); LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
clientSender.send(msg); clientSender.send(msg);
} }
/** /**
* This method is used to get a piece by its id * This method is used to get a piece by its id
*
* @param pieceId the UUID of the piece * @param pieceId the UUID of the piece
* @return the piece * @return the piece
*/ */
private Piece getPiece(UUID pieceId){ private Piece getPiece(UUID pieceId) {
for(Map.Entry<Color, PlayerData> entry : game.getBoard().getPlayerData().entrySet()){ for (var player : this.game.getPlayers().values()) {
for(Piece piece : entry.getValue().getPieces()){ for (Piece piece : player.getPieces()) {
if(piece.getUuid().equals(pieceId)){ if (piece.getUuid().equals(pieceId)) {
return piece; return piece;
} }
} }
@@ -78,7 +79,7 @@ private Piece getPiece(UUID pieceId){
* *
* @return the clientSender * @return the clientSender
*/ */
public ClientSender getClientSender(){ public ClientSender getClientSender() {
return clientSender; return clientSender;
} }
@@ -123,7 +124,7 @@ public void setOwnPlayerId(int ownPlayerId) {
* *
* @return the game * @return the game
*/ */
public Game getGame(){ public Game getGame() {
return game; return game;
} }
@@ -132,7 +133,7 @@ public Game getGame(){
* *
* @return the current State * @return the current State
*/ */
public ClientState getState(){ public ClientState getState() {
return state; return state;
} }
@@ -141,7 +142,7 @@ public ClientState getState(){
* *
* @return if the client is a host * @return if the client is a host
*/ */
public boolean isHost(){ public boolean isHost() {
return isHost; return isHost;
} }
@@ -150,7 +151,7 @@ public boolean isHost(){
* *
* @return the calculated moves as int * @return the calculated moves as int
*/ */
public int getCalculatedMoves(){ public int getCalculatedMoves() {
return game.getDiceEyes() * game.getDiceModifier(); return game.getDiceEyes() * game.getDiceModifier();
} }
@@ -159,7 +160,7 @@ public int getCalculatedMoves(){
* *
* @param isHost the boolean value * @param isHost the boolean value
*/ */
public void setHost(boolean isHost){ public void setHost(boolean isHost) {
this.isHost = isHost; this.isHost = isHost;
} }
@@ -480,14 +481,14 @@ public void received(SelectPieceMessage msg) {
* *
* @param pieceId the pieceID * @param pieceId the pieceID
*/ */
public void selectPiece(UUID pieceId){ public void selectPiece(UUID pieceId) {
state.selectPiece(getPiece(pieceId)); state.selectPiece(getPiece(pieceId));
} }
/** /**
* This method call the method selectNExt of the state * This method call the method selectNExt of the state
*/ */
public void selectNext(){ public void selectNext() {
state.selectNext(); state.selectNext();
} }
@@ -496,7 +497,7 @@ public void selectNext(){
* *
* @param card the BonusCard to selected * @param card the BonusCard to selected
*/ */
public void selectCard(BonusCard card){ public void selectCard(BonusCard card) {
state.selectCard(card); state.selectCard(card);
} }
@@ -505,7 +506,7 @@ public void selectCard(BonusCard card){
* *
* @param color the Color to be selected * @param color the Color to be selected
*/ */
public void selectTsk(Color color){ public void selectTsk(Color color) {
state.selectTSK(color); state.selectTSK(color);
} }
@@ -514,14 +515,14 @@ public void selectTsk(Color color){
* *
* @param color the color to be deselcted * @param color the color to be deselcted
*/ */
public void deselectTSK(Color color){ public void deselectTSK(Color color) {
state.deselectTSK(color); state.deselectTSK(color);
} }
/** /**
* This method calls the selectDice method of the state * This method calls the selectDice method of the state
*/ */
public void selectDice(){ public void selectDice() {
state.selectDice(); state.selectDice();
} }
@@ -530,7 +531,7 @@ public void selectDice(){
* *
* @param name the name to be set * @param name the name to be set
*/ */
public void selectName(String name){ public void selectName(String name) {
state.setName(name); state.setName(name);
} }
@@ -539,8 +540,8 @@ public void selectName(String name){
* *
* @param ready the value if this method should ready or unready * @param ready the value if this method should ready or unready
*/ */
public void selectReady(boolean ready){ public void selectReady(boolean ready) {
if(ready){ if (ready) {
state.selectReady(); state.selectReady();
} else { } else {
state.selectUnready(); state.selectUnready();
@@ -552,14 +553,14 @@ public void selectReady(boolean ready){
* *
* @param name the name of the player hosting * @param name the name of the player hosting
*/ */
public void selectHost(String name){ public void selectHost(String name) {
state.selectHost(name); state.selectHost(name);
} }
/** /**
* This method calls the selectLeave method of the state * This method calls the selectLeave method of the state
*/ */
public void selectLeave(){ public void selectLeave() {
state.selectLeave(); state.selectLeave();
} }
@@ -568,28 +569,28 @@ public void selectLeave(){
* *
* @param ip the ip to cennect to * @param ip the ip to cennect to
*/ */
public void selectJoin(String ip){ public void selectJoin(String ip) {
state.selectJoin(ip); state.selectJoin(ip);
} }
/** /**
* This method calls the selectAnimationEnd method of the state * This method calls the selectAnimationEnd method of the state
*/ */
public void selectAnimationEnd(){ public void selectAnimationEnd() {
state.selectAnimationEnd(); state.selectAnimationEnd();
} }
/** /**
* This method calls the selectStart method of the state * This method calls the selectStart method of the state
*/ */
public void selectStart(){ public void selectStart() {
state.selectStart(); state.selectStart();
} }
/** /**
* This method calls the selectResume method of the state * This method calls the selectResume method of the state
*/ */
public void selectResume(){ public void selectResume() {
state.selectResume(); state.selectResume();
} }
@@ -598,7 +599,7 @@ public void selectResume(){
* *
* @param state the new state * @param state the new state
*/ */
public void setState(ClientState state){ public void setState(ClientState state) {
this.state.exit(); this.state.exit();
state.enter(); state.enter();
this.state = state; this.state = state;
@@ -607,7 +608,7 @@ public void setState(ClientState state){
/** /**
* This method is used to enter the interrupt state and save the previous state * This method is used to enter the interrupt state and save the previous state
*/ */
public void enterInterrupt(){ public void enterInterrupt() {
interruptState.enter(); interruptState.enter();
interruptState.setPreviousState(state); interruptState.setPreviousState(state);
this.state = interruptState; this.state = interruptState;
@@ -618,7 +619,7 @@ public void enterInterrupt(){
* *
* @return the GameState * @return the GameState
*/ */
public GameState getGameState(){ public GameState getGameState() {
return gameState; return gameState;
} }
@@ -627,7 +628,7 @@ public GameState getGameState(){
* *
* @return the CeremonyState * @return the CeremonyState
*/ */
public CeremonyState getCeremony(){ public CeremonyState getCeremony() {
return ceremonyState; return ceremonyState;
} }
@@ -636,7 +637,7 @@ public CeremonyState getCeremony(){
* *
* @return the InterruptState * @return the InterruptState
*/ */
public InterruptState getInterrupt(){ public InterruptState getInterrupt() {
return interruptState; return interruptState;
} }
@@ -645,7 +646,7 @@ public InterruptState getInterrupt(){
* *
* @return the DialogsState * @return the DialogsState
*/ */
public DialogsState getDialogs(){ public DialogsState getDialogs() {
return dialogsState; return dialogsState;
} }
@@ -654,7 +655,7 @@ public DialogsState getDialogs(){
* *
* @return the SettingsState * @return the SettingsState
*/ */
public SettingsState getSettings(){ public SettingsState getSettings() {
return settingsState; return settingsState;
} }
@@ -663,8 +664,8 @@ public SettingsState getSettings(){
* *
* @return the next notification * @return the next notification
*/ */
public Notification getNotification(){ public Notification getNotification() {
if(!notifications.isEmpty()){ if (!notifications.isEmpty()) {
return notifications.remove(0); return notifications.remove(0);
} else { } else {
return null; return null;
@@ -676,7 +677,7 @@ public Notification getNotification(){
* *
* @param notification the notification to be added * @param notification the notification to be added
*/ */
public void addNotification(Notification notification){ public void addNotification(Notification notification) {
notifications.add(notification); notifications.add(notification);
} }

View File

@@ -5,17 +5,13 @@
import pp.mdga.client.DialogsState; import pp.mdga.client.DialogsState;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.Player;
import pp.mdga.game.PlayerData;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.LobbyPlayerJoinedMessage; import pp.mdga.message.server.*;
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
import pp.mdga.message.server.ServerStartGameMessage;
import pp.mdga.message.server.UpdateReadyMessage;
import pp.mdga.message.server.UpdateTSKMessage;
import pp.mdga.notification.*; import pp.mdga.notification.*;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class LobbyState extends DialogStates { public class LobbyState extends DialogStates {
@@ -58,15 +54,15 @@ public void selectReady() {
} }
@Override @Override
public void selectUnready(){ public void selectUnready() {
logic.send(new LobbyNotReadyMessage()); logic.send(new LobbyNotReadyMessage());
} }
@Override @Override
public void selectStart(){ public void selectStart() {
if(logic.isHost() && logic.getGame().areAllReady()){ if (logic.isHost() && logic.getGame().areAllReady()) {
logic.send(new StartGameMessage(false)); logic.send(new StartGameMessage(false));
} else if(logic.isHost() && !logic.getGame().areAllReady()) { } else if (logic.isHost() && !logic.getGame().areAllReady()) {
logic.send(new StartGameMessage(true)); logic.send(new StartGameMessage(true));
} else { } else {
LOGGER.log(System.Logger.Level.ERROR, "You are not the host"); LOGGER.log(System.Logger.Level.ERROR, "You are not the host");
@@ -74,25 +70,25 @@ public void selectStart(){
} }
@Override @Override
public void received(ServerStartGameMessage msg){ public void received(ServerStartGameMessage msg) {
logic.getGame().setBoard(msg.getBoard()); logic.getGame().setBoard(msg.getBoard());
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor())); logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
for (Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()) { for (var player : logic.getGame().getPlayers().values()) {
List<UUID> pieces = new ArrayList<>(); List<UUID> pieces = new ArrayList<>();
for (Piece piece : logic.getGame().getBoard().getPlayerData().get(entry.getValue().getColor()).getPieces()) { for (Piece piece : player.getPieces()) {
pieces.add(piece.getUuid()); pieces.add(piece.getUuid());
} }
logic.addNotification(new PlayerInGameNotification(entry.getValue().getColor(), pieces, entry.getValue().getName())); logic.addNotification(new PlayerInGameNotification(player.getColor(), pieces, player.getName()));
} }
logic.setState(logic.getGameState()); logic.setState(logic.getGameState());
} }
@Override @Override
public void received(LobbyPlayerJoinedMessage msg){ public void received(LobbyPlayerJoinedMessage msg) {
if(msg.getPlayer().getName().equals(logic.getOwnPlayerName())){ if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
logic.setOwnPlayerId(msg.getId()); logic.setOwnPlayerId(msg.getId());
} }
if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()){ if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()) {
logic.setHost(true); logic.setHost(true);
} }
@@ -101,9 +97,9 @@ public void received(LobbyPlayerJoinedMessage msg){
} }
@Override @Override
public void received(UpdateTSKMessage msg){ public void received(UpdateTSKMessage msg) {
if(msg.isTaken()) { if (msg.isTaken()) {
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), logic.getOwnPlayerId()== msg.getId())); logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), logic.getOwnPlayerId() == msg.getId()));
} else { } else {
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor())); logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
} }
@@ -112,13 +108,13 @@ public void received(UpdateTSKMessage msg){
} }
@Override @Override
public void received(LobbyPlayerLeaveMessage msg){ public void received(LobbyPlayerLeaveMessage msg) {
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor())); logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
logic.getGame().getPlayers().remove(msg.getId()); logic.getGame().getPlayers().remove(msg.getId());
} }
@Override @Override
public void received(UpdateReadyMessage msg){ public void received(UpdateReadyMessage msg) {
//TODO server sendet kein update on UNready //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

@@ -17,10 +17,10 @@ public GameStates(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
} }
protected void handlePowerCard(PlayCardMessage msg){ protected void handlePowerCard(PlayCardMessage msg) {
if (msg.getCard().equals(BonusCard.TURBO)){ if (msg.getCard().equals(BonusCard.TURBO)) {
logic.getGame().setDiceModifier(msg.getDiceModifier()); logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().equals(BonusCard.SHIELD)){ } else if (msg.getCard().equals(BonusCard.SHIELD)) {
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier())) % 10 != 0) { if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier())) % 10 != 0) {
logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED); logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).getUuid())); logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).getUuid()));
@@ -36,12 +36,12 @@ protected void handlePowerCard(PlayCardMessage msg){
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece);
logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece); logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece);
} }
logic.getGame().getDiscardPile().add(logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard())); logic.getGame().getDiscardPile().add(msg.getCard());
} }
protected void throwPiece(Piece piece){ protected void throwPiece(Piece piece) {
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
logic.getGame().getBoard().getPlayerData().get(piece.getColor()).addWaitingPiece(piece); logic.getGame().getPlayerByColor(piece.getColor()).addWaitingPiece(piece);
logic.addNotification(new ThrowPieceNotification(piece.getUuid())); logic.addNotification(new ThrowPieceNotification(piece.getUuid()));
logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown(); logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
logic.getGame().getGameStatistics().increasePiecesBeingThrown(); logic.getGame().getGameStatistics().increasePiecesBeingThrown();

View File

@@ -5,7 +5,10 @@
import pp.mdga.client.GameState; import pp.mdga.client.GameState;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.*; import pp.mdga.notification.ActivePlayerNotification;
import pp.mdga.notification.HomeMoveNotification;
import pp.mdga.notification.MovePieceNotification;
import pp.mdga.notification.PlayCardNotification;
public class SpectatorState extends GameStates { public class SpectatorState extends GameStates {
@@ -27,15 +30,15 @@ public void exit() {
} }
@Override @Override
public void received(CeremonyMessage msg){ public void received(CeremonyMessage msg) {
logic.setState(logic.getCeremony()); logic.setState(logic.getCeremony());
} }
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg) {
logic.getGame().setDiceEyes(msg.getDiceEye()); logic.getGame().setDiceEyes(msg.getDiceEye());
// logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); // logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier()));
if(msg.getDiceEye() == 6){ if (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6(); logic.getGame().getGameStatistics().increaseDiced6();
} }
@@ -43,7 +46,7 @@ public void received(DieMessage msg){
} }
@Override @Override
public void received(PlayCardMessage msg){ public void received(PlayCardMessage msg) {
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
handlePowerCard(msg); handlePowerCard(msg);
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
@@ -52,26 +55,26 @@ public void received(PlayCardMessage msg){
} }
@Override @Override
public void received(ActivePlayerMessage msg){ public void received(ActivePlayerMessage msg) {
logic.addNotification(new ActivePlayerNotification(msg.getColor())); logic.addNotification(new ActivePlayerNotification(msg.getColor()));
logic.getGame().setActiveColor(msg.getColor()); logic.getGame().setActiveColor(msg.getColor());
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg) {
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier()); Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if (msg.isHomeMove()){ if (msg.isHomeMove()) {
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove); logic.getGame().getPlayerByColor(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
} else { } else {
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown();
logic.getGame().getGameStatistics().increasePiecesThrown(); logic.getGame().getGameStatistics().increasePiecesThrown();
} }
if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ if (logic.getGame().getPlayerByColor(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)) {
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true));
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
} else { } else {

View File

@@ -3,7 +3,8 @@
import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.client.GameState; import pp.mdga.client.GameState;
import pp.mdga.game.*; import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.*; import pp.mdga.notification.*;
@@ -27,21 +28,21 @@ public void exit() {
} }
@Override @Override
public void received(CeremonyMessage msg){ public void received(CeremonyMessage msg) {
logic.setState(logic.getCeremony()); logic.setState(logic.getCeremony());
} }
@Override @Override
public void received(DiceNowMessage msg){ public void received(DiceNowMessage msg) {
logic.addNotification(new DiceNowNotification()); logic.addNotification(new DiceNowNotification());
parent.setState(parent.getTurn()); parent.setState(parent.getTurn());
} }
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg) {
logic.getGame().setDiceEyes(msg.getDiceEye()); logic.getGame().setDiceEyes(msg.getDiceEye());
// logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); // logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier()));
if(msg.getDiceEye() == 6){ if (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6(); logic.getGame().getGameStatistics().increaseDiced6();
} }
@@ -49,7 +50,7 @@ public void received(DieMessage msg){
} }
@Override @Override
public void received(PlayCardMessage msg){ public void received(PlayCardMessage msg) {
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
handlePowerCard(msg); handlePowerCard(msg);
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
@@ -58,21 +59,21 @@ public void received(PlayCardMessage msg){
} }
@Override @Override
public void received(ActivePlayerMessage msg){ public void received(ActivePlayerMessage msg) {
logic.addNotification(new ActivePlayerNotification(msg.getColor())); logic.addNotification(new ActivePlayerNotification(msg.getColor()));
logic.getGame().setActiveColor(msg.getColor()); logic.getGame().setActiveColor(msg.getColor());
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg) {
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier()); Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if (msg.isHomeMove()){ if (msg.isHomeMove()) {
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove); logic.getGame().getPlayerByColor(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
for(int i = msg.getTargetIndex() + 1; i < 4; i++){ for (int i = msg.getTargetIndex() + 1; i < 4; i++) {
if(!logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getHomeNodes()[i].isOccupied()){ if (!logic.getGame().getPlayerByColor(pieceToMove.getColor()).getHomeNodes()[i].isOccupied()) {
pieceToMove.setState(PieceState.HOME); pieceToMove.setState(PieceState.HOME);
break; break;
} }
@@ -84,7 +85,7 @@ public void received(MoveMessage msg){
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown();
logic.getGame().getGameStatistics().increasePiecesThrown(); logic.getGame().getGameStatistics().increasePiecesThrown();
} }
if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ if (logic.getGame().getPlayerByColor(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)) {
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true));
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
} else { } else {

View File

@@ -31,24 +31,24 @@ public void exit() {
} }
public void setPossiblePieces(ArrayList<Piece> possiblePieces){ public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
this.possiblePieces = possiblePieces; this.possiblePieces = possiblePieces;
} }
@Override @Override
public void selectPiece(Piece piece){ public void selectPiece(Piece piece) {
if(possiblePieces.contains(piece)){ if (possiblePieces.contains(piece)) {
logic.send(new SelectedPiecesMessage(piece.getUuid())); logic.send(new SelectedPiecesMessage(piece.getUuid()));
} }
} }
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if(msg.isHomeMove()){ if (msg.isHomeMove()) {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
logic.getGame().getBoard().getPlayerData().get(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece); logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
} else { } else {
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());

View File

@@ -1,197 +0,0 @@
package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
import pp.mdga.Resources;
/**
* 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.
*/
private HomeNode[] homeNodes;
/**
* The index of the start node for the player.
*/
private int startNodeIndex;
/**
* An array of Piece objects representing the waiting area of the player.
*/
private Piece[] waitingArea;
/**
* An array of Piece objects representing all the pieces of the player.
*/
private Piece[] pieces;
/**
* This constructor is used to create a new PlayerData object
*
* @param color the color of the player
*/
public PlayerData(Color color) {
homeNodes = new HomeNode[Resources.MAX_PIECES];
pieces = new Piece[Resources.MAX_PIECES];
waitingArea = new Piece[Resources.MAX_PIECES];
for (int i = 0; i < Resources.MAX_PIECES; i++) {
homeNodes[i] = new HomeNode();
pieces[i] = new Piece(color, PieceState.WAITING);
waitingArea[i] = pieces[i];
}
}
/**
* Constructor.
*/
private PlayerData() {
homeNodes = new HomeNode[Resources.MAX_PIECES];
waitingArea = new Piece[Resources.MAX_PIECES];
pieces = new Piece[Resources.MAX_PIECES];
}
/**
* This method will be used to check if the player is finished.
* ToDo: Currently return always false. Implement logic!
*
* @return true or false.
*/
public boolean isFinished() {
return false;
}
/**
* This method returns an Array of HomeNodes
*
* @return the array of HomeNodes
*/
public Node[] getHomeNodes() {
return homeNodes;
}
/**
* This method returns the index of the StartNode
*
* @return the index of the StartNode
*/
public int getStartNodeIndex() {
return startNodeIndex;
}
/**
* This method sets the index of the startNode.
*
* @param startNodeIndex the integer index of the startNode
*/
public void setStartNodeIndex(int startNodeIndex) {
this.startNodeIndex = startNodeIndex;
}
/**
* This method returns an array pieces representing the waiting area.
*
* @return the waiting area
*/
public Piece[] getWaitingArea() {
return waitingArea;
}
/**
* This method returns an array of pieces with all the players pieces
*
* @return the array of pieces
*/
public Piece[] getPieces() {
return pieces;
}
/**
* This method adds a piece to the waiting area
*
* @param piece the piece to be added to the waiting area
*/
public void addWaitingPiece(Piece piece) {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (waitingArea[i] == null) {
waitingArea[i] = piece;
return;
}
}
}
/**
* This method removes a piece from the waiting area
*
* @return the piece that was removed from the waiting area
*/
public Piece removePieceFromWaitingArea() {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (waitingArea[i] != null) {
Piece piece = waitingArea[i];
waitingArea[i] = null;
return piece;
}
}
return null;
}
/**
* This method sets a piece at the given index in the home area
*
* @param index the index of the node
* @param piece the piece to be set at the given index
*/
public void setPieceInHome(int index, Piece piece) {
homeNodes[index].setOccupant(piece);
}
/**
* This method will be used to return if the given piece parameter is inside the homNodes attribute of PlayerData
* class.
* If yes it will return true, otherwise false.
*
* @return true or false.
*/
public boolean homeIncludes(Piece piece) {
for (Node node : this.homeNodes) {
if (node.getOccupant() == piece) {
return true;
}
}
return false;
}
/**
* This method will be used to return the index of the given piece parameter in the homeNodes attribute of
* PlayerData class.
*
* @return index as an Integer.
*/
public int getIndexInHome(Piece piece) {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (homeNodes[i].getOccupant() == piece) {
return i;
}
}
return -1;
}
/**
* This method will be usd to check if the waitingArea attribute of PlayerData class is empty.
* If yes it will return false, otherwise true.
*
* @return true or false.
*/
public boolean hasPieceInWaitingArea() {
for (Piece piece : waitingArea) {
if (piece != null) {
return true;
}
}
return false;
}
}