merge after refactoring #16
@@ -11,8 +11,8 @@ public class InputSyncronizer {
 | 
			
		||||
    private InputManager inputManager;
 | 
			
		||||
 | 
			
		||||
    protected boolean rightMousePressed = false;
 | 
			
		||||
    private float rotationAngle = 0f;
 | 
			
		||||
    private int scrollValue = 50;
 | 
			
		||||
    private float rotationAngle = 180f;
 | 
			
		||||
    private int scrollValue = 0;
 | 
			
		||||
 | 
			
		||||
    InputSyncronizer(MdgaApp app) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
@@ -22,11 +22,6 @@ public class InputSyncronizer {
 | 
			
		||||
        setupInput();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void update() {
 | 
			
		||||
        rotateModel();
 | 
			
		||||
        updateScrollValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setupInput() {
 | 
			
		||||
        inputManager.addMapping("Settings", new KeyTrigger(KeyInput.KEY_ESCAPE));
 | 
			
		||||
 | 
			
		||||
@@ -57,25 +52,21 @@ public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
        public void onAnalog(String name, float value, float tpf) {
 | 
			
		||||
            if (name.equals("MouseLeft") && rightMousePressed) {
 | 
			
		||||
                rotationAngle -= value * 360f;
 | 
			
		||||
                rotateModel();
 | 
			
		||||
            } else if (name.equals("MouseRight") && rightMousePressed) {
 | 
			
		||||
                rotationAngle += value * 360f;
 | 
			
		||||
                rotateModel();
 | 
			
		||||
            } else if (name.equals("MouseScrollUp")) {
 | 
			
		||||
                scrollValue = Math.min(100, scrollValue + 1);
 | 
			
		||||
                updateScrollValue();
 | 
			
		||||
                scrollValue = Math.max(1, scrollValue - 5);
 | 
			
		||||
            } else if (name.equals("MouseScrollDown")) {
 | 
			
		||||
                scrollValue = Math.max(1, scrollValue - 1);
 | 
			
		||||
                updateScrollValue();
 | 
			
		||||
                scrollValue = Math.min(100, scrollValue + 5);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private void rotateModel() {
 | 
			
		||||
        //System.out.println("Rotation Angle: " + rotationAngle);
 | 
			
		||||
    public float getRotation() {
 | 
			
		||||
        return (rotationAngle / 2) % 360;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void updateScrollValue() {
 | 
			
		||||
        //System.out.println("Scroll Value: " + scrollValue);
 | 
			
		||||
    public int getScroll() {
 | 
			
		||||
        return scrollValue;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ public class MdgaApp extends SimpleApplication {
 | 
			
		||||
    MdgaView view = null;
 | 
			
		||||
    private MdgaState state = MdgaState.MAIN;
 | 
			
		||||
 | 
			
		||||
    private static float resolutionFactor = 1f;
 | 
			
		||||
    private static float resolutionFactor = 1.8f;
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        AppSettings settings = new AppSettings(true);
 | 
			
		||||
@@ -47,6 +47,10 @@ public void simpleInitApp() {
 | 
			
		||||
        modelSyncronizer = new ModelSyncronizer(this);
 | 
			
		||||
 | 
			
		||||
        inputManager.deleteMapping("SIMPLEAPP_Exit");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_ZoomIn");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_ZoomOut");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_RotateDrag");
 | 
			
		||||
        flyCam.setEnabled(false);
 | 
			
		||||
        GuiGlobals.initialize(this);
 | 
			
		||||
 | 
			
		||||
        enter(state);
 | 
			
		||||
@@ -54,7 +58,6 @@ public void simpleInitApp() {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void simpleUpdate(float tpf) {
 | 
			
		||||
        inputSyncronizer.update();
 | 
			
		||||
        view.update();
 | 
			
		||||
        acousticHandler.update();
 | 
			
		||||
        notificationSynchronizer.update();
 | 
			
		||||
@@ -114,4 +117,6 @@ public MdgaView getView() {
 | 
			
		||||
    public ModelSyncronizer getModelSyncronizer() {
 | 
			
		||||
        return modelSyncronizer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InputSyncronizer getInputSyncronizer() { return inputSyncronizer; }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,5 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.notification.Notification;
 | 
			
		||||
import pp.mdga.notification.PieceInGameNotification;
 | 
			
		||||
import pp.mdga.notification.PlayerInGameNotification;
 | 
			
		||||
 | 
			
		||||
public enum MdgaState {
 | 
			
		||||
    NONE,
 | 
			
		||||
    MAIN,
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.view.GameView;
 | 
			
		||||
import pp.mdga.client.view.LobbyView;
 | 
			
		||||
import pp.mdga.notification.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
import com.jme3.light.AmbientLight;
 | 
			
		||||
import com.jme3.light.DirectionalLight;
 | 
			
		||||
import com.jme3.math.ColorRGBA;
 | 
			
		||||
import com.jme3.math.FastMath;
 | 
			
		||||
import com.jme3.math.Vector3f;
 | 
			
		||||
import com.jme3.post.FilterPostProcessor;
 | 
			
		||||
import com.jme3.shadow.DirectionalLightShadowFilter;
 | 
			
		||||
@@ -32,11 +33,6 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void init() {
 | 
			
		||||
        app.getFlyByCamera().setEnabled(true);
 | 
			
		||||
        int zoom = 20;
 | 
			
		||||
        app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
 | 
			
		||||
        app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
 | 
			
		||||
 | 
			
		||||
        app.getRootNode().addLight(sun);
 | 
			
		||||
        app.getRootNode().addLight(ambient);
 | 
			
		||||
    }
 | 
			
		||||
@@ -45,4 +41,37 @@ public void shutdown() {
 | 
			
		||||
        app.getRootNode().removeLight(sun);
 | 
			
		||||
        app.getRootNode().removeLight(ambient);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void update(float scroll, float rotation) {
 | 
			
		||||
        float scrollValue = Math.max(0, Math.min(scroll, 100));
 | 
			
		||||
 | 
			
		||||
        float rotationValue = rotation % 360;
 | 
			
		||||
        if (rotationValue < 0) {
 | 
			
		||||
            rotationValue += 360;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        float radius;
 | 
			
		||||
 | 
			
		||||
        float verticalAngle;
 | 
			
		||||
        if (scroll < 100f) {
 | 
			
		||||
            verticalAngle = 20f + (scrollValue / 100f) * 45f;
 | 
			
		||||
            radius = 30f;
 | 
			
		||||
        } else {
 | 
			
		||||
            verticalAngle = 90f;
 | 
			
		||||
            rotationValue = 270f;
 | 
			
		||||
            radius = 50f;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        float verticalAngleRadians = FastMath.DEG_TO_RAD * verticalAngle;
 | 
			
		||||
 | 
			
		||||
        float z = radius * FastMath.sin(verticalAngleRadians);
 | 
			
		||||
        float x = radius * FastMath.cos(verticalAngleRadians) * FastMath.sin(FastMath.DEG_TO_RAD * rotationValue);
 | 
			
		||||
        float y = radius * FastMath.cos(verticalAngleRadians) * FastMath.cos(FastMath.DEG_TO_RAD * rotationValue);
 | 
			
		||||
 | 
			
		||||
        Vector3f cameraPosition = new Vector3f(x, y, z);
 | 
			
		||||
        app.getCamera().setLocation(cameraPosition);
 | 
			
		||||
 | 
			
		||||
        app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,12 @@
 | 
			
		||||
package pp.mdga.client.board.Outline;
 | 
			
		||||
 | 
			
		||||
import com.jme3.asset.AssetManager;
 | 
			
		||||
import com.jme3.material.Material;
 | 
			
		||||
import com.jme3.material.RenderState;
 | 
			
		||||
import com.jme3.material.RenderState.BlendMode;
 | 
			
		||||
import com.jme3.math.ColorRGBA;
 | 
			
		||||
import com.jme3.post.Filter;
 | 
			
		||||
import com.jme3.post.FilterPostProcessor;
 | 
			
		||||
import com.jme3.renderer.Camera;
 | 
			
		||||
import com.jme3.renderer.RenderManager;
 | 
			
		||||
import com.jme3.renderer.ViewPort;
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.Spatial;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
 | 
			
		||||
public class SelectObjectOutliner {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package pp.mdga.client.dialog;
 | 
			
		||||
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
public class GetPercentRunnable {
 | 
			
		||||
    private final Supplier<Float> action;
 | 
			
		||||
 | 
			
		||||
    public GetPercentRunnable(Supplier<Float> action) {
 | 
			
		||||
        this.action = action;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float get() {
 | 
			
		||||
        return action.get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -26,7 +26,7 @@ public HostDialog(MdgaApp app, Node node, Runnable backAction) {
 | 
			
		||||
        Panel imagePanel = new Panel();
 | 
			
		||||
        imagePanel.setBackground(b);
 | 
			
		||||
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 0));
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0));
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ public JoinDialog(MdgaApp app, Node node, Runnable backAction) {
 | 
			
		||||
        Panel imagePanel = new Panel();
 | 
			
		||||
        imagePanel.setBackground(b);
 | 
			
		||||
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 0));
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0));
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ public class SettingsDialog extends Dialog {
 | 
			
		||||
    private TextField nameInput;
 | 
			
		||||
 | 
			
		||||
    private HashMap<Slider, PercentRunnable> map = new HashMap<Slider, PercentRunnable>();
 | 
			
		||||
    private HashMap<Slider, GetPercentRunnable> map2 = new HashMap<Slider, GetPercentRunnable>();
 | 
			
		||||
 | 
			
		||||
    public SettingsDialog(MdgaApp app, Node node, String path) {
 | 
			
		||||
        super(app, node);
 | 
			
		||||
@@ -62,7 +63,7 @@ public void addButton(String label, Runnable action, Vector3f size) {
 | 
			
		||||
        createButton(label, action, size);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addSlider(String label, PercentRunnable action, Vector3f size, int start) {
 | 
			
		||||
    public void addSlider(String label, PercentRunnable action, GetPercentRunnable action2, Vector3f size, int start) {
 | 
			
		||||
        Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
 | 
			
		||||
 | 
			
		||||
        Slider slider = new Slider("slider");
 | 
			
		||||
@@ -71,7 +72,7 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
 | 
			
		||||
        slider.setBackground(background);
 | 
			
		||||
 | 
			
		||||
        slider.setPreferredSize(size);
 | 
			
		||||
        slider.setModel(new DefaultRangedValueModel(0, 10, start));
 | 
			
		||||
        slider.setModel(new DefaultRangedValueModel(0, 100, start));
 | 
			
		||||
        slider.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 30 * app.getResolutionFactor(), 0));
 | 
			
		||||
        slider.getDecrementButton().setText(" - ");
 | 
			
		||||
        slider.getIncrementButton().setText(" + ");
 | 
			
		||||
@@ -89,11 +90,19 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
 | 
			
		||||
        container.addChild(subContainer);
 | 
			
		||||
 | 
			
		||||
        map.put(slider, action);
 | 
			
		||||
        map2.put(slider, action2);
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(20 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void initVolume() {
 | 
			
		||||
        map2.forEach((slider, runnable) -> {
 | 
			
		||||
            double val = (double) runnable.get();
 | 
			
		||||
            slider.getModel().setPercent(val);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void update() {
 | 
			
		||||
        map.forEach((slider, runnable) -> {
 | 
			
		||||
            float val = (float) slider.getModel().getPercent();
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,209 @@
 | 
			
		||||
package pp.mdga.client.server;
 | 
			
		||||
 | 
			
		||||
import com.jme3.network.ConnectionListener;
 | 
			
		||||
import com.jme3.network.HostedConnection;
 | 
			
		||||
import com.jme3.network.Message;
 | 
			
		||||
import com.jme3.network.MessageListener;
 | 
			
		||||
import com.jme3.network.Network;
 | 
			
		||||
import com.jme3.network.Server;
 | 
			
		||||
import com.jme3.network.serializing.Serializer;
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.ServerSender;
 | 
			
		||||
 | 
			
		||||
import java.io.FileInputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.lang.System.Logger;
 | 
			
		||||
import java.lang.System.Logger.Level;
 | 
			
		||||
import java.util.concurrent.BlockingQueue;
 | 
			
		||||
import java.util.concurrent.LinkedBlockingQueue;
 | 
			
		||||
import java.util.logging.LogManager;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Server implementing the visitor pattern as MessageReceiver for ClientMessages
 | 
			
		||||
 */
 | 
			
		||||
public class MdgaServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
 | 
			
		||||
    private static final Logger LOGGER = System.getLogger(MdgaServer.class.getName());
 | 
			
		||||
 | 
			
		||||
    private Server myServer;
 | 
			
		||||
    private final ServerGameLogic logic;
 | 
			
		||||
    private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
        // Configure logging
 | 
			
		||||
        LogManager manager = LogManager.getLogManager();
 | 
			
		||||
        try {
 | 
			
		||||
            manager.readConfiguration(new FileInputStream("logging.properties"));
 | 
			
		||||
            LOGGER.log(Level.INFO, "Successfully read logging properties"); //NON-NLS
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            LOGGER.log(Level.INFO, e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Starts the Battleships server.
 | 
			
		||||
     */
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        new MdgaServer().run();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new MdgaServer.
 | 
			
		||||
     */
 | 
			
		||||
    public MdgaServer() {
 | 
			
		||||
        LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS
 | 
			
		||||
        logic = new ServerGameLogic(new Game(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void run() {
 | 
			
		||||
        startServer();
 | 
			
		||||
        this.connectionAdded(myServer, myServer.getConnection(0));
 | 
			
		||||
        while (true)
 | 
			
		||||
            processNextMessage();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void startServer() {
 | 
			
		||||
        try {
 | 
			
		||||
            LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
 | 
			
		||||
            myServer = Network.createServer(1234);
 | 
			
		||||
 | 
			
		||||
            initializeSerializables();
 | 
			
		||||
            myServer.start();
 | 
			
		||||
            registerListeners();
 | 
			
		||||
            LOGGER.log(Level.INFO, "Server started: {0}", myServer.isRunning()); //NON-NLS
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            LOGGER.log(Level.ERROR, "Couldn't start server: {0}", e.getMessage()); //NON-NLS
 | 
			
		||||
            exit(1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void processNextMessage() {
 | 
			
		||||
        try {
 | 
			
		||||
            pendingMessages.take().process(logic);
 | 
			
		||||
        } catch (InterruptedException ex) {
 | 
			
		||||
            LOGGER.log(Level.INFO, "Interrupted while waiting for messages"); //NON-NLS
 | 
			
		||||
            Thread.currentThread().interrupt();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initializeSerializables() {
 | 
			
		||||
        Serializer.registerClass(AnimationEnd.class);
 | 
			
		||||
        Serializer.registerClass(ClientStartGame.class);
 | 
			
		||||
        Serializer.registerClass(DeselectTSK.class);
 | 
			
		||||
        Serializer.registerClass(ForceContinueGame.class);
 | 
			
		||||
        Serializer.registerClass(ForceStartGame.class);
 | 
			
		||||
        Serializer.registerClass(JoinServer.class);
 | 
			
		||||
        Serializer.registerClass(LeaveGame.class);
 | 
			
		||||
        Serializer.registerClass(LobbyNotReady.class);
 | 
			
		||||
        Serializer.registerClass(LobbyReady.class);
 | 
			
		||||
        Serializer.registerClass(NoPowerCard.class);
 | 
			
		||||
        Serializer.registerClass(RequestBriefing.class);
 | 
			
		||||
        Serializer.registerClass(RequestDice.class);
 | 
			
		||||
        Serializer.registerClass(RequestMove.class);
 | 
			
		||||
        Serializer.registerClass(RequestPlayCard.class);
 | 
			
		||||
        Serializer.registerClass(SelectCard.class);
 | 
			
		||||
        Serializer.registerClass(SelectedPieces.class);
 | 
			
		||||
        Serializer.registerClass(SelectTSK.class);
 | 
			
		||||
 | 
			
		||||
        Serializer.registerClass(ActivePlayer.class);
 | 
			
		||||
        Serializer.registerClass(AnyPiece.class);
 | 
			
		||||
        Serializer.registerClass(Briefing.class);
 | 
			
		||||
        Serializer.registerClass(CeremonyMessage.class);
 | 
			
		||||
        Serializer.registerClass(Dice.class);
 | 
			
		||||
        Serializer.registerClass(DiceAgain.class);
 | 
			
		||||
        Serializer.registerClass(DiceNow.class);
 | 
			
		||||
        Serializer.registerClass(EndOfTurn.class);
 | 
			
		||||
        Serializer.registerClass(LobbyAccept.class);
 | 
			
		||||
        Serializer.registerClass(LobbyDeny.class);
 | 
			
		||||
        Serializer.registerClass(LobbyPlayerJoin.class);
 | 
			
		||||
        Serializer.registerClass(LobbyPlayerLeave.class);
 | 
			
		||||
        Serializer.registerClass(MoveMessage.class);
 | 
			
		||||
        Serializer.registerClass(NoTurn.class);
 | 
			
		||||
        Serializer.registerClass(PauseGame.class);
 | 
			
		||||
        Serializer.registerClass(PlayCard.class);
 | 
			
		||||
        Serializer.registerClass(PossibleCard.class);
 | 
			
		||||
        Serializer.registerClass(PossiblePiece.class);
 | 
			
		||||
        Serializer.registerClass(RankingResponse.class);
 | 
			
		||||
        Serializer.registerClass(RankingRollAgain.class);
 | 
			
		||||
        Serializer.registerClass(ReconnectBriefing.class);
 | 
			
		||||
        Serializer.registerClass(ResumeGame.class);
 | 
			
		||||
        Serializer.registerClass(ServerStartGame.class);
 | 
			
		||||
        Serializer.registerClass(StartPiece.class);
 | 
			
		||||
        Serializer.registerClass(UpdateReady.class);
 | 
			
		||||
        Serializer.registerClass(UpdateTSK.class);
 | 
			
		||||
        Serializer.registerClass(WaitPiece.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void registerListeners() {
 | 
			
		||||
        myServer.addMessageListener(this, AnimationEnd.class);
 | 
			
		||||
        myServer.addMessageListener(this, ClientStartGame.class);
 | 
			
		||||
        myServer.addMessageListener(this, DeselectTSK.class);
 | 
			
		||||
        myServer.addMessageListener(this, ForceContinueGame.class);
 | 
			
		||||
        myServer.addMessageListener(this, ForceStartGame.class);
 | 
			
		||||
        myServer.addMessageListener(this, JoinServer.class);
 | 
			
		||||
        myServer.addMessageListener(this, LeaveGame.class);
 | 
			
		||||
        myServer.addMessageListener(this, LobbyNotReady.class);
 | 
			
		||||
        myServer.addMessageListener(this, LobbyReady.class);
 | 
			
		||||
        myServer.addMessageListener(this, NoPowerCard.class);
 | 
			
		||||
        myServer.addMessageListener(this, RequestBriefing.class);
 | 
			
		||||
        myServer.addMessageListener(this, RequestDice.class);
 | 
			
		||||
        myServer.addMessageListener(this, RequestMove.class);
 | 
			
		||||
        myServer.addMessageListener(this, RequestPlayCard.class);
 | 
			
		||||
        myServer.addMessageListener(this, SelectCard.class);
 | 
			
		||||
        myServer.addMessageListener(this, SelectedPieces.class);
 | 
			
		||||
        myServer.addMessageListener(this, SelectTSK.class);
 | 
			
		||||
        myServer.addConnectionListener(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void messageReceived(HostedConnection source, Message message) {
 | 
			
		||||
        LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
 | 
			
		||||
        if (message instanceof ClientMessage clientMessage)
 | 
			
		||||
            pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void connectionAdded(Server server, HostedConnection hostedConnection) {
 | 
			
		||||
        LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
 | 
			
		||||
        logic.addPlayer(hostedConnection.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void connectionRemoved(Server server, HostedConnection hostedConnection) {
 | 
			
		||||
        LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
 | 
			
		||||
        final Player player = logic.getPlayerById(hostedConnection.getId());
 | 
			
		||||
        if (player == null)
 | 
			
		||||
            LOGGER.log(Level.INFO, "closed connection does not belong to an active player"); //NON-NLS
 | 
			
		||||
        else { //NON-NLS
 | 
			
		||||
            LOGGER.log(Level.INFO, "closed connection belongs to {0}", player); //NON-NLS
 | 
			
		||||
            exit(0);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void exit(int exitValue) { //NON-NLS
 | 
			
		||||
        LOGGER.log(Level.INFO, "close request"); //NON-NLS
 | 
			
		||||
        if (myServer != null)
 | 
			
		||||
            for (HostedConnection client : myServer.getConnections()) //NON-NLS
 | 
			
		||||
                if (client != null) client.close("Game over"); //NON-NLS
 | 
			
		||||
        System.exit(exitValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the specified message to the specified connection.
 | 
			
		||||
     *
 | 
			
		||||
     * @param id      the connection id
 | 
			
		||||
     * @param message the message
 | 
			
		||||
     */
 | 
			
		||||
    public void send(int id, ServerMessage message) {
 | 
			
		||||
        if (myServer == null || !myServer.isRunning()) {
 | 
			
		||||
            LOGGER.log(Level.ERROR, "no server running when trying to send {0}", message); //NON-NLS
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        final HostedConnection connection = myServer.getConnection(id);
 | 
			
		||||
        if (connection != null)
 | 
			
		||||
            connection.send(message);
 | 
			
		||||
        else
 | 
			
		||||
            LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
package pp.mdga.client.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.ClientInterpreter;
 | 
			
		||||
import pp.mdga.message.client.ClientMessage;
 | 
			
		||||
 | 
			
		||||
public record ReceivedMessage(ClientMessage msg, int from) {
 | 
			
		||||
    void process(ClientInterpreter interpreter) {
 | 
			
		||||
        msg.accept(interpreter, from);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -8,11 +8,6 @@
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
import pp.mdga.client.MdgaState;
 | 
			
		||||
import pp.mdga.client.gui.GuiHandler;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class GameView extends MdgaView {
 | 
			
		||||
    private BoardHandler boardHandler;
 | 
			
		||||
@@ -55,6 +50,11 @@ public void onLeave() {
 | 
			
		||||
        boardHandler.shutdown();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onUpdate() {
 | 
			
		||||
        camera.update(app.getInputSyncronizer().getScroll(), app.getInputSyncronizer().getRotation());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void enterExtendedSettings() {
 | 
			
		||||
        leaveButton.show();
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,6 @@
 | 
			
		||||
import pp.mdga.client.dialog.SingleButtonLeftDialog;
 | 
			
		||||
import pp.mdga.client.dialog.SingleButtonRightDialog;
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
import pp.mdga.client.MdgaState;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.shape.Quad;
 | 
			
		||||
import com.jme3.texture.Texture;
 | 
			
		||||
import pp.mdga.client.dialog.GetPercentRunnable;
 | 
			
		||||
import pp.mdga.client.dialog.PercentRunnable;
 | 
			
		||||
import pp.mdga.client.dialog.SettingsButtonDialog;
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
@@ -61,9 +62,9 @@ public MdgaView(MdgaApp app) {
 | 
			
		||||
        this.settings.addButton("Zurück", () -> leaveSettings(false), size);
 | 
			
		||||
 | 
			
		||||
        this.audio = new SettingsDialog(app, audioSettingsNode, "audio_icon.png");
 | 
			
		||||
        this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), size, 5);
 | 
			
		||||
        this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), size, 10);
 | 
			
		||||
        this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), size, 10);
 | 
			
		||||
        this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), new GetPercentRunnable(app.getAcousticHandler()::getMainVolume), size, (int) app.getAcousticHandler().getMainVolume() * 100);
 | 
			
		||||
        this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), new GetPercentRunnable(app.getAcousticHandler()::getMusicVolume), size, (int) app.getAcousticHandler().getMusicVolume() * 100);
 | 
			
		||||
        this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), new GetPercentRunnable(app.getAcousticHandler()::getSoundVolume), size, (int) app.getAcousticHandler().getSoundVolume() * 100);
 | 
			
		||||
        this.audio.addButton("Zurück", () -> leaveAudio(), size);
 | 
			
		||||
 | 
			
		||||
        this.video = new SettingsDialog(app, videoSettingsNode, "monitor.png");
 | 
			
		||||
@@ -75,6 +76,8 @@ public MdgaView(MdgaApp app) {
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        app.getGuiNode().attachChild(node);
 | 
			
		||||
 | 
			
		||||
        audio.initVolume();
 | 
			
		||||
 | 
			
		||||
        settingsButton.show();
 | 
			
		||||
 | 
			
		||||
        onEnter();
 | 
			
		||||
@@ -90,10 +93,12 @@ public void leave() {
 | 
			
		||||
 | 
			
		||||
    public void update() {
 | 
			
		||||
        audio.update();
 | 
			
		||||
        onUpdate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected abstract void onEnter();
 | 
			
		||||
    protected abstract void onLeave();
 | 
			
		||||
    protected void onUpdate() {}
 | 
			
		||||
 | 
			
		||||
    protected Geometry createBackground(String texturePath) {
 | 
			
		||||
        TextureKey key = new TextureKey(texturePath, true);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Projekte/mdga/client/src/main/resources/test.png~
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Projekte/mdga/client/src/main/resources/test.png~
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.2 MiB  | 
@@ -1,35 +0,0 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.message.client.ClientMessage;
 | 
			
		||||
 | 
			
		||||
public class ClientGameLogic {
 | 
			
		||||
    static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
 | 
			
		||||
 | 
			
		||||
    private Game game;
 | 
			
		||||
    private final ClientSender clientSender;
 | 
			
		||||
    private ClientState state;
 | 
			
		||||
 | 
			
		||||
    public ClientGameLogic(Game game, ClientSender clientSender) {
 | 
			
		||||
        this.game = game;
 | 
			
		||||
        this.clientSender = clientSender;
 | 
			
		||||
        state = new ClientAutomaton(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void send(ClientMessage msg){
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
 | 
			
		||||
        clientSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ClientSender getClientSender(){
 | 
			
		||||
        return clientSender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Game getGame(){
 | 
			
		||||
        return game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ClientState getState(){
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,70 +0,0 @@
 | 
			
		||||
package pp.mdga.message.client;
 | 
			
		||||
 | 
			
		||||
import com.jme3.network.serializing.Serializable;
 | 
			
		||||
import pp.mdga.game.BonusCard;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A message sent by a client to request playing a bonus card.
 | 
			
		||||
 */
 | 
			
		||||
@Serializable
 | 
			
		||||
public class RequestPlayCard extends ClientMessage {
 | 
			
		||||
    /**
 | 
			
		||||
     * The bonus card to be played.
 | 
			
		||||
     */
 | 
			
		||||
    private final BonusCard card;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The identifier of the piece.
 | 
			
		||||
     */
 | 
			
		||||
    private final String pieceIdentifier;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new RequestPlayCard instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param card the bonus card to be played
 | 
			
		||||
     * @param pieceIdentifier the identifier of the piece
 | 
			
		||||
     */
 | 
			
		||||
    public RequestPlayCard(BonusCard card, String pieceIdentifier) {
 | 
			
		||||
        this.pieceIdentifier = pieceIdentifier;
 | 
			
		||||
        this.card = card;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the bonus card associated with this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the bonus card
 | 
			
		||||
     */
 | 
			
		||||
    public BonusCard getCard() {
 | 
			
		||||
        return card;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the piece identifier associated with this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the piece identifier
 | 
			
		||||
     */
 | 
			
		||||
    public String getPieceIdentifier() {
 | 
			
		||||
        return pieceIdentifier;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a string representation of this message.
 | 
			
		||||
     *
 | 
			
		||||
     * @return a string representation of this message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "RequestPlayCard={card=" + card.toString() + '}';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Accepts a visitor to process this message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param interpreter the visitor to process this message
 | 
			
		||||
     * @param from        the connection ID from which the message was received
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void accept(ClientInterpreter interpreter, int from) {
 | 
			
		||||
        interpreter.received(this, from);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.AnimationEnd;
 | 
			
		||||
import pp.mdga.message.server.DiceNow;
 | 
			
		||||
 | 
			
		||||
public class Animation extends ServerState {
 | 
			
		||||
    public Animation(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedAnimationEnd(AnimationEnd msg, int from) {
 | 
			
		||||
        logic.send(logic.getGame().getStartPlayer(), new DiceNow());
 | 
			
		||||
        parent.gotoState(new Turn(parent, logic));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class Ceremony extends ServerState {
 | 
			
		||||
    public Ceremony(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class ChoosePiece extends ServerState {
 | 
			
		||||
    private final ChoosePieceStateMachine choosePieceStateMachine = new ChoosePieceStateMachine(this, logic);
 | 
			
		||||
 | 
			
		||||
    public ChoosePiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class ChoosePieceStateMachine extends ServerStateMachine{
 | 
			
		||||
    public ChoosePieceStateMachine(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public NoPiece initialState() {
 | 
			
		||||
        return new NoPiece(this, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestDice;
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Random;
 | 
			
		||||
 | 
			
		||||
public class DetermineStartPlayer extends ServerState {
 | 
			
		||||
    private final List<Player> player = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public DetermineStartPlayer(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        logic.getGame().addObserver(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
        final Random random = new Random();
 | 
			
		||||
        final int dice = random.nextInt(6) + 1;
 | 
			
		||||
        broadcastUpdate(new Dice(dice, new ArrayList<>()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        if (Boolean.TRUE.equals(logic.getGame().allRanked())) {
 | 
			
		||||
            broadcastUpdate(new RankingResponse());
 | 
			
		||||
            if (logic.getGame().getOrder().isEmpty()) {
 | 
			
		||||
                // todo: save the players with the same value?
 | 
			
		||||
                broadcastUpdate(new RankingRollAgain());
 | 
			
		||||
                broadcastUpdate(new EndOfTurn());
 | 
			
		||||
            } else {
 | 
			
		||||
                // todo: set start player
 | 
			
		||||
                Player startPlayer = new Player(1);
 | 
			
		||||
                logic.getGame().setStartPlayer(startPlayer);
 | 
			
		||||
                logic.send(startPlayer, new DiceNow());
 | 
			
		||||
                broadcastUpdate(new EndOfTurn());
 | 
			
		||||
                parent.gotoState(new Animation(parent, logic));
 | 
			
		||||
                logic.getGame().removeObserver(this);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.RequestDice;
 | 
			
		||||
 | 
			
		||||
public class FirstRoll extends ServerState {
 | 
			
		||||
    public FirstRoll(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
        // todo: implement player.hasMovablePieces()
 | 
			
		||||
//        if (player.hasMovablePieces()) {
 | 
			
		||||
//            // todo: goto ChoosePiece
 | 
			
		||||
//        } else {
 | 
			
		||||
//            // todo: implement roll
 | 
			
		||||
//            if (roll == 6) {
 | 
			
		||||
//                // todo: send to everyone? or one player?
 | 
			
		||||
//                logic.send(new Player(1), new Dice());
 | 
			
		||||
//                // todo: goto ChoosePiece
 | 
			
		||||
//            } else {
 | 
			
		||||
//                // todo: send to everyone? or one player?
 | 
			
		||||
//                logic.send(new Player(1), new DiceAgain());
 | 
			
		||||
//                parent.gotoState(new SecondRoll(parent, logic));
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,69 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.PauseGame;
 | 
			
		||||
import pp.mdga.message.server.PossibleCard;
 | 
			
		||||
import pp.mdga.message.server.RankingResponse;
 | 
			
		||||
 | 
			
		||||
public class GameState extends ServerState {
 | 
			
		||||
    private final GameStateMachine gameStateMachine = new GameStateMachine(this, logic);
 | 
			
		||||
 | 
			
		||||
    public GameState(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        logic.getGame().addObserver(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void entry() {
 | 
			
		||||
        gameStateMachine.entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        parent.gotoState(new Ceremony(parent, logic));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedAnimationEnd(AnimationEnd msg, int from) {
 | 
			
		||||
        gameStateMachine.receivedAnimationEnd(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedNoPowerCard(NoPowerCard msg, int from) {
 | 
			
		||||
        gameStateMachine.receivedNoPowerCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectCard(SelectCard msg, int from) {
 | 
			
		||||
        gameStateMachine.receivedSelectCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
        gameStateMachine.receivedRequestDice(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectedPieces(SelectedPieces msg, int from) {
 | 
			
		||||
        gameStateMachine.receivedSelectedPieces(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentPossibleCard(PossibleCard msg, int from) {
 | 
			
		||||
        gameStateMachine.sentPossibleCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentRankingResponse(RankingResponse msg, int from) {
 | 
			
		||||
        gameStateMachine.sentRankingResponse(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        if (Boolean.TRUE.equals(logic.getGame().playerHasDisconnected())) {
 | 
			
		||||
            broadcastUpdate(new PauseGame());
 | 
			
		||||
            parent.gotoState(new Interrupt(parent, logic, this));
 | 
			
		||||
            logic.getGame().removeObserver(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,26 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The GameStateMachine class represents the state machine for the game state.
 | 
			
		||||
 */
 | 
			
		||||
public class GameStateMachine extends ServerStateMachine {
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new GameStateMachine with the specified parent state and game logic.
 | 
			
		||||
     *
 | 
			
		||||
     * @param parent the parent state
 | 
			
		||||
     * @param logic  the server game logic
 | 
			
		||||
     */
 | 
			
		||||
    public GameStateMachine(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the initial state of the state machine, which is DetermineStartPlayer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the initial state
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public DetermineStartPlayer initialState() {
 | 
			
		||||
        return new DetermineStartPlayer(this, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.server.ResumeGame;
 | 
			
		||||
 | 
			
		||||
public class Interrupt extends ServerState {
 | 
			
		||||
    private final GameState lastState;
 | 
			
		||||
 | 
			
		||||
    public Interrupt(ServerState parent, ServerGameLogic logic, GameState lastState) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.lastState = lastState;
 | 
			
		||||
        logic.getGame().addObserver(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        if (Boolean.FALSE.equals(logic.getGame().gameIsInterrupted())) {
 | 
			
		||||
            broadcastUpdate(new ResumeGame());
 | 
			
		||||
            parent.gotoState(lastState);
 | 
			
		||||
            logic.getGame().removeObserver(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,94 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.ServerMessage;
 | 
			
		||||
import pp.mdga.message.server.ServerStartGame;
 | 
			
		||||
import pp.mdga.message.server.UpdateReady;
 | 
			
		||||
import pp.mdga.message.server.UpdateTSK;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents the lobby state of the server.
 | 
			
		||||
 */
 | 
			
		||||
public class Lobby extends ServerState {
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new Lobby state.
 | 
			
		||||
     *
 | 
			
		||||
     * @param parent the parent state
 | 
			
		||||
     * @param logic  the server game logic
 | 
			
		||||
     */
 | 
			
		||||
    public Lobby(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles the DeselectTSK message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the DeselectTSK message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedDeselectTSK(DeselectTSK msg, int from) {
 | 
			
		||||
        broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles the LobbyNotReady message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyNotReady message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedNotReady(LobbyNotReady msg, int from) {
 | 
			
		||||
        broadcastUpdate(new UpdateReady(getPlayerColor(from), false));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles the LobbyReady message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyReady message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedReady(LobbyReady msg, int from) {
 | 
			
		||||
        broadcastUpdate(new UpdateReady(getPlayerColor(from), true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Helper method to get the color associated with a player ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @param playerId The ID of the player.
 | 
			
		||||
     * @return The Color associated with the player, or null if not found.
 | 
			
		||||
     */
 | 
			
		||||
    private Color getPlayerColor(int playerId) {
 | 
			
		||||
        Player player = logic.getPlayerById(playerId);
 | 
			
		||||
 | 
			
		||||
        for (var entry : logic.getGame().getPlayers().entrySet()) {
 | 
			
		||||
            if (entry.getValue().equals(player)) {
 | 
			
		||||
                return entry.getKey();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles the SelectTSK message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectTSK message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectTSK(SelectTSK msg, int from) {
 | 
			
		||||
        broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles the ClientStartGame message.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the ClientStartGame message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedStartGame(ClientStartGame msg, int from) {
 | 
			
		||||
        if (Boolean.TRUE.equals(logic.getGame().allReady())) {
 | 
			
		||||
            broadcastUpdate(new ServerStartGame());
 | 
			
		||||
            parent.gotoState(new GameState(parent, logic));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class MovePiece extends ServerState {
 | 
			
		||||
    public MovePiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,55 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.server.WaitPiece;
 | 
			
		||||
 | 
			
		||||
public class NoPiece extends ServerState {
 | 
			
		||||
    public NoPiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void entry() {
 | 
			
		||||
//        if (hasTurbo() || turbo == 0) {
 | 
			
		||||
//            if (roll == 6 &&
 | 
			
		||||
//                logic.getGame().getBoard().getPlayerData().getWaitingArea().hasPieces() &&
 | 
			
		||||
//                logic.getGame().getBoard().getNodes().getStartNode(Color).isOccupied()) {
 | 
			
		||||
//                parent.gotoState(new WaitingPiece(parent, logic));
 | 
			
		||||
//            } else {
 | 
			
		||||
//                parent.gotoState(new NoTurn(parent, logic));
 | 
			
		||||
//            }
 | 
			
		||||
//        } else {
 | 
			
		||||
//            validateHasPieces();
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void validateHasPieces() {
 | 
			
		||||
//        if (logic.getGame().getBoard().getPlayerData().getWaitingArea().hasPieces()) {
 | 
			
		||||
//            if (logic.getGame().getBoard().getNodes().getStartNode(Color).isOccupied()) {
 | 
			
		||||
//                if (roll == 6) {
 | 
			
		||||
//                    logic.send(new Player(1), new WaitPiece());
 | 
			
		||||
//                } else {
 | 
			
		||||
//                    validateMove();
 | 
			
		||||
//                }
 | 
			
		||||
//            } else {
 | 
			
		||||
//                if (logic.getGame().getBoard().getNodes().getStartNode(Color).getPiece().canMove()) {
 | 
			
		||||
//                    logic.send(new Player(1), new WaitPiece());
 | 
			
		||||
//                    parent.gotoState(new StartPiece(parent, logic));
 | 
			
		||||
//                } else {
 | 
			
		||||
//                    validateMove();
 | 
			
		||||
//                }
 | 
			
		||||
//            }
 | 
			
		||||
//        } else {
 | 
			
		||||
//            validateMove();
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void validateMove() {
 | 
			
		||||
//        if (player.canMove()) {
 | 
			
		||||
//            parent.gotoState(new NoTurn(parent, logic));
 | 
			
		||||
//        } else {
 | 
			
		||||
//            logic.send(new Player(1), new SelectPiece());
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,14 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.server.EndOfTurn;
 | 
			
		||||
 | 
			
		||||
public class NoTurn extends ServerState {
 | 
			
		||||
    public NoTurn(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentEndOfTurn(EndOfTurn msg, int from) {
 | 
			
		||||
        // todo: goto end of turn
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public interface Observer {
 | 
			
		||||
    void update();
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class PlayPowerCard extends ServerState {
 | 
			
		||||
    public PlayPowerCard(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,54 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.NoPowerCard;
 | 
			
		||||
import pp.mdga.message.client.SelectCard;
 | 
			
		||||
import pp.mdga.message.client.SelectedPieces;
 | 
			
		||||
import pp.mdga.message.server.DiceNow;
 | 
			
		||||
import pp.mdga.message.server.PossibleCard;
 | 
			
		||||
 | 
			
		||||
public class PowerCard extends ServerState {
 | 
			
		||||
    public PowerCard(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        logic.getGame().addObserver(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedNoPowerCard(NoPowerCard msg, int from) {
 | 
			
		||||
        // todo: send to everyone? or one player?
 | 
			
		||||
        // todo: right msg?
 | 
			
		||||
        logic.send(new Player(1), new DiceNow());
 | 
			
		||||
        parent.gotoState(new RollDice(parent, logic));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectCard(SelectCard msg, int from) {
 | 
			
		||||
        // todo: send to everyone? or one player?
 | 
			
		||||
        logic.send(new Player(1), new PossibleCard());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectedPieces(SelectedPieces msg, int from) {
 | 
			
		||||
//        if (verifySelectedPieces()) {
 | 
			
		||||
//            // todo: send to everyone? or one player?
 | 
			
		||||
//            // todo: msg PowerCardAnimation?
 | 
			
		||||
//            logic.send(new Player(1), new PowerCardAnimation());
 | 
			
		||||
//            parent.gotoState(new PlayPowerCard(parent, logic));
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentPossibleCard(PossibleCard msg, int from) {
 | 
			
		||||
        // todo: implement
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        if (!super.getMoveablePieces(logic.getGame().getActiveColor()).isEmpty()) {
 | 
			
		||||
            // todo: send to everyone? or one player?
 | 
			
		||||
            // todo: right msg?
 | 
			
		||||
            logic.send(new Player(1), new DiceNow());
 | 
			
		||||
            parent.gotoState(new RollDice(parent, logic));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class RollDice extends ServerState {
 | 
			
		||||
    private final RollDiceMachine rollDiceMachine = new RollDiceMachine(this, logic);
 | 
			
		||||
 | 
			
		||||
    public RollDice(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class RollDiceMachine extends ServerStateMachine {
 | 
			
		||||
    public RollDiceMachine(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public FirstRoll initialState() {
 | 
			
		||||
        return new FirstRoll(this, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestDice;
 | 
			
		||||
import pp.mdga.message.server.Dice;
 | 
			
		||||
import pp.mdga.message.server.DiceAgain;
 | 
			
		||||
 | 
			
		||||
public class SecondRoll extends ServerState {
 | 
			
		||||
    public SecondRoll(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
//        if (roll == 6) {
 | 
			
		||||
//            // todo: send to everyone? or one player?
 | 
			
		||||
//            logic.send(new Player(1), new Dice());
 | 
			
		||||
//            // todo: goto ChoosePiece
 | 
			
		||||
//        } else {
 | 
			
		||||
//            // todo: send to everyone? or one player?
 | 
			
		||||
//            logic.send(new Player(1), new DiceAgain());
 | 
			
		||||
//            parent.gotoState(new ThirdRoll(parent, logic));
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestMove;
 | 
			
		||||
import pp.mdga.message.server.StartPiece;
 | 
			
		||||
 | 
			
		||||
public class SelectPiece extends ServerState {
 | 
			
		||||
    public SelectPiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestMove(RequestMove msg, int from) {
 | 
			
		||||
//        if (verifyPiece(p)) {
 | 
			
		||||
//            logic.send(new Player(1), new Animation());
 | 
			
		||||
//            // todo: goto state
 | 
			
		||||
//        } else {
 | 
			
		||||
//            logic.send(new Player(1), new StartPiece());
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The ServerAutomaton class represents the top-level state machine for the server.
 | 
			
		||||
 * It initializes the state machine and sets the initial state to Lobby.
 | 
			
		||||
 */
 | 
			
		||||
public class ServerAutomaton extends ServerStateMachine {
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new ServerAutomaton with the specified game logic.
 | 
			
		||||
     *
 | 
			
		||||
     * @param logic the server game logic
 | 
			
		||||
     */
 | 
			
		||||
    public ServerAutomaton(ServerGameLogic logic) {
 | 
			
		||||
        super(null, logic);
 | 
			
		||||
        entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the initial state of the state machine, which is Lobby.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the initial state
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public Lobby initialState() {
 | 
			
		||||
        return new Lobby(this, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,145 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.ServerMessage;
 | 
			
		||||
 | 
			
		||||
import java.lang.System.Logger;
 | 
			
		||||
 | 
			
		||||
public class ServerGameLogic implements ClientInterpreter {
 | 
			
		||||
    static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName());
 | 
			
		||||
 | 
			
		||||
    private final Game game;
 | 
			
		||||
    private final ServerSender serverSender;
 | 
			
		||||
    private ServerState state;
 | 
			
		||||
 | 
			
		||||
    public ServerGameLogic(Game game, ServerSender serverSender) {
 | 
			
		||||
        this.game = game;
 | 
			
		||||
        this.serverSender = serverSender;
 | 
			
		||||
        state = new ServerAutomaton(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(AnimationEnd animationEnd, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DeselectTSK deselectTSK, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ForceStartGame forceStartGame, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(JoinServer joinServer, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LeaveGame leaveGame, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyNotReady lobbyNotReady, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyReady lobbyReady, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestBriefing requestBriefing, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestDice requestDice, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestMove requestMove, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestPlayCard requestPlayCard, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectCard selectCard, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectTSK selectTSK, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ForceContinueGame forceContinueGame, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ClientStartGame clientStartGame, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(NoPowerCard noPowerCard, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectedPieces selectedPieces, int from) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends a message to the specified player.
 | 
			
		||||
     *
 | 
			
		||||
     * @param player the player to send the message to
 | 
			
		||||
     * @param msg    the message to send
 | 
			
		||||
     */
 | 
			
		||||
    public void send(Player player, ServerMessage msg) {
 | 
			
		||||
        LOGGER.log(Logger.Level.INFO, "sending to {0}: {1}", player, msg); //NON-NLS
 | 
			
		||||
        serverSender.send(player.getId(), msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ServerSender getServerSender() {
 | 
			
		||||
        return serverSender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Game getGame() {
 | 
			
		||||
        return game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the player representing the client with the specified connection ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @param id the ID of the client
 | 
			
		||||
     * @return the player associated with the client ID, or null if not found
 | 
			
		||||
     */
 | 
			
		||||
    public Player getPlayerById(int id) {
 | 
			
		||||
        for (var entry : game.getPlayers().entrySet())
 | 
			
		||||
            if (entry.getValue().getId() == id)
 | 
			
		||||
                return entry.getValue();
 | 
			
		||||
        LOGGER.log(Logger.Level.ERROR, "no player found with connection {0}", id); //NON-NLS
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ServerState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.server.ServerMessage;
 | 
			
		||||
 | 
			
		||||
public interface ServerSender {
 | 
			
		||||
    void send(int id, ServerMessage msg);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,324 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Node;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PieceState;
 | 
			
		||||
import pp.mdga.game.PlayerData;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurn;
 | 
			
		||||
import pp.mdga.message.server.PossibleCard;
 | 
			
		||||
import pp.mdga.message.server.RankingResponse;
 | 
			
		||||
import pp.mdga.message.server.ServerMessage;
 | 
			
		||||
 | 
			
		||||
import java.lang.System.Logger;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Abstract class representing a state in the server's state machine.
 | 
			
		||||
 * Implements the Observer pattern to observe changes in the game state.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class ServerState implements Observer {
 | 
			
		||||
    /**
 | 
			
		||||
     * Logger for logging messages within the application.
 | 
			
		||||
     */
 | 
			
		||||
    protected static final Logger LOGGER = System.getLogger(ServerState.class.getName());
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The parent state of the current state.
 | 
			
		||||
     */
 | 
			
		||||
    protected ServerState parent;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The game logic associated with the server state.
 | 
			
		||||
     */
 | 
			
		||||
    protected ServerGameLogic logic;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new ServerState with the specified parent state and game logic.
 | 
			
		||||
     *
 | 
			
		||||
     * @param parent the parent state of the current state
 | 
			
		||||
     * @param logic  the game logic associated with the server state
 | 
			
		||||
     */
 | 
			
		||||
    protected ServerState(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        this.parent = parent;
 | 
			
		||||
        this.logic = logic;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when the state is entered.
 | 
			
		||||
     */
 | 
			
		||||
    public void entry() { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when the state is exited.
 | 
			
		||||
     */
 | 
			
		||||
    public void exit() { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when an animation ends.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the animation end message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedAnimationEnd(AnimationEnd msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a TSK is deselected.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the deselect TSK message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedDeselectTSK(DeselectTSK msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a NoPowerCard message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the NoPowerCard message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedNoPowerCard(NoPowerCard msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a LobbyNotReady message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyNotReady message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedNotReady(LobbyNotReady msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a LobbyReady message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyReady message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedReady(LobbyReady msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RequestDice message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RequestDice message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RequestMove message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RequestMove message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedRequestMove(RequestMove msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectCard message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectCard message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedSelectCard(SelectCard msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectTSK message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectTSK message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedSelectTSK(SelectTSK msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectedPieces message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectedPieces message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedSelectedPieces(SelectedPieces msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a StartGame message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the StartGame message
 | 
			
		||||
     */
 | 
			
		||||
    public void receivedStartGame(ClientStartGame msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when an EndOfTurn message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the EndOfTurn message
 | 
			
		||||
     */
 | 
			
		||||
    public void sentEndOfTurn(EndOfTurn msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a PossibleCard message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the PossibleCard message
 | 
			
		||||
     */
 | 
			
		||||
    public void sentPossibleCard(PossibleCard msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RankingResponce message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RankingResponce message
 | 
			
		||||
     */
 | 
			
		||||
    public void sentRankingResponse(RankingResponse msg, int from) { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method transitions to a new state.
 | 
			
		||||
     *
 | 
			
		||||
     * @param state the new state to transition to
 | 
			
		||||
     * @throws IllegalStateException if called outside a state machine
 | 
			
		||||
     */
 | 
			
		||||
    public void gotoState(ServerState state) {
 | 
			
		||||
        throw new IllegalStateException("not in a statemachine");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the parent state of the current state.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the parent state
 | 
			
		||||
     */
 | 
			
		||||
    public ServerState getParent() {
 | 
			
		||||
        return parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when the observed object is changed.
 | 
			
		||||
     * It is part of the Observer pattern implementation.
 | 
			
		||||
     */
 | 
			
		||||
    public void update() { /* do nothing */ }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to calculate the steps a piece can move
 | 
			
		||||
     *
 | 
			
		||||
     * @return the steps a piece can move
 | 
			
		||||
     */
 | 
			
		||||
    private int calculateSteps() {
 | 
			
		||||
        return logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to test if u can move a piece
 | 
			
		||||
     *
 | 
			
		||||
     * @param piece the piece to be moved
 | 
			
		||||
     * @return true if the piece can be moved, false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    protected boolean tryMove(Piece piece) {
 | 
			
		||||
        int steps = calculateSteps();
 | 
			
		||||
        if (piece.getState() == PieceState.HOME) {
 | 
			
		||||
            return tryHomeMove(piece, steps);
 | 
			
		||||
        } else {
 | 
			
		||||
            int homeMoves = getHomeMoves(piece, steps);
 | 
			
		||||
            if (homeMoves > 0) {
 | 
			
		||||
                return tryHomeMove(piece, homeMoves);
 | 
			
		||||
            } else {
 | 
			
		||||
                return tryInfieldMove(piece, steps);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to determine if a piece would move into the home area.
 | 
			
		||||
     *
 | 
			
		||||
     * @param piece the piece to be moved
 | 
			
		||||
     * @param steps the steps the piece would move
 | 
			
		||||
     * @return the number of steps the piece would move into the home area
 | 
			
		||||
     */
 | 
			
		||||
    protected int getHomeMoves(Piece piece, int steps) {
 | 
			
		||||
        int figureIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        Color col = piece.getColor();
 | 
			
		||||
        int startIndex = logic.getGame().getBoard().getPlayerData().get(col).getStartNodeIndex();
 | 
			
		||||
        int moveIndex = startIndex + steps;
 | 
			
		||||
        if (moveIndex > logic.getGame().getBoard().getInfield().length) {
 | 
			
		||||
            moveIndex %= logic.getGame().getBoard().getInfield().length;
 | 
			
		||||
            if (moveIndex >= startIndex) {
 | 
			
		||||
                return moveIndex - startIndex + 1;
 | 
			
		||||
            }
 | 
			
		||||
        } else if (figureIndex < startIndex && moveIndex >= startIndex) {
 | 
			
		||||
            return moveIndex - startIndex + 1;
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to determine if a piece can move in the infield
 | 
			
		||||
     *
 | 
			
		||||
     * @param piece the piece to be moved
 | 
			
		||||
     * @param steps the steps the piece would move
 | 
			
		||||
     * @return true if the piece can move in the infield, false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    protected boolean tryInfieldMove(Piece piece, int steps) {
 | 
			
		||||
        int figureIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        int moveIndex = (figureIndex + steps) % logic.getGame().getBoard().getInfield().length;
 | 
			
		||||
        Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
 | 
			
		||||
        if (occupant != null) {
 | 
			
		||||
            return occupant.getColor() != piece.getColor();
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to determine if a piece can move inside the home area
 | 
			
		||||
     *
 | 
			
		||||
     * @param piece the piece to be moved
 | 
			
		||||
     * @param steps the steps the piece would move
 | 
			
		||||
     * @return true if the piece can move into the home area, false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    protected boolean tryHomeMove(Piece piece, int steps) {
 | 
			
		||||
        Color col = piece.getColor();
 | 
			
		||||
        PlayerData playerData = logic.getGame().getBoard().getPlayerData().get(col);
 | 
			
		||||
        Node[] homeNodes = playerData.getHomeNodes();
 | 
			
		||||
        int index;
 | 
			
		||||
 | 
			
		||||
        if (playerData.homeIncludes(piece)) {
 | 
			
		||||
            index = playerData.getIndexInHome(piece);
 | 
			
		||||
        } else {
 | 
			
		||||
            index = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (index + steps >= homeNodes.length) {
 | 
			
		||||
            return false;
 | 
			
		||||
        } else {
 | 
			
		||||
            for (int i = index; i <= index + steps; i++) {
 | 
			
		||||
                if (homeNodes[i].getOccupant() != null) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to get the pieces that can be moved
 | 
			
		||||
     *
 | 
			
		||||
     * @param color the color of the pieces
 | 
			
		||||
     * @return the pieces that can be moved
 | 
			
		||||
     */
 | 
			
		||||
    protected List<Piece> getMoveablePieces(Color color) {
 | 
			
		||||
        ArrayList<Piece> moveablePieces = new ArrayList<>();
 | 
			
		||||
        ArrayList<Piece> pieces = new ArrayList<>();
 | 
			
		||||
        for (Piece piece : logic.getGame().getBoard().getPlayerData().get(color).getPieces()) {
 | 
			
		||||
            if (piece.getState() == PieceState.ACTIVE || piece.getState() == PieceState.HOME) {
 | 
			
		||||
                pieces.add(piece);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (Piece piece : pieces) {
 | 
			
		||||
            if (tryMove(piece)) {
 | 
			
		||||
                moveablePieces.add(piece);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return moveablePieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Broadcasts an update message to all players.
 | 
			
		||||
     *
 | 
			
		||||
     * @param updateMessage the update message to be sent
 | 
			
		||||
     */
 | 
			
		||||
    protected void broadcastUpdate(ServerMessage updateMessage) {
 | 
			
		||||
        for (var entry : logic.getGame().getPlayers().entrySet()) {
 | 
			
		||||
            logic.send(entry.getValue(), updateMessage);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a string representation of the object.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the simple name of the class
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return getClass().getSimpleName();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,234 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurn;
 | 
			
		||||
import pp.mdga.message.server.PossibleCard;
 | 
			
		||||
import pp.mdga.message.server.RankingResponse;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Abstract class representing a state machine for the server.
 | 
			
		||||
 * It manages the transitions between different states and delegates
 | 
			
		||||
 * the handling of messages to the current state.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class ServerStateMachine extends ServerState {
 | 
			
		||||
    /**
 | 
			
		||||
     * The current state of the state machine.
 | 
			
		||||
     */
 | 
			
		||||
    private ServerState state;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new instance of ServerStateMachine.
 | 
			
		||||
     *
 | 
			
		||||
     * @param parent the parent state
 | 
			
		||||
     * @param logic  the server game logic
 | 
			
		||||
     */
 | 
			
		||||
    protected ServerStateMachine(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates the initial state of a state machine.
 | 
			
		||||
     */
 | 
			
		||||
    public abstract ServerState initialState();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Transitions to a new state.
 | 
			
		||||
     *
 | 
			
		||||
     * @param newState the new state to transition to
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void gotoState(ServerState newState) {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "{0}: {1} --> {2}", this, state, newState);
 | 
			
		||||
        enter(newState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when the state is entered.
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void entry() {
 | 
			
		||||
        final ServerState newState = initialState();
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "{0}: initial state={1}", this, newState);
 | 
			
		||||
        enter(newState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Enters a new state.
 | 
			
		||||
     *
 | 
			
		||||
     * @param newState the new state to enter
 | 
			
		||||
     * @throws IllegalArgumentException if the new state does not belong to this state machine
 | 
			
		||||
     */
 | 
			
		||||
    private void enter(ServerState newState) {
 | 
			
		||||
        if (newState.parent != this)
 | 
			
		||||
            throw new IllegalArgumentException("Wrong state: " + newState + " belongs to " + newState.parent + " instead of " + this);
 | 
			
		||||
        state = newState;
 | 
			
		||||
        state.entry();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when the state is exited.
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        state.exit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when an animation ends.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the animation end message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedAnimationEnd(AnimationEnd msg, int from) {
 | 
			
		||||
        state.receivedAnimationEnd(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a TSK is deselected.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the deselect TSK message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedDeselectTSK(DeselectTSK msg, int from) {
 | 
			
		||||
        state.receivedDeselectTSK(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a NoPowerCard message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the NoPowerCard message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedNoPowerCard(NoPowerCard msg, int from) {
 | 
			
		||||
        state.receivedNoPowerCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a LobbyNotReady message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyNotReady message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedNotReady(LobbyNotReady msg, int from) {
 | 
			
		||||
        state.receivedNotReady(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a LobbyReady message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the LobbyReady message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedReady(LobbyReady msg, int from) {
 | 
			
		||||
        state.receivedReady(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RequestDice message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RequestDice message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
        state.receivedRequestDice(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RequestMove message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RequestMove message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestMove(RequestMove msg, int from) {
 | 
			
		||||
        state.receivedRequestMove(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectCard message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectCard message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectCard(SelectCard msg, int from) {
 | 
			
		||||
        state.receivedSelectCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectTSK message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectTSK message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectTSK(SelectTSK msg, int from) {
 | 
			
		||||
        state.receivedSelectTSK(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a SelectedPieces message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the SelectedPieces message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedSelectedPieces(SelectedPieces msg, int from) {
 | 
			
		||||
        state.receivedSelectedPieces(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a StartGame message is received.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the StartGame message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedStartGame(ClientStartGame msg, int from) {
 | 
			
		||||
        state.receivedStartGame(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when an EndOfTurn message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the EndOfTurn message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentEndOfTurn(EndOfTurn msg, int from) {
 | 
			
		||||
        state.sentEndOfTurn(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a PossibleCard message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the PossibleCard message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentPossibleCard(PossibleCard msg, int from) {
 | 
			
		||||
        state.sentPossibleCard(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is called when a RankingResponse message is sent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the RankingResponse message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sentRankingResponse(RankingResponse msg, int from) {
 | 
			
		||||
        state.sentRankingResponse(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a string representation of the object, including the current state.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the string representation of the object
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return super.toString() + "(in " + state + ")";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the current state.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the current state
 | 
			
		||||
     */
 | 
			
		||||
    public ServerState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,21 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestMove;
 | 
			
		||||
 | 
			
		||||
public class StartPiece extends ServerState {
 | 
			
		||||
    public StartPiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestMove(RequestMove msg, int from) {
 | 
			
		||||
//        if (verifyPiece(p)) {
 | 
			
		||||
//            logic.send(new Player(1), new Animation());
 | 
			
		||||
//            // todo: goto state
 | 
			
		||||
//        } else {
 | 
			
		||||
//            logic.send(new Player(1), new pp.mdga.message.server.StartPiece());
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestDice;
 | 
			
		||||
import pp.mdga.message.server.Dice;
 | 
			
		||||
import pp.mdga.message.server.DiceAgain;
 | 
			
		||||
 | 
			
		||||
public class ThirdRoll extends ServerState {
 | 
			
		||||
    public ThirdRoll(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestDice(RequestDice msg, int from) {
 | 
			
		||||
//        if (roll == 6) {
 | 
			
		||||
//            // todo: send to everyone? or one player?
 | 
			
		||||
//            logic.send(new Player(1), new Dice());
 | 
			
		||||
//            // todo: goto ChoosePiece
 | 
			
		||||
//        } else {
 | 
			
		||||
//            // todo: send to everyone? or one player?
 | 
			
		||||
//            logic.send(new Player(1), new DiceAgain());
 | 
			
		||||
//            // todo: goto End from Turn
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,34 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.server.ActivePlayer;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
 | 
			
		||||
public class Turn extends ServerState {
 | 
			
		||||
    private final TurnStateMachine turnStateMachine = new TurnStateMachine(this, logic);
 | 
			
		||||
 | 
			
		||||
    public Turn(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // todo: when TurnStateMachine is in the end state, and then?
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        Player player = logic.getGame().getStartPlayer();
 | 
			
		||||
 | 
			
		||||
//        if (player.isFinished()) {
 | 
			
		||||
//            logic.send(player, new Spectator());
 | 
			
		||||
//        } else {
 | 
			
		||||
//            logic.send(player, new EndOfTurn());
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
        if (logic.getGame().getPlayers().size() == 1) {
 | 
			
		||||
            broadcastUpdate(new CeremonyMessage());
 | 
			
		||||
            this.getParent().getParent().exit();
 | 
			
		||||
        } else {
 | 
			
		||||
            // todo: next player
 | 
			
		||||
            broadcastUpdate(new ActivePlayer(null));
 | 
			
		||||
            parent.gotoState(new Animation(parent, logic));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
public class TurnStateMachine extends ServerStateMachine {
 | 
			
		||||
    public TurnStateMachine(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PowerCard initialState() {
 | 
			
		||||
        return new PowerCard(this, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
package pp.mdga.server;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.RequestDice;
 | 
			
		||||
import pp.mdga.message.client.RequestMove;
 | 
			
		||||
import pp.mdga.message.server.StartPiece;
 | 
			
		||||
 | 
			
		||||
public class WaitingPiece extends ServerState {
 | 
			
		||||
    public WaitingPiece(ServerState parent, ServerGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void receivedRequestMove(RequestMove msg, int from) {
 | 
			
		||||
//        if (verifyPiece(p)) {
 | 
			
		||||
//            logic.send(new Player(1), new Animation());
 | 
			
		||||
//            // todo: goto state
 | 
			
		||||
//        } else {
 | 
			
		||||
//            logic.send(new Player(1), new StartPiece());
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,171 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.message.client.ClientMessage;
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
 | 
			
		||||
public class ClientGameLogic implements ServerInterpreter {
 | 
			
		||||
    static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
 | 
			
		||||
 | 
			
		||||
    private Game game;
 | 
			
		||||
    private final ClientSender clientSender;
 | 
			
		||||
    private ClientState state;
 | 
			
		||||
 | 
			
		||||
    public ClientGameLogic(Game game, ClientSender clientSender) {
 | 
			
		||||
        this.game = game;
 | 
			
		||||
        this.clientSender = clientSender;
 | 
			
		||||
        state = new ClientAutomaton(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void send(ClientMessage msg){
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
 | 
			
		||||
        clientSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ClientSender getClientSender(){
 | 
			
		||||
        return clientSender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Game getGame(){
 | 
			
		||||
        return game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ClientState getState(){
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ActivePlayer msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(AnyPiece msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(Briefing msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(Dice msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DiceAgain msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DiceNow msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(EndOfTurn msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyAccept msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyDeny msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerJoin msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerLeave msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(NoTurn msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PauseGame msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCard msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PossibleCard msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PossiblePiece msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RankingResponse msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RankingRollAgain msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ReconnectBriefing msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ResumeGame msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ServerStartGame msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(StartPiece msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(UpdateReady msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(UpdateTSK msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(WaitPiece msg) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
 | 
			
		||||
public abstract class ClientStateMachine extends ClientState {
 | 
			
		||||
 | 
			
		||||
    private ClientState state;
 | 
			
		||||
@@ -0,0 +1,8 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
public abstract class DialogStates extends ClientState{
 | 
			
		||||
 | 
			
		||||
    public DialogStates(ClientState parent, ClientGameLogic logic){
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
public class StartDialog extends ClientState {
 | 
			
		||||
public class StartDialog extends DialogStates {
 | 
			
		||||
    public StartDialog(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
    }
 | 
			
		||||
@@ -2,8 +2,6 @@
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.server.Observer;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The Game class represents the game state of the Ludo game.
 | 
			
		||||
 * It contains all the information needed to play the game.
 | 
			
		||||
@@ -12,16 +10,16 @@
 | 
			
		||||
public class Game {
 | 
			
		||||
    private int diceModifier = 1;
 | 
			
		||||
    private int diceEyes;
 | 
			
		||||
    private Map<Color, Player> players = new HashMap<Color, Player>();
 | 
			
		||||
    private Map<Color, Player> players = new EnumMap<>(Color.class);
 | 
			
		||||
    private Statistic gameStatistics;
 | 
			
		||||
    private ArrayList<BonusCard> drawPile;
 | 
			
		||||
    private ArrayList<BonusCard> discardPile = new ArrayList<>();
 | 
			
		||||
    private List<BonusCard> drawPile;
 | 
			
		||||
    private List<BonusCard> discardPile = new ArrayList<>();
 | 
			
		||||
    private Board board;
 | 
			
		||||
    private Color activeColor;
 | 
			
		||||
    private LinkedList<Color> order;
 | 
			
		||||
    private Map<Color, Integer> playerConnectionID;
 | 
			
		||||
    private List<Color> order;
 | 
			
		||||
    private final ArrayList<Player> playerList = new ArrayList<>(4);
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Observer> observers = new ArrayList<>();
 | 
			
		||||
    private final ArrayList<Observer> observers = new ArrayList<>();
 | 
			
		||||
    private Player startPlayer;
 | 
			
		||||
    private Boolean gameHasStarted = false;
 | 
			
		||||
    private Boolean playerHasDisconnected = false;
 | 
			
		||||
@@ -127,7 +125,7 @@ public void setGameStatistics(Statistic gameStatistics) {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the draw pile
 | 
			
		||||
     */
 | 
			
		||||
    public ArrayList<BonusCard> getDrawPile() {
 | 
			
		||||
    public List<BonusCard> getDrawPile() {
 | 
			
		||||
        return drawPile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -136,7 +134,7 @@ public ArrayList<BonusCard> getDrawPile() {
 | 
			
		||||
     *
 | 
			
		||||
     * @param drawPile the new draw pile
 | 
			
		||||
     */
 | 
			
		||||
    public void setDrawPile(ArrayList<BonusCard> drawPile) {
 | 
			
		||||
    public void setDrawPile(List<BonusCard> drawPile) {
 | 
			
		||||
        this.drawPile = drawPile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -145,7 +143,7 @@ public void setDrawPile(ArrayList<BonusCard> drawPile) {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the discard pile
 | 
			
		||||
     */
 | 
			
		||||
    public ArrayList<BonusCard> getDiscardPile() {
 | 
			
		||||
    public List<BonusCard> getDiscardPile() {
 | 
			
		||||
        return discardPile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -154,7 +152,7 @@ public ArrayList<BonusCard> getDiscardPile() {
 | 
			
		||||
     *
 | 
			
		||||
     * @param discardPile the new discard pile
 | 
			
		||||
     */
 | 
			
		||||
    public void setDiscardPile(ArrayList<BonusCard> discardPile) {
 | 
			
		||||
    public void setDiscardPile(List<BonusCard> discardPile) {
 | 
			
		||||
        this.discardPile = discardPile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -199,7 +197,7 @@ public void setActiveColor(Color activeColor) {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the order of the players
 | 
			
		||||
     */
 | 
			
		||||
    public LinkedList<Color> getOrder() {
 | 
			
		||||
    public List<Color> getOrder() {
 | 
			
		||||
        return order;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -208,48 +206,10 @@ public LinkedList<Color> getOrder() {
 | 
			
		||||
     *
 | 
			
		||||
     * @param order the new order of the players
 | 
			
		||||
     */
 | 
			
		||||
    public void setOrder(LinkedList<Color> order) {
 | 
			
		||||
    public void setOrder(List<Color> order) {
 | 
			
		||||
        this.order = order;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns the player connection ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the player connection ID
 | 
			
		||||
     */
 | 
			
		||||
    public Map<Color, Integer> getPlayerConnectionID() {
 | 
			
		||||
        return playerConnectionID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method sets the player connection ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @param playerConnectionID the new player connection ID
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerConnectionID(Map<Color, Integer> playerConnectionID) {
 | 
			
		||||
        this.playerConnectionID = playerConnectionID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method sets the player connection ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @param color        the color of the player
 | 
			
		||||
     * @param connectionID the new connection ID
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerConnectionID(Color color, int connectionID) {
 | 
			
		||||
        playerConnectionID.put(color, connectionID);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns the player connection ID.
 | 
			
		||||
     *
 | 
			
		||||
     * @param color the color of the player
 | 
			
		||||
     * @return the player connection ID
 | 
			
		||||
     */
 | 
			
		||||
    public int getPlayerConnectionID(Color color) {
 | 
			
		||||
        return playerConnectionID.get(color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method adds a player to the game.
 | 
			
		||||
     *
 | 
			
		||||
@@ -321,7 +281,7 @@ public Boolean playerHasDisconnected() {
 | 
			
		||||
     */
 | 
			
		||||
    public void setGameIsInterrupted(Boolean gameIsInterrupted) {
 | 
			
		||||
        this.gameIsInterrupted = gameIsInterrupted;
 | 
			
		||||
        if (!gameIsInterrupted) notifyObservers();
 | 
			
		||||
        if (Boolean.FALSE.equals(gameIsInterrupted)) notifyObservers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -349,7 +309,7 @@ public Boolean getMovablePieces() {
 | 
			
		||||
     */
 | 
			
		||||
    public void setMovablePieces(Boolean movablePieces) {
 | 
			
		||||
        this.movablePieces = movablePieces;
 | 
			
		||||
        if (!movablePieces) notifyObservers();
 | 
			
		||||
        if (Boolean.FALSE.equals(movablePieces)) notifyObservers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -359,7 +319,7 @@ public void setMovablePieces(Boolean movablePieces) {
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerHasDisconnected(Boolean playerHasDisconnected) {
 | 
			
		||||
        this.playerHasDisconnected = playerHasDisconnected;
 | 
			
		||||
        if (playerHasDisconnected) notifyObservers();
 | 
			
		||||
        if (Boolean.TRUE.equals(playerHasDisconnected)) notifyObservers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -378,7 +338,7 @@ public Boolean allRanked() {
 | 
			
		||||
     */
 | 
			
		||||
    public void setAllRanked(Boolean allRanked) {
 | 
			
		||||
        this.allRanked = allRanked;
 | 
			
		||||
        if (allRanked) notifyObservers();
 | 
			
		||||
        if (Boolean.TRUE.equals(allRanked)) notifyObservers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -402,7 +362,7 @@ public void setStartPlayer(Player startPlayer) {
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns the all ready state.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the all ready state
 | 
			
		||||
     * @return the already state
 | 
			
		||||
     */
 | 
			
		||||
    public Boolean allReady() {
 | 
			
		||||
        return allReady;
 | 
			
		||||
@@ -415,7 +375,7 @@ public Boolean allReady() {
 | 
			
		||||
     */
 | 
			
		||||
    public void setAllReady(Boolean allReady) {
 | 
			
		||||
        this.allReady = allReady;
 | 
			
		||||
        if (allReady) notifyObservers();
 | 
			
		||||
        if (Boolean.TRUE.equals(allReady)) notifyObservers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -439,4 +399,25 @@ public Piece getPieceThroughIdentifier(String identifier) {
 | 
			
		||||
        int index = Integer.parseInt(parts[1]);
 | 
			
		||||
        return board.getPlayerData().get(color).getPieces()[index];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ArrayList<Player> getPlayerList() {
 | 
			
		||||
        return playerList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addPlayerToList(Player player) {
 | 
			
		||||
        playerList.add(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removePlayerFromList(Player player) {
 | 
			
		||||
        playerList.remove(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Player getPlayerFromList(String name) {
 | 
			
		||||
        for (Player player : playerList) {
 | 
			
		||||
            if (player.getName().equals(name)) {
 | 
			
		||||
                return player;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user