Updated client states.
Updated the client states by removing all references to the 'PlayerData' class.
This commit is contained in:
		@@ -5,13 +5,13 @@
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PlayerData;
 | 
			
		||||
import pp.mdga.message.client.ClientMessage;
 | 
			
		||||
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.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -52,20 +52,21 @@ public ClientGameLogic(ClientSender clientSender) {
 | 
			
		||||
     *
 | 
			
		||||
     * @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);
 | 
			
		||||
        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()){
 | 
			
		||||
                if(piece.getUuid().equals(pieceId)){
 | 
			
		||||
    private Piece getPiece(UUID pieceId) {
 | 
			
		||||
        for (var player : this.game.getPlayers().values()) {
 | 
			
		||||
            for (Piece piece : player.getPieces()) {
 | 
			
		||||
                if (piece.getUuid().equals(pieceId)) {
 | 
			
		||||
                    return piece;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -78,7 +79,7 @@ private Piece getPiece(UUID pieceId){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the clientSender
 | 
			
		||||
     */
 | 
			
		||||
    public ClientSender getClientSender(){
 | 
			
		||||
    public ClientSender getClientSender() {
 | 
			
		||||
        return clientSender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -123,7 +124,7 @@ public void setOwnPlayerId(int ownPlayerId) {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the game
 | 
			
		||||
     */
 | 
			
		||||
    public Game getGame(){
 | 
			
		||||
    public Game getGame() {
 | 
			
		||||
        return game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -132,7 +133,7 @@ public Game getGame(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the current State
 | 
			
		||||
     */
 | 
			
		||||
    public ClientState getState(){
 | 
			
		||||
    public ClientState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -141,7 +142,7 @@ public ClientState getState(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return if the client is a host
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isHost(){
 | 
			
		||||
    public boolean isHost() {
 | 
			
		||||
        return isHost;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -150,7 +151,7 @@ public boolean isHost(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the calculated moves as int
 | 
			
		||||
     */
 | 
			
		||||
    public int getCalculatedMoves(){
 | 
			
		||||
    public int getCalculatedMoves() {
 | 
			
		||||
        return game.getDiceEyes() * game.getDiceModifier();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -159,7 +160,7 @@ public int getCalculatedMoves(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param isHost the boolean value
 | 
			
		||||
     */
 | 
			
		||||
    public void setHost(boolean isHost){
 | 
			
		||||
    public void setHost(boolean isHost) {
 | 
			
		||||
        this.isHost = isHost;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -480,14 +481,14 @@ public void received(SelectPieceMessage msg) {
 | 
			
		||||
     *
 | 
			
		||||
     * @param pieceId the pieceID
 | 
			
		||||
     */
 | 
			
		||||
    public void selectPiece(UUID pieceId){
 | 
			
		||||
    public void selectPiece(UUID pieceId) {
 | 
			
		||||
        state.selectPiece(getPiece(pieceId));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method call the method selectNExt of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectNext(){
 | 
			
		||||
    public void selectNext() {
 | 
			
		||||
        state.selectNext();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -496,7 +497,7 @@ public void selectNext(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param card the BonusCard to selected
 | 
			
		||||
     */
 | 
			
		||||
    public void selectCard(BonusCard card){
 | 
			
		||||
    public void selectCard(BonusCard card) {
 | 
			
		||||
        state.selectCard(card);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -505,7 +506,7 @@ public void selectCard(BonusCard card){
 | 
			
		||||
     *
 | 
			
		||||
     * @param color the Color to be selected
 | 
			
		||||
     */
 | 
			
		||||
    public void selectTsk(Color color){
 | 
			
		||||
    public void selectTsk(Color color) {
 | 
			
		||||
        state.selectTSK(color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -514,14 +515,14 @@ public void selectTsk(Color color){
 | 
			
		||||
     *
 | 
			
		||||
     * @param color the color to be deselcted
 | 
			
		||||
     */
 | 
			
		||||
    public void deselectTSK(Color color){
 | 
			
		||||
    public void deselectTSK(Color color) {
 | 
			
		||||
        state.deselectTSK(color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method calls the selectDice method of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectDice(){
 | 
			
		||||
    public void selectDice() {
 | 
			
		||||
        state.selectDice();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -530,7 +531,7 @@ public void selectDice(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param name the name to be set
 | 
			
		||||
     */
 | 
			
		||||
    public void selectName(String name){
 | 
			
		||||
    public void selectName(String name) {
 | 
			
		||||
        state.setName(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -539,8 +540,8 @@ public void selectName(String name){
 | 
			
		||||
     *
 | 
			
		||||
     * @param ready the value if this method should ready or unready
 | 
			
		||||
     */
 | 
			
		||||
    public void selectReady(boolean ready){
 | 
			
		||||
        if(ready){
 | 
			
		||||
    public void selectReady(boolean ready) {
 | 
			
		||||
        if (ready) {
 | 
			
		||||
            state.selectReady();
 | 
			
		||||
        } else {
 | 
			
		||||
            state.selectUnready();
 | 
			
		||||
@@ -552,14 +553,14 @@ public void selectReady(boolean ready){
 | 
			
		||||
     *
 | 
			
		||||
     * @param name the name of the player hosting
 | 
			
		||||
     */
 | 
			
		||||
    public void selectHost(String name){
 | 
			
		||||
    public void selectHost(String name) {
 | 
			
		||||
        state.selectHost(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method calls the selectLeave method of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectLeave(){
 | 
			
		||||
    public void selectLeave() {
 | 
			
		||||
        state.selectLeave();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -568,28 +569,28 @@ public void selectLeave(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param ip the ip to cennect to
 | 
			
		||||
     */
 | 
			
		||||
    public void selectJoin(String ip){
 | 
			
		||||
    public void selectJoin(String ip) {
 | 
			
		||||
        state.selectJoin(ip);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method calls the selectAnimationEnd method of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
    public void selectAnimationEnd() {
 | 
			
		||||
        state.selectAnimationEnd();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method calls the selectStart method of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectStart(){
 | 
			
		||||
    public void selectStart() {
 | 
			
		||||
        state.selectStart();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method calls the selectResume method of the state
 | 
			
		||||
     */
 | 
			
		||||
    public void selectResume(){
 | 
			
		||||
    public void selectResume() {
 | 
			
		||||
        state.selectResume();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -598,7 +599,7 @@ public void selectResume(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param state the new state
 | 
			
		||||
     */
 | 
			
		||||
    public void setState(ClientState state){
 | 
			
		||||
    public void setState(ClientState state) {
 | 
			
		||||
        this.state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        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
 | 
			
		||||
     */
 | 
			
		||||
    public void enterInterrupt(){
 | 
			
		||||
    public void enterInterrupt() {
 | 
			
		||||
        interruptState.enter();
 | 
			
		||||
        interruptState.setPreviousState(state);
 | 
			
		||||
        this.state = interruptState;
 | 
			
		||||
@@ -618,7 +619,7 @@ public void enterInterrupt(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the GameState
 | 
			
		||||
     */
 | 
			
		||||
    public GameState getGameState(){
 | 
			
		||||
    public GameState getGameState() {
 | 
			
		||||
        return gameState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -627,7 +628,7 @@ public GameState getGameState(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the CeremonyState
 | 
			
		||||
     */
 | 
			
		||||
    public CeremonyState getCeremony(){
 | 
			
		||||
    public CeremonyState getCeremony() {
 | 
			
		||||
        return ceremonyState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -636,7 +637,7 @@ public CeremonyState getCeremony(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the InterruptState
 | 
			
		||||
     */
 | 
			
		||||
    public InterruptState getInterrupt(){
 | 
			
		||||
    public InterruptState getInterrupt() {
 | 
			
		||||
        return interruptState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -645,7 +646,7 @@ public InterruptState getInterrupt(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the DialogsState
 | 
			
		||||
     */
 | 
			
		||||
    public DialogsState getDialogs(){
 | 
			
		||||
    public DialogsState getDialogs() {
 | 
			
		||||
        return dialogsState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -654,7 +655,7 @@ public DialogsState getDialogs(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the SettingsState
 | 
			
		||||
     */
 | 
			
		||||
    public SettingsState getSettings(){
 | 
			
		||||
    public SettingsState getSettings() {
 | 
			
		||||
        return settingsState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -663,8 +664,8 @@ public SettingsState getSettings(){
 | 
			
		||||
     *
 | 
			
		||||
     * @return the next notification
 | 
			
		||||
     */
 | 
			
		||||
    public Notification getNotification(){
 | 
			
		||||
        if(!notifications.isEmpty()){
 | 
			
		||||
    public Notification getNotification() {
 | 
			
		||||
        if (!notifications.isEmpty()) {
 | 
			
		||||
            return notifications.remove(0);
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
@@ -676,7 +677,7 @@ public Notification getNotification(){
 | 
			
		||||
     *
 | 
			
		||||
     * @param notification the notification to be added
 | 
			
		||||
     */
 | 
			
		||||
    public void addNotification(Notification notification){
 | 
			
		||||
    public void addNotification(Notification notification) {
 | 
			
		||||
        notifications.add(notification);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,17 +5,13 @@
 | 
			
		||||
import pp.mdga.client.DialogsState;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.game.PlayerData;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.LobbyPlayerJoinedMessage;
 | 
			
		||||
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.message.server.*;
 | 
			
		||||
import pp.mdga.notification.*;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class LobbyState extends DialogStates {
 | 
			
		||||
 | 
			
		||||
@@ -58,15 +54,15 @@ public void selectReady() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectUnready(){
 | 
			
		||||
    public void selectUnready() {
 | 
			
		||||
        logic.send(new LobbyNotReadyMessage());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectStart(){
 | 
			
		||||
        if(logic.isHost() && logic.getGame().areAllReady()){
 | 
			
		||||
    public void selectStart() {
 | 
			
		||||
        if (logic.isHost() && logic.getGame().areAllReady()) {
 | 
			
		||||
            logic.send(new StartGameMessage(false));
 | 
			
		||||
        } else if(logic.isHost() && !logic.getGame().areAllReady()) {
 | 
			
		||||
        } else if (logic.isHost() && !logic.getGame().areAllReady()) {
 | 
			
		||||
            logic.send(new StartGameMessage(true));
 | 
			
		||||
        } else {
 | 
			
		||||
            LOGGER.log(System.Logger.Level.ERROR, "You are not the host");
 | 
			
		||||
@@ -74,25 +70,25 @@ public void selectStart(){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ServerStartGameMessage msg){
 | 
			
		||||
    public void received(ServerStartGameMessage msg) {
 | 
			
		||||
        logic.getGame().setBoard(msg.getBoard());
 | 
			
		||||
        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<>();
 | 
			
		||||
            for (Piece piece : logic.getGame().getBoard().getPlayerData().get(entry.getValue().getColor()).getPieces()) {
 | 
			
		||||
            for (Piece piece : player.getPieces()) {
 | 
			
		||||
                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());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerJoinedMessage msg){
 | 
			
		||||
        if(msg.getPlayer().getName().equals(logic.getOwnPlayerName())){
 | 
			
		||||
    public void received(LobbyPlayerJoinedMessage msg) {
 | 
			
		||||
        if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
 | 
			
		||||
            logic.setOwnPlayerId(msg.getId());
 | 
			
		||||
        }
 | 
			
		||||
        if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()){
 | 
			
		||||
        if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()) {
 | 
			
		||||
            logic.setHost(true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -101,9 +97,9 @@ public void received(LobbyPlayerJoinedMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(UpdateTSKMessage msg){
 | 
			
		||||
        if(msg.isTaken()) {
 | 
			
		||||
            logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), logic.getOwnPlayerId()== msg.getId()));
 | 
			
		||||
    public void received(UpdateTSKMessage msg) {
 | 
			
		||||
        if (msg.isTaken()) {
 | 
			
		||||
            logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), logic.getOwnPlayerId() == msg.getId()));
 | 
			
		||||
        } else {
 | 
			
		||||
            logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
 | 
			
		||||
        }
 | 
			
		||||
@@ -112,13 +108,13 @@ public void received(UpdateTSKMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerLeaveMessage msg){
 | 
			
		||||
    public void received(LobbyPlayerLeaveMessage msg) {
 | 
			
		||||
        logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
 | 
			
		||||
        logic.getGame().getPlayers().remove(msg.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
 | 
			
		||||
 
 | 
			
		||||
@@ -17,10 +17,10 @@ public GameStates(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void handlePowerCard(PlayCardMessage msg){
 | 
			
		||||
        if (msg.getCard().equals(BonusCard.TURBO)){
 | 
			
		||||
    protected void handlePowerCard(PlayCardMessage msg) {
 | 
			
		||||
        if (msg.getCard().equals(BonusCard.TURBO)) {
 | 
			
		||||
            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) {
 | 
			
		||||
                logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);
 | 
			
		||||
                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()[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().getPlayerData().get(piece.getColor()).addWaitingPiece(piece);
 | 
			
		||||
        logic.getGame().getPlayerByColor(piece.getColor()).addWaitingPiece(piece);
 | 
			
		||||
        logic.addNotification(new ThrowPieceNotification(piece.getUuid()));
 | 
			
		||||
        logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
 | 
			
		||||
        logic.getGame().getGameStatistics().increasePiecesBeingThrown();
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,10 @@
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
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 {
 | 
			
		||||
 | 
			
		||||
@@ -27,15 +30,15 @@ public void exit() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg){
 | 
			
		||||
    public void received(CeremonyMessage msg) {
 | 
			
		||||
        logic.setState(logic.getCeremony());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DieMessage msg){
 | 
			
		||||
    public void received(DieMessage msg) {
 | 
			
		||||
        logic.getGame().setDiceEyes(msg.getDiceEye());
 | 
			
		||||
//        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().getGameStatistics().increaseDiced6();
 | 
			
		||||
        }
 | 
			
		||||
@@ -43,7 +46,7 @@ public void received(DieMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCardMessage msg){
 | 
			
		||||
    public void received(PlayCardMessage msg) {
 | 
			
		||||
        logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
 | 
			
		||||
        handlePowerCard(msg);
 | 
			
		||||
        logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
 | 
			
		||||
@@ -52,26 +55,26 @@ public void received(PlayCardMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ActivePlayerMessage msg){
 | 
			
		||||
    public void received(ActivePlayerMessage msg) {
 | 
			
		||||
        logic.addNotification(new ActivePlayerNotification(msg.getColor()));
 | 
			
		||||
        logic.getGame().setActiveColor(msg.getColor());
 | 
			
		||||
        parent.setState(parent.getAnimation());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg){
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        if (msg.isHomeMove()){
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            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 {
 | 
			
		||||
            if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
 | 
			
		||||
                throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
 | 
			
		||||
                logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().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.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
 | 
			
		||||
            } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,8 @@
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
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.notification.*;
 | 
			
		||||
 | 
			
		||||
@@ -27,21 +28,21 @@ public void exit() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg){
 | 
			
		||||
    public void received(CeremonyMessage msg) {
 | 
			
		||||
        logic.setState(logic.getCeremony());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DiceNowMessage msg){
 | 
			
		||||
    public void received(DiceNowMessage msg) {
 | 
			
		||||
        logic.addNotification(new DiceNowNotification());
 | 
			
		||||
        parent.setState(parent.getTurn());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DieMessage msg){
 | 
			
		||||
    public void received(DieMessage msg) {
 | 
			
		||||
        logic.getGame().setDiceEyes(msg.getDiceEye());
 | 
			
		||||
//        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().getGameStatistics().increaseDiced6();
 | 
			
		||||
        }
 | 
			
		||||
@@ -49,7 +50,7 @@ public void received(DieMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCardMessage msg){
 | 
			
		||||
    public void received(PlayCardMessage msg) {
 | 
			
		||||
        logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
 | 
			
		||||
        handlePowerCard(msg);
 | 
			
		||||
        logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
 | 
			
		||||
@@ -58,21 +59,21 @@ public void received(PlayCardMessage msg){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ActivePlayerMessage msg){
 | 
			
		||||
    public void received(ActivePlayerMessage msg) {
 | 
			
		||||
        logic.addNotification(new ActivePlayerNotification(msg.getColor()));
 | 
			
		||||
        logic.getGame().setActiveColor(msg.getColor());
 | 
			
		||||
        parent.setState(parent.getAnimation());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg){
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        if (msg.isHomeMove()){
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
 | 
			
		||||
            logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
 | 
			
		||||
            for(int i = msg.getTargetIndex() + 1; i < 4; i++){
 | 
			
		||||
                if(!logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getHomeNodes()[i].isOccupied()){
 | 
			
		||||
            logic.getGame().getPlayerByColor(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
 | 
			
		||||
            for (int i = msg.getTargetIndex() + 1; i < 4; i++) {
 | 
			
		||||
                if (!logic.getGame().getPlayerByColor(pieceToMove.getColor()).getHomeNodes()[i].isOccupied()) {
 | 
			
		||||
                    pieceToMove.setState(PieceState.HOME);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
@@ -84,7 +85,7 @@ public void received(MoveMessage msg){
 | 
			
		||||
                logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().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.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
 | 
			
		||||
            } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,24 +31,24 @@ public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPossiblePieces(ArrayList<Piece> possiblePieces){
 | 
			
		||||
    public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
 | 
			
		||||
        this.possiblePieces = possiblePieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectPiece(Piece piece){
 | 
			
		||||
        if(possiblePieces.contains(piece)){
 | 
			
		||||
    public void selectPiece(Piece piece) {
 | 
			
		||||
        if (possiblePieces.contains(piece)) {
 | 
			
		||||
            logic.send(new SelectedPiecesMessage(piece.getUuid()));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg){
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        if(msg.isHomeMove()){
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            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 {
 | 
			
		||||
            if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
 | 
			
		||||
                throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user