Merge branch 'development' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-01 into development
This commit is contained in:
1887
Projekte/mdga/client/hs_err_pid24033.log
Normal file
1887
Projekte/mdga/client/hs_err_pid24033.log
Normal file
File diff suppressed because one or more lines are too long
@@ -1,15 +1,19 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.system.JmeContext;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import pp.mdga.client.acoustic.AcousticHandler;
|
||||
import pp.mdga.client.animation.AnimationHandler;
|
||||
import com.jme3.system.AppSettings;
|
||||
import pp.mdga.client.dialog.JoinDialog;
|
||||
import pp.mdga.client.view.*;
|
||||
import pp.mdga.message.server.ServerInterpreter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* Main application class for the MdgaApp game.
|
||||
@@ -17,6 +21,8 @@
|
||||
*/
|
||||
public class MdgaApp extends SimpleApplication {
|
||||
|
||||
private static Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
|
||||
|
||||
/** Handles animations in the application. */
|
||||
private AnimationHandler animationHandler;
|
||||
|
||||
@@ -39,7 +45,7 @@ public class MdgaApp extends SimpleApplication {
|
||||
private MdgaState state = null;
|
||||
|
||||
/** Scale for rendering images. */
|
||||
private static final float IMAGE_SCALE = 1.5f;
|
||||
private float imageScale = prefs.getInt("scale", 1);
|
||||
|
||||
/** The main menu view. */
|
||||
private MdgaView mainView;
|
||||
@@ -74,9 +80,9 @@ private MdgaApp() {
|
||||
public static void main(String[] args) {
|
||||
AppSettings settings = new AppSettings(true);
|
||||
settings.setSamples(128);
|
||||
settings.setWidth(prefs.getInt("width", 1280));
|
||||
settings.setHeight(prefs.getInt("height", 720));
|
||||
settings.setCenterWindow(true);
|
||||
settings.setWidth((int) (1920*0.9f));
|
||||
settings.setHeight((int) (1080*0.9f));
|
||||
settings.setVSync(false);
|
||||
|
||||
MdgaApp app = new MdgaApp();
|
||||
@@ -190,7 +196,7 @@ public MdgaState getState() {
|
||||
* @return the image scale as a float
|
||||
*/
|
||||
public float getImageScale() {
|
||||
return IMAGE_SCALE;
|
||||
return imageScale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,8 +255,34 @@ public ExecutorService getExecutor() {
|
||||
return this.executor;
|
||||
}
|
||||
|
||||
public ServerConnection getNetworkSupport() {
|
||||
public ServerConnection getNetworkSupport(){
|
||||
return networkConnection;
|
||||
}
|
||||
|
||||
public void updateResolution(int width, int height, float imageFactor) {
|
||||
prefs.putInt("width", width);
|
||||
prefs.putInt("height", height);
|
||||
prefs.putFloat("scale", imageFactor);
|
||||
|
||||
try {
|
||||
restartApp();
|
||||
} catch (Exception e) {
|
||||
//nothing
|
||||
}
|
||||
}
|
||||
|
||||
public static void restartApp() throws IOException {
|
||||
String javaBin = System.getProperty("java.home") + "/bin/java";
|
||||
String classPath = System.getProperty("java.class.path");
|
||||
String className = System.getProperty("sun.java.command");
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(
|
||||
javaBin, "-cp", classPath, className
|
||||
);
|
||||
|
||||
builder.start();
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,4 +158,8 @@ protected void calculateRelative() {
|
||||
heightStep = verticalStep / 2;
|
||||
widthStep = horizontalStep / 2;
|
||||
}
|
||||
|
||||
public Vector2f getPos() {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,20 +30,9 @@ public SettingsButton(MdgaApp app, Node node, Runnable action) {
|
||||
|
||||
// Enable adjustment for positioning
|
||||
adjust = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the settings button by attaching it to the scene graph.
|
||||
*/
|
||||
@Override
|
||||
public void show() {
|
||||
release();
|
||||
|
||||
calculateRelative();
|
||||
setRelative();
|
||||
setImageRelative(pictureNormal);
|
||||
|
||||
node.attachChild(instance);
|
||||
pictureNormal.setImage(app.getAssetManager(), "Images/Settings_Button_normal.png", true);
|
||||
pictureHover.setImage(app.getAssetManager(), "Images/Settings_Button_hover.png", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,12 +40,6 @@ public void show() {
|
||||
*/
|
||||
@Override
|
||||
public void onHover() {
|
||||
icon = new IconComponent("Images/Settings_Button_hover.png");
|
||||
icon.setIconScale(0.02f * app.getImageScale());
|
||||
icon.setHAlignment(HAlignment.Center);
|
||||
icon.setVAlignment(VAlignment.Center);
|
||||
|
||||
instance.setIcon(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,12 +47,6 @@ public void onHover() {
|
||||
*/
|
||||
@Override
|
||||
public void onUnHover() {
|
||||
icon = new IconComponent("Images/Settings_Button_normal.png");
|
||||
icon.setIconScale(0.02f * app.getImageScale());
|
||||
icon.setHAlignment(HAlignment.Center);
|
||||
icon.setVAlignment(VAlignment.Center);
|
||||
|
||||
instance.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,21 @@
|
||||
import com.jme3.math.Vector2f;
|
||||
import com.jme3.scene.Node;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.button.ButtonLeft;
|
||||
import pp.mdga.client.button.ButtonRight;
|
||||
import pp.mdga.client.button.MenuButton;
|
||||
import pp.mdga.client.view.MdgaView;
|
||||
|
||||
public class VideoSettingsDialog extends Dialog {
|
||||
private MenuButton backButton;
|
||||
|
||||
private ButtonLeft hdButton9;
|
||||
private ButtonLeft fullHdButton9;
|
||||
private ButtonLeft wqhdButton9;
|
||||
private ButtonRight hdButton10;
|
||||
private ButtonRight fullHdButton10;
|
||||
private ButtonRight wqhdButton10;
|
||||
|
||||
private final MdgaView view;
|
||||
|
||||
private boolean active = false;
|
||||
@@ -20,8 +29,30 @@ public VideoSettingsDialog(MdgaApp app, Node node, MdgaView view) {
|
||||
|
||||
backButton = new MenuButton(app, node, view::leaveVideoSettings, "Zurück");
|
||||
|
||||
// MenuButton für verschiedene Auflösungen erstellen
|
||||
hdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(1280, 720, 1.0f), "hd 16:9", 10);
|
||||
fullHdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(1920, 1080, 2.25f), "full hd 16:9", 10);
|
||||
wqhdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(2560, 1440, 4.0f), "wqhd 16:9", 10);
|
||||
|
||||
|
||||
hdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1280, 800, 1.0f), "hd 16:10", 10);
|
||||
fullHdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1920, 1200, 2.25f), "full hd 16:10", 10);
|
||||
wqhdButton10 = new ButtonRight(app, node, () -> app.updateResolution(2560, 1600, 4.0f), "wqhd 16:10", 10);
|
||||
|
||||
float offset = 2.8f;
|
||||
|
||||
hdButton9.setPos(new Vector2f(hdButton9.getPos().x, MenuButton.VERTICAL - offset));
|
||||
hdButton10.setPos(new Vector2f(hdButton10.getPos().x, MenuButton.VERTICAL - offset));
|
||||
offset += 1.5f;
|
||||
|
||||
fullHdButton9.setPos(new Vector2f(fullHdButton9.getPos().x, MenuButton.VERTICAL - offset));
|
||||
fullHdButton10.setPos(new Vector2f(fullHdButton10.getPos().x, MenuButton.VERTICAL - offset));
|
||||
offset += 1.5f;
|
||||
|
||||
wqhdButton9.setPos(new Vector2f(wqhdButton9.getPos().x, MenuButton.VERTICAL - offset));
|
||||
wqhdButton10.setPos(new Vector2f(wqhdButton10.getPos().x, MenuButton.VERTICAL - offset));
|
||||
offset += 1.5f;
|
||||
|
||||
backButton.setPos(new Vector2f(0, 1.8f));
|
||||
}
|
||||
|
||||
@@ -29,6 +60,14 @@ public VideoSettingsDialog(MdgaApp app, Node node, MdgaView view) {
|
||||
protected void onShow() {
|
||||
active = true;
|
||||
|
||||
hdButton9.show();
|
||||
fullHdButton9.show();
|
||||
wqhdButton9.show();
|
||||
|
||||
hdButton10.show();
|
||||
fullHdButton10.show();
|
||||
wqhdButton10.show();
|
||||
|
||||
backButton.show();
|
||||
}
|
||||
|
||||
@@ -36,6 +75,14 @@ protected void onShow() {
|
||||
protected void onHide() {
|
||||
active = false;
|
||||
|
||||
hdButton9.hide();
|
||||
fullHdButton9.hide();
|
||||
wqhdButton9.hide();
|
||||
|
||||
hdButton10.hide();
|
||||
fullHdButton10.hide();
|
||||
wqhdButton10.hide();
|
||||
|
||||
backButton.hide();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import com.jme3.network.*;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
import com.jme3.network.serializing.serializers.EnumSerializer;
|
||||
import pp.mdga.game.*;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.*;
|
||||
@@ -12,7 +13,6 @@
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -130,6 +130,7 @@ private void initializeSerializables() {
|
||||
Serializer.registerClass(ReconnectBriefingMessage.class);
|
||||
Serializer.registerClass(ResumeGameMessage.class);
|
||||
Serializer.registerClass(ServerStartGameMessage.class);
|
||||
Serializer.registerClass(ShutdownMessage.class);
|
||||
Serializer.registerClass(StartPieceMessage.class);
|
||||
Serializer.registerClass(UpdateReadyMessage.class);
|
||||
Serializer.registerClass(UpdateTSKMessage.class);
|
||||
@@ -143,6 +144,8 @@ private void initializeSerializables() {
|
||||
Serializer.registerClass(StartNode.class);
|
||||
Serializer.registerClass(PlayerData.class);
|
||||
Serializer.registerClass(HomeNode.class);
|
||||
Serializer.registerClass(PieceState.class, new EnumSerializer());
|
||||
Serializer.registerClass(ShieldState.class, new EnumSerializer());
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
@@ -199,6 +202,9 @@ private void messageReceived(HostedConnection source, ClientMessage message) {
|
||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||
System.out.println("new connection " + hostedConnection); //NON-NLS
|
||||
LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS
|
||||
if (this.myServer.getConnections().size() == 1) {
|
||||
this.logic.getGame().setHost(hostedConnection.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,8 +32,6 @@ public class GameView extends MdgaView {
|
||||
private CameraHandler camera;
|
||||
private GuiHandler guiHandler;
|
||||
|
||||
private ButtonRight cheatButton; //TODO
|
||||
|
||||
private ButtonLeft leaveButton;
|
||||
private ButtonRight confirmButton;
|
||||
|
||||
@@ -44,7 +42,6 @@ public class GameView extends MdgaView {
|
||||
public GameView(MdgaApp app) {
|
||||
super(app);
|
||||
|
||||
cheatButton = new ButtonRight(app, overlayNode, () -> app.getModelSynchronize().enter(MdgaState.CEREMONY), "CHEAT", 1);
|
||||
leaveButton = new ButtonLeft(app, overlayNode, () -> app.getModelSynchronize().leave(), "Spiel verlassen", 1);
|
||||
|
||||
confirmButton = new ButtonRight(app, guiNode, () -> app.getModelSynchronize().confirm(), "Bestätigen", 1);
|
||||
@@ -90,7 +87,6 @@ public void onUpdate(float tpf) {
|
||||
protected void onEnterOverlay(Overlay overlay) {
|
||||
if(overlay == Overlay.SETTINGS) {
|
||||
leaveButton.show();
|
||||
cheatButton.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +94,6 @@ protected void onEnterOverlay(Overlay overlay) {
|
||||
protected void onLeaveOverlay(Overlay overlay) {
|
||||
if(overlay == Overlay.SETTINGS) {
|
||||
leaveButton.hide();
|
||||
cheatButton.hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.DialogsState;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.PlayerData;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.LobbyPlayerJoinedMessage;
|
||||
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
||||
@@ -13,6 +15,8 @@
|
||||
import pp.mdga.message.server.UpdateTSKMessage;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LobbyState extends DialogStates {
|
||||
|
||||
private final DialogsState parent;
|
||||
@@ -73,6 +77,13 @@ public void selectStart(){
|
||||
public void received(ServerStartGameMessage msg){
|
||||
logic.getGame().setBoard(msg.getBoard());
|
||||
logic.addNotification(new GameNotification(logic.getGame().getPlayers().get(parent.getOwnPlayerId()).getColor()));
|
||||
for(Map.Entry<Color, PlayerData> entry : msg.getBoard().getPlayerData().entrySet()){
|
||||
List<UUID> pieceIds = new ArrayList<>();
|
||||
for(Piece piece : entry.getValue().getPieces()){
|
||||
pieceIds.add(piece.getUuid());
|
||||
}
|
||||
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceIds, logic.getGame().getPlayerByColor(entry.getKey()).getName()));
|
||||
}
|
||||
parent.startGame();
|
||||
}
|
||||
|
||||
@@ -81,6 +92,9 @@ public void received(LobbyPlayerJoinedMessage msg){
|
||||
if(msg.getPlayer().getName().equals(parent.getOwnPlayerName())){
|
||||
parent.setOwnPlayerId(msg.getId());
|
||||
}
|
||||
if (msg.isHost() && msg.getId() == parent.getOwnPlayerId()){
|
||||
logic.setHost(true);
|
||||
}
|
||||
logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,7 @@
|
||||
*/
|
||||
@Serializable
|
||||
public class Board {
|
||||
private Map<Color, PlayerData> playerData;
|
||||
private Map<Color, PlayerData> playerData = new HashMap<>();
|
||||
private final Node[] infield;
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,17 @@ public Board() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to add the given color and playerData parameters to the playerData attribute of
|
||||
* Board class.
|
||||
*
|
||||
* @param color as the color of the player as a Color enumeration.
|
||||
* @param playerData as the playerData of the player as a PlayerData object.
|
||||
*/
|
||||
public void addPlayerData(Color color, PlayerData playerData) {
|
||||
this.playerData.put(color, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the playerData
|
||||
*
|
||||
|
||||
@@ -43,11 +43,14 @@ public class Die {
|
||||
*/
|
||||
private int lastNumberOfDice;
|
||||
|
||||
private final boolean lock;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new Die object with a random seed.
|
||||
*/
|
||||
public Die() {
|
||||
this.random = RandomGeneratorFactory.of("Random").create();
|
||||
this.lock = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +60,18 @@ public Die() {
|
||||
*/
|
||||
public Die(long seed) {
|
||||
this.random = RandomGeneratorFactory.of("Random").create(seed);
|
||||
this.lock = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param roll as the roll which should be returned everytime the shuffle method will be called as an Integer.
|
||||
*/
|
||||
public Die(int roll) {
|
||||
this.random = RandomGeneratorFactory.of("Random").create();
|
||||
this.lastNumberOfDice = roll;
|
||||
this.lock = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +80,10 @@ public Die(long seed) {
|
||||
* @return lastNumberOfDice as an Integer.
|
||||
*/
|
||||
public int shuffle() {
|
||||
if (this.lock) {
|
||||
return this.lastNumberOfDice;
|
||||
}
|
||||
|
||||
this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1;
|
||||
|
||||
return this.lastNumberOfDice;
|
||||
|
||||
@@ -42,6 +42,9 @@ public class Game {
|
||||
// The die used in the game.
|
||||
private Die die;
|
||||
|
||||
// The host of this game
|
||||
private int host;
|
||||
|
||||
// The color of the active player.
|
||||
private Color activeColor;
|
||||
|
||||
@@ -232,6 +235,15 @@ public Color getActiveColor() {
|
||||
return activeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return host attribute of Game class.
|
||||
*
|
||||
* @return host as an Integer.
|
||||
*/
|
||||
public int getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the dice modifier.
|
||||
*
|
||||
@@ -304,6 +316,24 @@ public void setActiveColor(Color activeColor) {
|
||||
this.activeColor = activeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to set die attribute of Game class to the given die parameter.
|
||||
*
|
||||
* @param die as the new value of die as a Die object.
|
||||
*/
|
||||
public void setDie(Die die) {
|
||||
this.die = die;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to set host attribute of Game class to the given host parameter.
|
||||
*
|
||||
* @param host as the new value of host as an Integer.
|
||||
*/
|
||||
public void setHost(int host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the all ready state.
|
||||
*
|
||||
|
||||
@@ -43,6 +43,8 @@ public Piece(Color color, PieceState state, int id) {
|
||||
|
||||
private Piece() {
|
||||
color = null;
|
||||
state = PieceState.WAITING;
|
||||
shield = ShieldState.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,5 +19,17 @@ public enum PieceState {
|
||||
/**
|
||||
* The piece is finished.
|
||||
*/
|
||||
HOMEFINISHED
|
||||
HOMEFINISHED;
|
||||
|
||||
public static PieceState getPieceStateByIndex(int index){
|
||||
if (index < 0 || index >= values().length) {
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
return values()[index];
|
||||
}
|
||||
|
||||
|
||||
public PieceState next() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class PlayerData {
|
||||
*/
|
||||
public PlayerData(Color color) {
|
||||
homeNodes = new HomeNode[4];
|
||||
pieces = new Piece[4];
|
||||
waitingArea = new Piece[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
homeNodes[i] = new HomeNode();
|
||||
|
||||
@@ -15,5 +15,16 @@ public enum ShieldState {
|
||||
/**
|
||||
* The shield is suppressed, when the piece is on a start node.
|
||||
*/
|
||||
SUPPRESSED
|
||||
SUPPRESSED;
|
||||
|
||||
public static ShieldState getShieldStateByIndex(int index){
|
||||
if (index < 0 || index >= values().length) {
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
return values()[index];
|
||||
}
|
||||
|
||||
public ShieldState next() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,23 @@ public class LobbyPlayerJoinedMessage extends ServerMessage {
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The flag is the new player is the host
|
||||
*/
|
||||
private final boolean host;
|
||||
|
||||
/**
|
||||
* Constructs a new LobbyPlayerJoin instance with the specified player name.
|
||||
*
|
||||
* @param player the player joining the lobby
|
||||
* @param id the id of the player
|
||||
* @param id the id of the player
|
||||
* @param host as the flag if the player is the host as a Boolean.
|
||||
*/
|
||||
public LobbyPlayerJoinedMessage(int id, Player player) {
|
||||
public LobbyPlayerJoinedMessage(int id, Player player, boolean host) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.id = id;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +44,7 @@ public LobbyPlayerJoinedMessage(int id, Player player) {
|
||||
private LobbyPlayerJoinedMessage() {
|
||||
player = null;
|
||||
id = 0;
|
||||
host = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +65,10 @@ public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
|
||||
@@ -207,4 +207,11 @@ public interface ServerInterpreter {
|
||||
* @param msg the SelectPiece message received.
|
||||
*/
|
||||
void received(SelectPieceMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a SelectTSK message received from the server.
|
||||
*
|
||||
* @param shutdownMessage the SelectTSK message received.
|
||||
*/
|
||||
void received(ShutdownMessage shutdownMessage);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to inform the clients that the server is shutting down.
|
||||
*/
|
||||
@Serializable
|
||||
public class ShutdownMessage extends ServerMessage {
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bundle key of the informational text to be shown at the client.
|
||||
* This key is used to retrieve the appropriate localized text for display.
|
||||
*
|
||||
* @return the bundle key of the informational text
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ public class GameState extends ServerState {
|
||||
* Create GameState states.
|
||||
*/
|
||||
private GameAutomatonState currentState;
|
||||
private final GameAutomatonState determineStartPlayerState;
|
||||
private final GameAutomatonState animationState;
|
||||
private final GameAutomatonState turnState;
|
||||
private final DetermineStartPlayerState determineStartPlayerState;
|
||||
private final AnimationState animationState;
|
||||
private final TurnState turnState;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -122,27 +122,27 @@ public GameAutomatonState getCurrentState() {
|
||||
/**
|
||||
* This method will be used to return determineStartPlayerState attribute of GameState class.
|
||||
*
|
||||
* @return determineStartPlayerState as a GameAutomatonState object.
|
||||
* @return determineStartPlayerState as a DetermineStartPlayerState object.
|
||||
*/
|
||||
public GameAutomatonState getDetermineStartPlayerState() {
|
||||
public DetermineStartPlayerState getDetermineStartPlayerState() {
|
||||
return this.determineStartPlayerState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return animationState attribute of GameState class.
|
||||
*
|
||||
* @return animationState as a GameAutomatonState object.
|
||||
* @return animationState as a AnimationState object.
|
||||
*/
|
||||
public GameAutomatonState getAnimationState() {
|
||||
public AnimationState getAnimationState() {
|
||||
return this.animationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return turnState attribute of GameState class.
|
||||
*
|
||||
* @return turnState as a GameAutomatonState object.
|
||||
* @return turnState as a TurnState object.
|
||||
*/
|
||||
public GameAutomatonState getTurnState() {
|
||||
public TurnState getTurnState() {
|
||||
return this.turnState;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.PlayerData;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
@@ -43,6 +44,15 @@ public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited LobbyState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to initialize the game and all necessary objects.
|
||||
*/
|
||||
public void initializeGame() {
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a JoinedLobbyMessage message.
|
||||
* It will also get the client id of the player who send this message
|
||||
@@ -55,8 +65,8 @@ public void received(JoinedLobbyMessage msg, int from) {
|
||||
Player player = new Player(msg.getName());
|
||||
player.setColor(Color.getColorByIndex(this.logic.getGame().getPlayers().size()));
|
||||
this.logic.getGame().addPlayer(from, player);
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(entry.getKey(), entry.getValue()));
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(entry.getKey(), entry.getValue(), entry.getKey() == this.logic.getGame().getHost()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +113,14 @@ public void received(LobbyReadyMessage msg, int from) {
|
||||
this.logic.getGame().getPlayerById(from).setReady(true);
|
||||
this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, true));
|
||||
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
|
||||
if (!entry.getValue().isActive()) {
|
||||
if (!entry.getValue().isReady()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.logic.getGame().setAllReady(true);
|
||||
if (this.logic.getGame().allReady()) {
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
}
|
||||
}
|
||||
@@ -137,6 +148,9 @@ public void received(LobbyNotReadyMessage msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void received(LeaveGameMessage msg, int from) {
|
||||
if (from == this.logic.getGame().getHost()) {
|
||||
this.logic.getServerSender().broadcast(new ShutdownMessage());
|
||||
}
|
||||
this.logic.getGame().removePlayer(from);
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerLeaveMessage(from));
|
||||
this.logic.getServerSender().disconnectClient(from);
|
||||
@@ -152,6 +166,7 @@ public void received(LeaveGameMessage msg, int from) {
|
||||
@Override
|
||||
public void received(StartGameMessage msg, int from) {
|
||||
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
|
||||
this.initializeGame();
|
||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||
this.logic.setCurrentState(this.logic.getGameState());
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.ActivePlayerMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.message.server.EndOfTurnMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -21,7 +24,8 @@ public class DetermineStartPlayerState extends GameAutomatonState {
|
||||
/**
|
||||
* Create DetermineStartPlayerState attributes.
|
||||
*/
|
||||
private Map<Player, Integer> diceResults = new HashMap<>();
|
||||
private Map<Integer, Integer> diceResults = new HashMap<>();
|
||||
private List<Integer> playersHaveToRoll = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -36,6 +40,9 @@ public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic)
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered DetermineStartPlayerState state.");
|
||||
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||
this.playersHaveToRoll.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,23 +60,27 @@ public void exit() {
|
||||
@Override
|
||||
public void received(RequestDieMessage msg, int from) {
|
||||
int roll = this.logic.getGame().getDie().shuffle();
|
||||
this.diceResults.put(this.logic.getGame().getPlayerById(from), roll);
|
||||
this.diceResults.put(from, roll);
|
||||
int maximumRoll = 0;
|
||||
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
|
||||
Map<Integer, Long> frequencyMap = diceResults.values().stream()
|
||||
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||
Map.Entry<Integer, Long> result = frequencyMap.entrySet().stream()
|
||||
.max(Map.Entry.comparingByKey())
|
||||
.orElseThrow(() -> new IllegalStateException("Die Map ist leer"));
|
||||
}
|
||||
this.logic.getServerSender().send(from, new DieMessage(roll));
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> entry: this.diceResults.entrySet()) {
|
||||
if (maximumRoll == 0) {
|
||||
maximumRoll = this.diceResults.get(entry.getKey());
|
||||
} else if (maximumRoll < entry.getValue()) {
|
||||
maximumRoll = entry.getValue();
|
||||
} else {
|
||||
this.playersHaveToRoll.remove(entry.getKey());
|
||||
this.logic.getServerSender().send(entry.getKey(), new EndOfTurnMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return diceResults attribute of DetermineStartPlayerState class.
|
||||
*
|
||||
* @return diceResults as a Map combing Player objects and Integers.
|
||||
*/
|
||||
public Map<Player, Integer> getDiceResults() {
|
||||
return this.diceResults;
|
||||
if (this.playersHaveToRoll.size() == 1) {
|
||||
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor()));
|
||||
} else {
|
||||
for (Integer id: this.playersHaveToRoll) {
|
||||
this.logic.getServerSender().send(id, new DieMessage(roll));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user