Merge branch 'development' into dev/client_koppe2

This commit is contained in:
Felix Koppe
2024-12-04 13:43:33 +01:00
75 changed files with 2140 additions and 559 deletions

View File

@@ -1,6 +1,5 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true"> <configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true">
<option name="ALTERNATIVE_JRE_PATH" value="temurin-20" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp" /> <option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp" />
<module name="Projekte.mdga.client.main" /> <module name="Projekte.mdga.client.main" />

View File

@@ -30,14 +30,14 @@ public enum Asset {
tank, tank,
world(1.2f), world(1.2f),
shieldRing("Models/shieldRing/shieldRing.j3o", null), shieldRing("Models/shieldRing/shieldRing.j3o", null),
treeSmall, treeSmall(1.2f),
treeBig, treeBig(1.2f),
turboCard, turboCard,
turboSymbol("Models/turboCard/turboSymbol.j3o", "Models/turboCard/turboCard_diff.j3o"), turboSymbol("Models/turboCard/turboSymbol.j3o", "Models/turboCard/turboCard_diff.png"),
swapCard, swapCard,
swapSymbol("Models/swapCard/swapSymbol.j3o", "Models/swapCard/swapCard_diff.j3o"), swapSymbol("Models/swapCard/swapSymbol.j3o", "Models/swapCard/swapCard_diff.png"),
shieldCard, shieldCard,
shieldSymbol("Models/shieldCard/shieldSymbol.j3o", "Models/shieldCard/shieldCard_diff.j3o"), shieldSymbol("Models/shieldCard/shieldSymbol.j3o", "Models/shieldCard/shieldCard_diff.png"),
dice dice
; ;

View File

@@ -17,6 +17,7 @@
import pp.mdga.client.board.OutlineControl; import pp.mdga.client.board.OutlineControl;
import pp.mdga.client.board.PieceControl; import pp.mdga.client.board.PieceControl;
import pp.mdga.client.gui.CardControl; import pp.mdga.client.gui.CardControl;
import pp.mdga.client.gui.DiceControl;
import pp.mdga.client.view.GameView; import pp.mdga.client.view.GameView;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Color; import pp.mdga.game.Color;
@@ -26,6 +27,7 @@
import pp.mdga.notification.SelectableCardsNotification; import pp.mdga.notification.SelectableCardsNotification;
import java.util.List; import java.util.List;
import java.util.UUID;
public class InputSynchronizer { public class InputSynchronizer {
@@ -93,10 +95,14 @@ public void onAction(String name, boolean isPressed, float tpf) {
} }
if(name.equals("Click") && isPressed) { if(name.equals("Click") && isPressed) {
if (app.getView() instanceof GameView gameView) { if (app.getView() instanceof GameView gameView) {
DiceControl diceSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), DiceControl.class);
CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class); CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class);
OutlineControl boardSelect = checkHover(app.getCamera(), app.getRootNode(), OutlineControl.class); OutlineControl boardSelect = checkHover(app.getCamera(), app.getRootNode(), OutlineControl.class);
if(cardLayerSelect != null) { if(diceSelect != null) {
app.getModelSynchronize().rolledDice();
}
else if(cardLayerSelect != null) {
//cardSelect //cardSelect
if(cardLayerSelect.isSelectable()) gameView.getGuiHandler().selectCard(cardLayerSelect); if(cardLayerSelect.isSelectable()) gameView.getGuiHandler().selectCard(cardLayerSelect);
} }
@@ -118,8 +124,21 @@ else if(boardSelect != null) {
} }
if(name.equals("Test") &&isPressed){ if(name.equals("Test") &&isPressed){
if(app.getView() instanceof GameView gameView){ if(app.getView() instanceof GameView gameView){
// app.getNotificationSynchronizer().addTestNotification(new FinishNotification(Color.NAVY)); // gameView.getGuiHandler().rollRankingResult(Color.AIRFORCE, 1);
// app.getNotificationSynchronizer().addTestNotification(new MovePieceNotification()); // gameView.getGuiHandler().rollRankingResult(Color.ARMY, 2);
// gameView.getGuiHandler().rollRankingResult(Color.NAVY, 3);
// gameView.getGuiHandler().rollRankingResult(Color.CYBER, 4);
// gameView.getGuiHandler().showDice();
// UUID p1 = UUID.randomUUID();
// gameView.getBoardHandler().addPlayer(Color.AIRFORCE,List.of(p1,UUID.randomUUID(),UUID.randomUUID(),UUID.randomUUID()));
// gameView.getBoardHandler().movePieceStartAnim(p1,0);
gameView.getGuiHandler().drawCard(Color.ARMY);
gameView.getGuiHandler().addCardOwn(BonusCard.SHIELD);
gameView.getGuiHandler().playCardOwn(BonusCard.SHIELD);
} }
} }
} }

View File

@@ -2,12 +2,18 @@
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.simsilica.lemur.GuiGlobals; import com.simsilica.lemur.GuiGlobals;
import com.sun.tools.javac.Main;
import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.acoustic.AcousticHandler;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import pp.mdga.client.dialog.JoinDialog; import pp.mdga.client.dialog.JoinDialog;
import pp.mdga.client.view.*; import pp.mdga.client.view.*;
import javax.imageio.ImageIO;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
@@ -39,7 +45,7 @@ public class MdgaApp extends SimpleApplication {
private MdgaState state = null; private MdgaState state = null;
/** Scale for rendering images. */ /** Scale for rendering images. */
private float imageScale = prefs.getInt("scale", 1); private final float imageScale = prefs.getInt("scale", 1);
/** The main menu view. */ /** The main menu view. */
private MdgaView mainView; private MdgaView mainView;
@@ -60,7 +66,7 @@ public class MdgaApp extends SimpleApplication {
private ServerConnection networkConnection; private ServerConnection networkConnection;
private MdgaApp() { public MdgaApp() {
networkConnection = new NetworkSupport(this); networkConnection = new NetworkSupport(this);
this.clientGameLogic = new ClientGameLogic(networkConnection); this.clientGameLogic = new ClientGameLogic(networkConnection);
} }
@@ -76,12 +82,15 @@ public static void main(String[] args) {
settings.setSamples(128); settings.setSamples(128);
settings.setWidth(prefs.getInt("width", 1280)); settings.setWidth(prefs.getInt("width", 1280));
settings.setHeight(prefs.getInt("height", 720)); settings.setHeight(prefs.getInt("height", 720));
settings.setFullscreen(prefs.getBoolean("fullscreen", false));
settings.setCenterWindow(true); settings.setCenterWindow(true);
settings.setVSync(false); settings.setVSync(false);
settings.setTitle("MDGA");
MdgaApp app = new MdgaApp(); MdgaApp app = new MdgaApp();
app.setSettings(settings); app.setSettings(settings);
app.setShowSettings(false); app.setShowSettings(false);
app.setPauseOnLostFocus(false);
app.start(); app.start();
} }
@@ -106,7 +115,7 @@ public void simpleInitApp() {
gameView = new GameView(this); gameView = new GameView(this);
ceremonyView = new CeremonyView(this); ceremonyView = new CeremonyView(this);
enter(MdgaState.MAIN); enter(MdgaState.GAME);
} }
/** /**
@@ -244,19 +253,29 @@ public ServerConnection getNetworkSupport(){
return networkConnection; return networkConnection;
} }
public void updateResolution(int width, int height, float imageFactor) { public void updateResolution(int width, int height, float imageFactor, boolean isFullscreen) {
if(isFullscreen) {
int baseWidth = 1280;
int baseHeight = 720;
float baseAspectRatio = (float) baseWidth / baseHeight;
float newAspectRatio = (float) width / height;
float scaleFactor = Math.max((float) width / baseWidth, (float) height / baseHeight);
settings.setFullscreen(true);
prefs.putFloat("scale", scaleFactor);
prefs.putBoolean("fullscreen", true);
} else {
prefs.putInt("width", width); prefs.putInt("width", width);
prefs.putInt("height", height); prefs.putInt("height", height);
prefs.putFloat("scale", imageFactor); prefs.putFloat("scale", imageFactor);
prefs.putBoolean("fullscreen", false);
}
}
public static void restartApp() {
try { try {
restartApp();
} catch (Exception e) {
//nothing
}
}
public static void restartApp() throws IOException {
String javaBin = System.getProperty("java.home") + "/bin/java"; String javaBin = System.getProperty("java.home") + "/bin/java";
String classPath = System.getProperty("java.class.path"); String classPath = System.getProperty("java.class.path");
String className = System.getProperty("sun.java.command"); String className = System.getProperty("sun.java.command");
@@ -268,6 +287,16 @@ public static void restartApp() throws IOException {
builder.start(); builder.start();
System.exit(0); System.exit(0);
} catch (Exception e) {
throw new RuntimeException("restart failed");
}
}
public void afterGameCleanup() {
MainView main = (MainView) mainView;
main.getJoinDialog().disconnect();
main.getHostDialog().shutdownServer();
} }
} }

View File

@@ -26,6 +26,11 @@ public void addTestNotification(Notification n) {
public void update() { public void update() {
Notification n = app.getGameLogic().getNotification(); Notification n = app.getGameLogic().getNotification();
while (n != null) {
if(n instanceof InfoNotification infoNotification) {
app.getView().showInfo(infoNotification.getMessage(), infoNotification.isError());
return;
}
if(n != null) { if(n != null) {
switch (app.getState()) { switch (app.getState()) {
@@ -42,16 +47,21 @@ public void update() {
handleCeremony(n); handleCeremony(n);
break; break;
case NONE: case NONE:
throw new RuntimeException("no notification expected: " + n.toString()); throw new RuntimeException("no notification expected: " + n.getClass().getName());
} }
} }
n = app.getGameLogic().getNotification();
}
} }
private void handleMain(Notification notification) { private void handleMain(Notification notification) {
if (notification instanceof LobbyDialogNotification) { if (notification instanceof LobbyDialogNotification) {
app.enter(MdgaState.LOBBY); app.enter(MdgaState.LOBBY);
} else if (notification instanceof StartDialogNotification) {
//nothing
} else { } else {
throw new RuntimeException("notification not expected: "); throw new RuntimeException("notification not expected in main: "+ notification.getClass().getName());
} }
} }
@@ -61,6 +71,7 @@ private void handleLobby(Notification notification) {
if (notification instanceof TskSelectNotification n) { if (notification instanceof TskSelectNotification n) {
lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName()); lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName());
} else if (notification instanceof StartDialogNotification) { } else if (notification instanceof StartDialogNotification) {
app.afterGameCleanup();
app.enter(MdgaState.MAIN); app.enter(MdgaState.MAIN);
} else if (notification instanceof TskUnselectNotification n) { } else if (notification instanceof TskUnselectNotification n) {
lobbyView.setTaken(n.getColor(), false, false, null); lobbyView.setTaken(n.getColor(), false, false, null);
@@ -70,7 +81,7 @@ private void handleLobby(Notification notification) {
app.enter(MdgaState.GAME); app.enter(MdgaState.GAME);
((GameView) app.getView()).setOwnColor(n.getOwnColor()); ((GameView) app.getView()).setOwnColor(n.getOwnColor());
} else { } else {
throw new RuntimeException("notification not expected: " + notification.toString()); throw new RuntimeException("notification not expected in lobby: " + notification.getClass().getName());
} }
} }
@@ -81,7 +92,7 @@ private void handleGame(Notification notification) {
ModelSynchronizer modelSynchronizer = app.getModelSynchronize(); ModelSynchronizer modelSynchronizer = app.getModelSynchronize();
if (notification instanceof AcquireCardNotification n) { if (notification instanceof AcquireCardNotification n) {
guiHandler.addCard(n.getBonusCard()); guiHandler.addCardOwn(n.getBonusCard());
} else if (notification instanceof ActivePlayerNotification n) { } else if (notification instanceof ActivePlayerNotification n) {
gameView.getGuiHandler().setActivePlayer(n.getColor()); gameView.getGuiHandler().setActivePlayer(n.getColor());
boardHandler.showDice(n.getColor()); boardHandler.showDice(n.getColor());
@@ -136,18 +147,15 @@ private void handleGame(Notification notification) {
} else if (notification instanceof NoShieldNotification n) { } else if (notification instanceof NoShieldNotification n) {
boardHandler.unshieldPiece(n.getPieceId()); boardHandler.unshieldPiece(n.getPieceId());
} else if (notification instanceof PlayCardNotification n) { } else if (notification instanceof PlayCardNotification n) {
switch(n.getCard()){ if(n.getColor() == gameView.getOwnColor()) guiHandler.playCardOwn(n.getCard());
case SWAP -> guiHandler.swap(); else guiHandler.playCardEnemy(n.getColor(), n.getCard());
case TURBO -> guiHandler.turbo();
case SHIELD -> guiHandler.shield();
default -> throw new RuntimeException("invalid card");
}
} else if (notification instanceof PlayerInGameNotification n) { } else if (notification instanceof PlayerInGameNotification n) {
boardHandler.addPlayer(n.getColor(),n.getPiecesList()); boardHandler.addPlayer(n.getColor(),n.getPiecesList());
guiHandler.addPlayer(n.getColor(),n.getName()); guiHandler.addPlayer(n.getColor(),n.getName());
} else if (notification instanceof ResumeNotification) { } else if (notification instanceof ResumeNotification) {
//ignore //ignore
} else if (notification instanceof RollDiceNotification n) { } else if (notification instanceof RollDiceNotification n) {
gameView.getGuiHandler().hideText();
if(n.getColor() == gameView.getOwnColor()){ if(n.getColor() == gameView.getOwnColor()){
guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1); guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1);
} }
@@ -163,6 +171,7 @@ private void handleGame(Notification notification) {
} else if (notification instanceof ShieldSuppressedNotification n) { } else if (notification instanceof ShieldSuppressedNotification n) {
boardHandler.suppressShield(n.getPieceId()); boardHandler.suppressShield(n.getPieceId());
} else if (notification instanceof StartDialogNotification) { } else if (notification instanceof StartDialogNotification) {
app.afterGameCleanup();
app.enter(MdgaState.MAIN); app.enter(MdgaState.MAIN);
} else if (notification instanceof SwapPieceNotification n) { } else if (notification instanceof SwapPieceNotification n) {
// boardHandler.swapPieces(n.getFirstPiece(), n.getSecondPiece()); // boardHandler.swapPieces(n.getFirstPiece(), n.getSecondPiece());
@@ -183,15 +192,16 @@ private void handleGame(Notification notification) {
} else if (notification instanceof FinishNotification n){ } else if (notification instanceof FinishNotification n){
guiHandler.finish(n.getColorFinished()); guiHandler.finish(n.getColorFinished());
} else { } else {
throw new RuntimeException("notification not expected: " + notification.toString()); throw new RuntimeException("notification not expected in game: " + notification.getClass().getName());
} }
} }
private void handleCeremony(Notification notification) { private void handleCeremony(Notification notification) {
if (notification instanceof StartDialogNotification) { if (notification instanceof StartDialogNotification) {
app.afterGameCleanup();
app.enter(MdgaState.MAIN); app.enter(MdgaState.MAIN);
} else { } else {
throw new RuntimeException("notification not expected: " + notification.toString()); throw new RuntimeException("notification not expected in ceremony: " + notification.getClass().getName());
} }
} }
} }

View File

@@ -7,6 +7,8 @@
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor; import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.FXAAFilter;
import com.jme3.post.ssao.SSAOFilter;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.shadow.DirectionalLightShadowFilter; import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.shadow.EdgeFilteringMode; import com.jme3.shadow.EdgeFilteringMode;
@@ -37,6 +39,8 @@ public class CameraHandler {
private Color ownColor; private Color ownColor;
private boolean init; private boolean init;
private boolean initRot; private boolean initRot;
private SSAOFilter ssaoFilter;
private FXAAFilter fxaaFilter;
/** /**
* Constructor for the CameraHandler. Initializes the camera settings and lighting. * Constructor for the CameraHandler. Initializes the camera settings and lighting.
@@ -65,6 +69,9 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp) {
dlsf.setEnabled(true); dlsf.setEnabled(true);
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON); dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
dlsf.setShadowIntensity(0.7f); dlsf.setShadowIntensity(0.7f);
ssaoFilter = new SSAOFilter(6, 10f, 0.33f, 0.61f);
// ssaoFilter = new SSAOFilter();
fxaaFilter = new FXAAFilter();
sky = SkyFactory.createSky(app.getAssetManager(), "Images/sky/sky.dds", EnvMapType.EquirectMap).rotate(FastMath.HALF_PI*1,0,FastMath.HALF_PI*0.2f); sky = SkyFactory.createSky(app.getAssetManager(), "Images/sky/sky.dds", EnvMapType.EquirectMap).rotate(FastMath.HALF_PI*1,0,FastMath.HALF_PI*0.2f);
@@ -82,6 +89,8 @@ public void init(Color ownColor) {
app.getRootNode().addLight(ambient); app.getRootNode().addLight(ambient);
app.getRootNode().attachChild(sky); app.getRootNode().attachChild(sky);
fpp.addFilter(dlsf); fpp.addFilter(dlsf);
fpp.addFilter(ssaoFilter);
fpp.addFilter(fxaaFilter);
init = true; init = true;
initRot = true; initRot = true;
this.ownColor = ownColor; this.ownColor = ownColor;

View File

@@ -107,8 +107,8 @@ private static Asset getLoadedAsset(String assetName) {
case "radar" -> Asset.radar; case "radar" -> Asset.radar;
case "ship" -> Asset.ship; case "ship" -> Asset.ship;
case "tank" -> Asset.tank; case "tank" -> Asset.tank;
case "tree_small" -> Asset.treeSmall; case "treeSmall" -> Asset.treeSmall;
case "tree_big" -> Asset.treeBig; case "treeBig" -> Asset.treeBig;
default -> throw new IllegalStateException("Unexpected value: " + assetName); default -> throw new IllegalStateException("Unexpected value: " + assetName);
}; };
} }

View File

@@ -92,4 +92,16 @@ public void resetPort() {
public void connectToServer() { public void connectToServer() {
connectServer(); connectServer();
} }
public void disconnect() {
NetworkSupport network = getNetwork();
if (network != null) {
try {
network.disconnect();
} catch (Exception e) {
System.err.println("Error while disconnecting: " + e.getMessage());
}
}
}
} }

View File

@@ -14,6 +14,8 @@ public abstract class NetworkDialog extends Dialog {
private String hostname; private String hostname;
private int portNumber; private int portNumber;
private Future<Object> connectionFuture; private Future<Object> connectionFuture;
private MdgaServer serverInstance;
private Thread serverThread;
public NetworkDialog(MdgaApp app, Node node, NetworkSupport network) { public NetworkDialog(MdgaApp app, Node node, NetworkSupport network) {
super(app, node); super(app, node);
@@ -28,7 +30,6 @@ public void setPortNumber(int portNumber) {
this.portNumber = portNumber; this.portNumber = portNumber;
} }
protected Object initNetwork() { protected Object initNetwork() {
try { try {
this.network.initNetwork(this.hostname, this.portNumber); this.network.initNetwork(this.hostname, this.portNumber);
@@ -39,25 +40,49 @@ protected Object initNetwork() {
} }
protected void connectServer() { protected void connectServer() {
try { try {
connectionFuture = this.network.getApp().getExecutor().submit(this::initNetwork); connectionFuture = this.network.getApp().getExecutor().submit(this::initNetwork);
} catch (NumberFormatException var2) { } catch (NumberFormatException var2) {
throw new NumberFormatException("Port must be a number"); throw new NumberFormatException("Port must be a number");
} }
} }
protected void startServer() { protected void startServer() {
(new Thread(() -> { serverThread = new Thread(() -> {
try { try {
MdgaServer mdgaServer = new MdgaServer(portNumber); serverInstance = new MdgaServer(portNumber);
mdgaServer.run(); serverInstance.run();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
});
})).start(); serverThread.start();
}
public void shutdownServer() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.err.println("Thread was interrupted: " + e.getMessage());
}
if (serverInstance != null) {
serverInstance.shutdown();
serverInstance = null;
}
if (serverThread != null && serverThread.isAlive()) {
serverThread.interrupt();
try {
serverThread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
serverThread = null;
}
} }
public void update(float delta) { public void update(float delta) {
@@ -65,14 +90,14 @@ public void update(float delta) {
try { try {
this.connectionFuture.get(); this.connectionFuture.get();
} catch (ExecutionException ignored) { } catch (ExecutionException ignored) {
// todo: implement // TODO: implement
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
} }
public NetworkSupport getNetwork(){ public NetworkSupport getNetwork() {
return network; return network;
} }
} }

View File

@@ -177,6 +177,109 @@ public String getName() {
"CarryPro", "CarryPro",
"ProBaiter", "ProBaiter",
"GameWarden", "GameWarden",
"KartoffelKönig",
"SaufenderWolf",
"WurstGriller",
"Flitzekacke",
"BratwurstBub",
"Hoppeldoppels",
"BananenMensch",
"KlopapierGuru",
"SchnitzelKing",
"NerdNomade",
"Dönertänzer",
"GlitzerGurke",
"SchinkenShrek",
"KäseKalle",
"SchokoSchnecke",
"KeksKämpfer",
"QuarkPiraten",
"Müslimonster",
"KnuddelNase",
"FantaFighter",
"SchnapsSaurier",
"Wackelpudding",
"ZitronenZock",
"FettWurst",
"PlüschPanda",
"Zuckerschnur",
"FluffiKopf",
"DonutDöner",
"VollpfostenX",
"Schraubenschlüssel",
"Witzepumper",
"ToastTraum",
"FroschFighter",
"KrümelTiger",
"RegenWolke",
"PuddingPower",
"KoffeinKrieger",
"SpeckSchlumpf",
"SuperSuppe",
"BierBärchen",
"FischBär",
"Flauschi",
"Schokomonster",
"ChaosKäse",
"FlitzLappen",
"WurstWombat",
"KrümelMensch",
"PuddingBär",
"ZickZack",
"Schwabel",
"Fluffi",
"RülpsFrosch",
"PommesPapa",
"QuarkBär",
"KnusperKönig",
"ToastBrot",
"Ploppster",
"Schleimschwein",
"Äpfelchen",
"Knallbonbon",
"KaffeeKopf",
"WackelWurst",
"RennKeks",
"BröselBub",
"ZockerBrot",
"BierWurm",
"StinkFlummi",
"SchlumpfKing",
"PurzelBär",
"FlinkFluff",
"PloppPudel",
"Schnorchel",
"FliegenKopf",
"PixelPommes",
"SchwipsWürst",
"WutzBär",
"KnuddelKeks",
"FantaFlumm",
"ZockerKäse",
"LachHäufchen",
"GurkenGuru",
"PonySchnitzel",
"NudelNinja",
"VulkanKeks",
"WasserToast",
"MenschSalat",
"KampfKohlenhydrate",
"SockenZirkus",
"SchwimmBärchen",
"TanzenderDachgepäckträger",
"PizzamarktMensch",
"ZahnarztZocker",
"RollerCoasterTester",
"WaschmaschinenPilot",
"WitzigeZwiebel",
"Pillenschlucker",
"ZwiebelReiter",
"HüpfenderKaktus",
"KochenderAsteroid",
"ChaosKarotte",
"WolkenFurz",
"SchnitzelPartikel",
"WackelBiene",
}; };
Random random = new Random(); Random random = new Random();

View File

@@ -3,13 +3,20 @@
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaApp;
import pp.mdga.client.button.AbstractButton;
import pp.mdga.client.button.ButtonLeft; import pp.mdga.client.button.ButtonLeft;
import pp.mdga.client.button.ButtonRight; import pp.mdga.client.button.ButtonRight;
import pp.mdga.client.button.MenuButton; import pp.mdga.client.button.MenuButton;
import pp.mdga.client.view.MdgaView; import pp.mdga.client.view.MdgaView;
import java.util.prefs.Preferences;
public class VideoSettingsDialog extends Dialog { public class VideoSettingsDialog extends Dialog {
private static Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
private ButtonRight fullscreenButton;
private MenuButton backButton; private MenuButton backButton;
private ButtonRight restartButton;
private ButtonLeft hdButton9; private ButtonLeft hdButton9;
private ButtonLeft fullHdButton9; private ButtonLeft fullHdButton9;
@@ -29,20 +36,24 @@ public VideoSettingsDialog(MdgaApp app, Node node, MdgaView view) {
backButton = new MenuButton(app, node, view::leaveVideoSettings, "Zurück"); backButton = new MenuButton(app, node, view::leaveVideoSettings, "Zurück");
// MenuButton für verschiedene Auflösungen erstellen restartButton = new ButtonRight(app, node, MdgaApp::restartApp, "Neustart", 1);
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); fullscreenButton = new ButtonRight(app, node, () -> updateResolution(0, 0, 0, true), "Vollbild", 1);
wqhdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(2560, 1440, 4.0f), "wqhd 16:9", 10);
hdButton9 = new ButtonLeft(app, node, () -> updateResolution(1280, 720, 1.0f, false), "hd 16:9", 10);
fullHdButton9 = new ButtonLeft(app, node, () -> updateResolution(1920, 1080, 2.25f, false), "full hd 16:9", 10);
wqhdButton9 = new ButtonLeft(app, node, () -> updateResolution(2560, 1440, 4.0f, false), "wqhd 16:9", 10);
hdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1280, 800, 1.0f), "hd 16:10", 10); hdButton10 = new ButtonRight(app, node, () -> updateResolution(1280, 800, 1.0f, false), "hd 16:10", 10);
fullHdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1920, 1200, 2.25f), "full hd 16:10", 10); fullHdButton10 = new ButtonRight(app, node, () -> updateResolution(1920, 1200, 2.25f, false), "full hd 16:10", 10);
wqhdButton10 = new ButtonRight(app, node, () -> app.updateResolution(2560, 1600, 4.0f), "wqhd 16:10", 10); wqhdButton10 = new ButtonRight(app, node, () -> updateResolution(2560, 1600, 4.0f, false), "wqhd 16:10", 10);
float offset = 2.8f; float offset = 2.8f;
hdButton9.setPos(new Vector2f(hdButton9.getPos().x, MenuButton.VERTICAL - offset)); hdButton9.setPos(new Vector2f(hdButton9.getPos().x, MenuButton.VERTICAL - offset));
hdButton10.setPos(new Vector2f(hdButton10.getPos().x, MenuButton.VERTICAL - offset)); hdButton10.setPos(new Vector2f(hdButton10.getPos().x, MenuButton.VERTICAL - offset));
fullscreenButton.setPos(new Vector2f(fullscreenButton.getPos().x, MenuButton.VERTICAL - offset));
offset += 1.5f; offset += 1.5f;
fullHdButton9.setPos(new Vector2f(fullHdButton9.getPos().x, MenuButton.VERTICAL - offset)); fullHdButton9.setPos(new Vector2f(fullHdButton9.getPos().x, MenuButton.VERTICAL - offset));
@@ -68,6 +79,7 @@ protected void onShow() {
fullHdButton10.show(); fullHdButton10.show();
wqhdButton10.show(); wqhdButton10.show();
fullscreenButton.show();
backButton.show(); backButton.show();
} }
@@ -83,7 +95,9 @@ protected void onHide() {
fullHdButton10.hide(); fullHdButton10.hide();
wqhdButton10.hide(); wqhdButton10.hide();
fullscreenButton.hide();
backButton.hide(); backButton.hide();
restartButton.hide();
} }
public void update() { public void update() {
@@ -91,4 +105,12 @@ public void update() {
return; return;
} }
} }
public void updateResolution(int width, int height, float imageFactor, boolean isFullscreen) {
if(width != prefs.getInt("width", 1280) || height != prefs.getInt("height", 720) || isFullscreen != prefs.getBoolean("fullscreen", false)) {
restartButton.show();
}
app.updateResolution(width, height, imageFactor, isFullscreen);
}
} }

View File

@@ -10,19 +10,20 @@
import pp.mdga.client.animation.ZoomControl; import pp.mdga.client.animation.ZoomControl;
import pp.mdga.game.Color; import pp.mdga.game.Color;
public class ActionTextHandler { class ActionTextHandler {
private Node root; private Node root;
private BitmapFont font; private BitmapFont font;
private AppSettings appSettings; private AppSettings appSettings;
private int ranking;
public ActionTextHandler(Node guiNode, AssetManager assetManager, AppSettings appSettings){ ActionTextHandler(Node guiNode, AssetManager assetManager, AppSettings appSettings){
root = new Node("actionTextRoot"); root = new Node("actionTextRoot");
guiNode.attachChild(root); guiNode.attachChild(root);
root.setLocalTranslation(center(appSettings.getWidth(), appSettings.getHeight(), Vector3f.ZERO)); root.setLocalTranslation(center(appSettings.getWidth(), appSettings.getHeight(), Vector3f.ZERO));
font = assetManager.loadFont("Fonts/Gunplay.fnt"); font = assetManager.loadFont("Fonts/Gunplay.fnt");
this.appSettings = appSettings; this.appSettings = appSettings;
ranking = 0;
} }
private Node createTextWithSpacing(String[] textArr, float spacing, float size, ColorRGBA[] colorArr) { private Node createTextWithSpacing(String[] textArr, float spacing, float size, ColorRGBA[] colorArr) {
@@ -74,48 +75,48 @@ private Vector3f centerText(float width, float height, Vector3f pos){
return center(-width, height, pos); return center(-width, height, pos);
} }
public void activePlayer(String name, Color color){ void activePlayer(String name, Color color){
createTopText(new String[]{name," ist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{name," ist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
public void ownActive(Color color){ void ownActive(Color color){
createTopText(new String[]{"Du"," bist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{"Du"," bist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
public void diceNum(int diceNum, String name, Color color){ void diceNum(int diceNum, String name, Color color){
createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0); createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0);
createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 100); createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 100);
} }
public void diceNumMult(int diceNum,int mult, String name, Color color){ void diceNumMult(int diceNum,int mult, String name, Color color){
createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0); createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0);
createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 100); createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 100);
} }
public void ownDice(int diceNum){ void ownDice(int diceNum){
createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 0); createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 0);
} }
public void ownDiceMult(int diceNum, int mult){ void ownDiceMult(int diceNum, int mult){
createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 0); createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 0);
} }
public void drawCard(String name, Color color){ void drawCard(String name, Color color){
createTopText(new String[]{name," erhält eine Bonuskarte"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{name," erhält eine Bonuskarte"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
public void drawCardOwn(Color color){ void drawCardOwn(Color color){
createTopText(new String[]{"Du"," erhälst eine Bonuskarte"}, 5,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{"Du"," erhälst eine Bonuskarte"}, 5,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
public void finishText(String name, Color color){ void finishText(String name, Color color){
createTopText(new String[]{name," ist fertig!"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{name," ist fertig!"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
public void finishTextOwn(Color color){ void finishTextOwn(Color color){
createTopText(new String[]{"Du", " bist fertig!"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); createTopText(new String[]{"Du", " bist fertig!"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
} }
@@ -131,9 +132,25 @@ private ColorRGBA playerColorToColorRGBA(Color color){
}; };
} }
public void hide(){ void hide(){
ranking = 0;
root.detachAllChildren(); root.detachAllChildren();
} }
float paddingRanked = 100;
void rollRankingResult(String name, Color color, int eye){
createTopText(new String[]{name,": "+eye}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, paddingRanked*ranking);
ranking++;
}
void rollRankingResultOwn(Color color, int eye){
createTopText(new String[]{"Du",": "+eye}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, paddingRanked*ranking);
ranking++;
}
void diceNow(){
createTopText("Klicke zum Würfeln", 5, 80, ColorRGBA.White, 0);
}
} }

View File

@@ -60,7 +60,7 @@ private Node createNum(){
Material mat = new Material(getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); Material mat = new Material(getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Black); mat.setColor("Color", ColorRGBA.Black);
circle.setMaterial(mat); circle.setMaterial(mat);
root.attachChild(circle); // root.attachChild(circle);
BitmapFont guiFont = getApp().getAssetManager().loadFont("Fonts/Gunplay.fnt"); BitmapFont guiFont = getApp().getAssetManager().loadFont("Fonts/Gunplay.fnt");
num = new BitmapText(guiFont); num = new BitmapText(guiFont);
num.setSize(0.3f); num.setSize(0.3f);

View File

@@ -86,7 +86,7 @@ public void render(RenderManager rm) {
public void update(float tpf) { public void update(float tpf) {
if (init && !cardBuffer.isEmpty()) { if (init && !cardBuffer.isEmpty()) {
for (Spatial spatial : cardBuffer) { for (Spatial spatial : cardBuffer) {
root.attachChild(spatial); // root.attachChild(spatial);
} }
cardBuffer.clear(); cardBuffer.clear();
} }
@@ -94,7 +94,9 @@ public void update(float tpf) {
} }
public void addSpatial(Spatial card) { public void addSpatial(Spatial card) {
cardBuffer.add(card); // cardBuffer.add(card);
root.attachChild(card);
root = root;
} }
public void deleteSpatial(Spatial spatial) { public void deleteSpatial(Spatial spatial) {

View File

@@ -85,6 +85,19 @@ public void addCard(BonusCard card) {
bonusCardControlMap.get(card).setNumCard(newNum); bonusCardControlMap.get(card).setNumCard(newNum);
} }
public void removeCard(BonusCard card){
if(bonusCardControlMap.containsKey(card)){
bonusCardIntegerMap.put(card, bonusCardIntegerMap.get(card) - 1);
if(bonusCardIntegerMap.get(card) <= 0){
cardLayer.deleteSpatial(bonusCardControlMap.get(card).getRoot());
bonusCardIntegerMap.remove(card);
bonusCardControlMap.remove(card);
}
}
}
public void clearSelectableCards() { public void clearSelectableCards() {
for (CardControl control : selectableCards) { for (CardControl control : selectableCards) {
control.setSelectable(false); control.setSelectable(false);

View File

@@ -67,14 +67,38 @@ public void showRolledDice(int rollNum, Color color) {
public void showDice() { public void showDice() {
cardLayerHandler.showDice(); cardLayerHandler.showDice();
actionTextHandler.diceNow();
} }
public void hideDice() { public void hideDice() {
cardLayerHandler.hideDice(); cardLayerHandler.hideDice();
} }
public void addCard(BonusCard card) { //add own handCard
public void addCardOwn(BonusCard card) {
cardLayerHandler.addCard(card); cardLayerHandler.addCard(card);
playerNameHandler.addCard(ownColor);
actionTextHandler.drawCardOwn(ownColor);
}
public void playCardOwn(BonusCard card){
getEffectByCard(card);
cardLayerHandler.removeCard(card);
playerNameHandler.removeCard(ownColor);
}
public void playCardEnemy(Color color, BonusCard card) {
getEffectByCard(card);
playerNameHandler.removeCard(color);
}
private void getEffectByCard(BonusCard bonus){
switch(bonus){
case SWAP -> swap();
case TURBO -> turbo();
case SHIELD -> shield();
default -> throw new RuntimeException("invalid card");
}
} }
public void clearSelectableCards() { public void clearSelectableCards() {
@@ -124,9 +148,11 @@ public void hideText(){
actionTextHandler.hide(); actionTextHandler.hide();
} }
//addCard Enemy (DrawCardNotification)
public void drawCard(Color color) { public void drawCard(Color color) {
if (ownColor == color) actionTextHandler.drawCardOwn(color); //Color != ownColor
else actionTextHandler.drawCard(playerNameHandler.getName(color), color); actionTextHandler.drawCard(playerNameHandler.getName(color), color);
playerNameHandler.addCard(color);
} }
public void finish(Color color){ public void finish(Color color){
@@ -134,5 +160,12 @@ public void finish(Color color){
else actionTextHandler.finishText(playerNameHandler.getName(color), color); else actionTextHandler.finishText(playerNameHandler.getName(color), color);
} }
public void rollRankingResult(Color color, int eye){
if(ownColor == color) actionTextHandler.rollRankingResultOwn(color, eye);
else actionTextHandler.rollRankingResult(playerNameHandler.getName(color), color, eye);
}
} }

View File

@@ -4,23 +4,27 @@
import com.jme3.font.BitmapFont; import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText; import com.jme3.font.BitmapText;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.ui.Picture; import com.jme3.ui.Picture;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
public class PlayerNameHandler { public class PlayerNameHandler {
private final BitmapFont playerFont; private final BitmapFont playerFont;
private final Node playerNameNode; private final Node playerNameNode;
private final List<Color> playerOrder; private final List<Color> playerOrder;
private final Map<Color, String> colorNameMap; private final Map<Color, String> colorNameMap;
private final Map<Color, Integer> colorCardMap;
private final AppSettings appSettings; private final AppSettings appSettings;
private final AssetManager assetManager; private final AssetManager assetManager;
private Color ownColor; private Color ownColor;
@@ -43,6 +47,7 @@ public PlayerNameHandler(Node guiNode, AssetManager assetManager, AppSettings ap
playerNameNode = new Node("player name node"); playerNameNode = new Node("player name node");
playerOrder = new ArrayList<>(); playerOrder = new ArrayList<>();
colorNameMap = new HashMap<>(); colorNameMap = new HashMap<>();
colorCardMap = new HashMap<>();
this.appSettings = appSettings; this.appSettings = appSettings;
this.assetManager = assetManager; this.assetManager = assetManager;
} }
@@ -64,13 +69,38 @@ private void drawPlayers(){
if(!colorNameMap.containsKey(color)) throw new RuntimeException(color + " isn't mapped to a name"); if(!colorNameMap.containsKey(color)) throw new RuntimeException(color + " isn't mapped to a name");
Node nameParent = new Node("nameParent"); Node nameParent = new Node("nameParent");
nameParent.attachChild(createName(colorNameMap.get(color), i == 0, color == ownColor));
nameParent.attachChild(createColor(color)); nameParent.attachChild(createColor(color));
BitmapText name = createName(colorNameMap.get(color), i == 0, color == ownColor);
nameParent.attachChild(name);
if(colorCardMap.getOrDefault(color, 0) > 0){
Picture pic = createHandCard(name.getLineWidth());
nameParent.attachChild(pic);
nameParent.attachChild(createCardNum(colorCardMap.get(color), pic.getWidth(), pic.getLocalTranslation().getX()));
}
nameParent.setLocalTranslation(50,appSettings.getWindowHeight()-PADDING_TOP- MARGIN_NAMES *i,0); nameParent.setLocalTranslation(50,appSettings.getWindowHeight()-PADDING_TOP- MARGIN_NAMES *i,0);
playerNameNode.attachChild(nameParent); playerNameNode.attachChild(nameParent);
} }
} }
private Spatial createCardNum(int num, float lastWidth, float lastX ) {
BitmapText hudText = new BitmapText(playerFont);
//renderedSize = 45
hudText.setSize(TEXT_SIZE);
hudText.setColor(NORMAL_COLOR);
hudText.setText(String.valueOf(num));
hudText.setLocalTranslation(lastX + lastWidth + 20,hudText.getHeight()/2, 0);
return hudText;
}
private Picture createHandCard(float width) {
Picture pic = new Picture("HUD Picture");
pic.setImage(assetManager, "./Images/handcard.png", true);
pic.setWidth(IMAGE_SIZE);
pic.setHeight(IMAGE_SIZE);
pic.setPosition(-pic.getWidth()/2 + width + PADDING_LEFT * 2 ,-pic.getHeight()/2);
return pic;
}
private String imagePath(Color color){ private String imagePath(Color color){
String root = "./Images/name_pictures/"; String root = "./Images/name_pictures/";
return switch(color){ return switch(color){
@@ -93,7 +123,7 @@ private Spatial createColor(Color color) {
private Spatial createName(String name, boolean first, boolean own){ private BitmapText createName(String name, boolean first, boolean own){
BitmapText hudText = new BitmapText(playerFont); BitmapText hudText = new BitmapText(playerFont);
//renderedSize = 45 //renderedSize = 45
hudText.setSize(TEXT_SIZE); hudText.setSize(TEXT_SIZE);
@@ -120,8 +150,22 @@ public void setActivePlayer(Color color) {
} }
public String getName(Color color){ public String getName(Color color){
if(!colorNameMap.containsKey(color)) throw new RuntimeException("color is not in colorNameMap");
return colorNameMap.get(color); return colorNameMap.get(color);
} }
public void addCard(Color color){
colorCardMap.put(color, colorCardMap.getOrDefault(color, 0) + 1);
drawPlayers();
}
public void removeCard(Color color){
if(colorCardMap.containsKey(color)){
colorCardMap.put(color, colorCardMap.getOrDefault(color, 0) - 1);
if(colorCardMap.get(color) <= 0) colorCardMap.remove(color);
}
drawPlayers();
}
} }

View File

@@ -3,6 +3,7 @@
import com.jme3.network.*; import com.jme3.network.*;
import com.jme3.network.serializing.Serializer; import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.EnumSerializer; import com.jme3.network.serializing.serializers.EnumSerializer;
import pp.mdga.Resources;
import pp.mdga.game.*; import pp.mdga.game.*;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
@@ -135,6 +136,7 @@ private void initializeSerializables() {
Serializer.registerClass(UpdateReadyMessage.class); Serializer.registerClass(UpdateReadyMessage.class);
Serializer.registerClass(UpdateTSKMessage.class); Serializer.registerClass(UpdateTSKMessage.class);
Serializer.registerClass(WaitPieceMessage.class); Serializer.registerClass(WaitPieceMessage.class);
Serializer.registerClass(IncorrectRequestMessage.class);
Serializer.registerClass(Player.class); Serializer.registerClass(Player.class);
Serializer.registerClass(Statistic.class); Serializer.registerClass(Statistic.class);
Serializer.registerClass(Board.class); Serializer.registerClass(Board.class);
@@ -144,8 +146,10 @@ private void initializeSerializables() {
Serializer.registerClass(StartNode.class); Serializer.registerClass(StartNode.class);
Serializer.registerClass(PlayerData.class); Serializer.registerClass(PlayerData.class);
Serializer.registerClass(HomeNode.class); Serializer.registerClass(HomeNode.class);
Serializer.registerClass(PlayerDataMessage.class);
Serializer.registerClass(StartBriefingMessage.class); Serializer.registerClass(Color.class, new EnumSerializer());
Serializer.registerClass(PieceState.class, new EnumSerializer());
Serializer.registerClass(ShieldState.class, new EnumSerializer());
} }
private void registerListeners() { private void registerListeners() {
@@ -198,12 +202,31 @@ private void messageReceived(HostedConnection source, ClientMessage message) {
pendingMessages.add(new ReceivedMessage(message, source.getId())); pendingMessages.add(new ReceivedMessage(message, source.getId()));
} }
/**
* This method will be used to handle all connections which are connected to the server.
* It will check if the maximum number of connected clients are already reached. If yes it will send a
* LobbyDenyMessage to the given hostedConnection parameter and close it, otherwise it will send a
* LobbyAcceptMessage to the given hostedConnection parameter. In Addition, if the number of connected clients is
* equal to 1 it will set the host of the game to the id of the given hostedConnection parameter.
*
* @param server as the server which is contains all connections as a Server object.
* @param hostedConnection as the connection which is added to the server as a HostedConnection object.
*/
@Override @Override
public void connectionAdded(Server server, HostedConnection hostedConnection) { public void connectionAdded(Server server, HostedConnection hostedConnection) {
System.out.println("new connection " + hostedConnection); //NON-NLS System.out.println("new connection " + hostedConnection); //NON-NLS
LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS
if (this.myServer.getConnections().size() == 1) {
if (this.myServer.getConnections().size() > Resources.MAX_PLAYERS) {
this.logic.getServerSender().send(hostedConnection.getId(), new LobbyDenyMessage());
hostedConnection.close("");
} else {
if (hostedConnection.getAddress().contains("127.0.0.1") && this.logic.getGame().getHost() == -1) {
this.logic.getGame().setHost(hostedConnection.getId()); this.logic.getGame().setHost(hostedConnection.getId());
this.logic.getServerSender().send(hostedConnection.getId(), new LobbyAcceptMessage(hostedConnection.getId()));
} else {
this.logic.getServerSender().send(hostedConnection.getId(), new LobbyAcceptMessage());
}
} }
} }
@@ -278,4 +301,21 @@ public void broadcast(ServerMessage message) {
public void disconnectClient(int id) { public void disconnectClient(int id) {
this.myServer.getConnection(id).close(""); this.myServer.getConnection(id).close("");
} }
/**
* This method will be used to shut down the server.
* It will iterate threw all connections of myServer attribute and check if they are equal to null. If not they will
* be closed. After that the myServer attribute will be closed and this program will be exited with the exit code 0.
*/
@Override
public void shutdown() {
for (HostedConnection client : this.myServer.getConnections()) {
if (client != null) {
client.close("Host closed the server.");
}
}
this.myServer.close();
this.exit(0);
}
} }

View File

@@ -65,6 +65,13 @@ public void onEnter() {
app.getAcousticHandler().playSound(MdgaSound.START); app.getAcousticHandler().playSound(MdgaSound.START);
guiHandler.addPlayer(Color.AIRFORCE, "Cedric");
guiHandler.addPlayer(Color.ARMY, "Ben");
guiHandler.addPlayer(Color.CYBER, "Felix");
guiHandler.addPlayer(Color.NAVY, "Daniel");
} }
@Override @Override

View File

@@ -18,6 +18,7 @@
import pp.mdga.client.button.LobbyButton; import pp.mdga.client.button.LobbyButton;
import pp.mdga.client.button.SettingsButton; import pp.mdga.client.button.SettingsButton;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.message.client.StartGameMessage;
import pp.mdga.notification.GameNotification; import pp.mdga.notification.GameNotification;
public class LobbyView extends MdgaView { public class LobbyView extends MdgaView {
@@ -25,6 +26,7 @@ public class LobbyView extends MdgaView {
private ButtonLeft leaveButton; private ButtonLeft leaveButton;
private ButtonRight readyButton; private ButtonRight readyButton;
private ButtonRight startButton;
private LobbyButton cyberButton; private LobbyButton cyberButton;
private LobbyButton airforceButton; private LobbyButton airforceButton;
@@ -42,6 +44,7 @@ public LobbyView(MdgaApp app) {
leaveButton = new ButtonLeft(app, guiNode, this::leaveLobby, "Verlassen", 1); leaveButton = new ButtonLeft(app, guiNode, this::leaveLobby, "Verlassen", 1);
readyButton = new ButtonRight(app, guiNode, this::ready, "Bereit", 1); readyButton = new ButtonRight(app, guiNode, this::ready, "Bereit", 1);
startButton = new ButtonRight(app, guiNode, () -> app.getGameLogic().selectStart(), "Starten", 7);
cyberButton = new LobbyButton(app, guiNode, rootNode, () -> toggleTsk(Color.CYBER), Color.CYBER); cyberButton = new LobbyButton(app, guiNode, rootNode, () -> toggleTsk(Color.CYBER), Color.CYBER);
airforceButton = new LobbyButton(app, guiNode, rootNode, () -> toggleTsk(Color.AIRFORCE), Color.AIRFORCE); airforceButton = new LobbyButton(app, guiNode, rootNode, () -> toggleTsk(Color.AIRFORCE), Color.AIRFORCE);
@@ -61,6 +64,10 @@ public void onEnter() {
leaveButton.show(); leaveButton.show();
readyButton.show(); readyButton.show();
if(app.getGameLogic().isHost()) {
startButton.show();
}
cyberButton.show(); cyberButton.show();
airforceButton.show(); airforceButton.show();
armyButton.show(); armyButton.show();
@@ -95,6 +102,7 @@ public void onEnter() {
public void onLeave() { public void onLeave() {
leaveButton.hide(); leaveButton.hide();
readyButton.hide(); readyButton.hide();
startButton.hide();
airforceButton.hide(); airforceButton.hide();
armyButton.hide(); armyButton.hide();
@@ -223,6 +231,10 @@ private void toggleTsk(Color color) {
break; break;
} }
if(isReady) {
setReady(own, false);
}
switch (taken) { switch (taken) {
case NOT: case NOT:
app.getModelSynchronize().selectTsk(color); app.getModelSynchronize().selectTsk(color);

View File

@@ -1,8 +1,12 @@
package pp.mdga.client.view; package pp.mdga.client.view;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaApp;
import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.acoustic.MdgaSound;
import pp.mdga.client.button.AbstractButton;
import pp.mdga.client.button.LabelButton;
import pp.mdga.client.dialog.HostDialog; import pp.mdga.client.dialog.HostDialog;
import pp.mdga.client.dialog.JoinDialog; import pp.mdga.client.dialog.JoinDialog;
import pp.mdga.client.dialog.StartDialog; import pp.mdga.client.dialog.StartDialog;
@@ -96,6 +100,7 @@ private void mainMenu() {
private void tryHost() { private void tryHost() {
int port = 0; int port = 0;
String text = hostDialog.getPort(); String text = hostDialog.getPort();
app.getGameLogic().selectHost("");
try { try {
port = Integer.parseInt(text); port = Integer.parseInt(text);
@@ -108,10 +113,6 @@ private void tryHost() {
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
hostDialog.connectServerAsClient(); hostDialog.connectServerAsClient();
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
app.getModelSynchronize().setHost(port); app.getModelSynchronize().setHost(port);
//app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); //app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT);
return; return;
@@ -127,6 +128,7 @@ private void tryJoin() {
int port = 0; int port = 0;
String ip = joinDialog.getIpt(); String ip = joinDialog.getIpt();
String portText = joinDialog.getPort(); String portText = joinDialog.getPort();
app.getGameLogic().selectJoin("");
try { try {
// Validate the port // Validate the port
@@ -140,11 +142,6 @@ private void tryJoin() {
app.getModelSynchronize().setName(startDialog.getName()); app.getModelSynchronize().setName(startDialog.getName());
joinDialog.setHostname(ip); joinDialog.setHostname(ip);
joinDialog.connectToServer(); joinDialog.connectToServer();
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
app.getModelSynchronize().setJoin(ip, port);
return; return;
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@@ -234,5 +231,13 @@ public void back() {
break; break;
} }
} }
public JoinDialog getJoinDialog() {
return joinDialog;
}
public HostDialog getHostDialog() {
return hostDialog;
}
} }

View File

@@ -2,9 +2,12 @@
import com.jme3.asset.TextureKey; import com.jme3.asset.TextureKey;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad; import com.jme3.scene.shape.Quad;
import com.jme3.system.NanoTimer;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaApp;
import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.acoustic.MdgaSound;
@@ -30,6 +33,9 @@ public enum Overlay {
private VideoSettingsDialog videoSettingsDialog; private VideoSettingsDialog videoSettingsDialog;
private AudioSettingsDialog audioSettingsDialog; private AudioSettingsDialog audioSettingsDialog;
protected LabelButton infoLabel = null;
protected NanoTimer infoTimer = new NanoTimer();
private int settingsDepth = 0; private int settingsDepth = 0;
public MdgaView(MdgaApp app) { public MdgaView(MdgaApp app) {
@@ -80,6 +86,11 @@ public void update(float tpf) {
videoSettingsDialog.update(); videoSettingsDialog.update();
audioSettingsDialog.update(); audioSettingsDialog.update();
if (null != infoLabel && infoTimer.getTimeInSeconds() > 5) {
infoLabel.hide();
infoLabel = null;
}
onUpdate(tpf); onUpdate(tpf);
} }
@@ -193,4 +204,24 @@ public void pressForward() {
ceremonyView.forward(); ceremonyView.forward();
} }
} }
public void showInfo(String error, boolean isError) {
infoTimer.reset();
if(null != infoLabel) {
infoLabel.hide();
}
infoLabel = new LabelButton(app, guiNode, error, new Vector2f(5.5f, 2), new Vector2f(0.5f, AbstractButton.VERTICAL - 0.5f), false);
ColorRGBA color;
if(isError) {
color = ColorRGBA.Red.clone();
} else {
color = ColorRGBA.Green.clone();
}
infoLabel.setColor(ColorRGBA.Black, color);
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -1,7 +1,5 @@
world 0,0 90 world 0,0 90
#tree_small 1,1 0
#tree_big 0,0 0
#Marine Pos #Marine Pos
marine 4,-5 270 marine 4,-5 270
@@ -131,3 +129,144 @@ node_home_blue 4,0 0
node_home_blue 3,0 0 node_home_blue 3,0 0
node_home_blue 2,0 0 node_home_blue 2,0 0
node_home_blue 1,0 0 node_home_blue 1,0 0
# Randomly Distributed Trees within Radius 12 to 40
treeSmall 10,15 180
treeBig -15,12 45
treeSmall -8,-22 270
treeBig 22,8 90
treeSmall -18,-10 135
treeBig 9,24 300
treeSmall 17,-9 60
treeBig -20,5 330
treeSmall -14,18 200
treeBig 25,-7 120
treeBig -12,-18 150
treeSmall 19,-16 45
treeBig 7,10 90
treeBig -19,-9 270
treeSmall 21,4 110
treeBig -11,17 300
treeSmall 3,-21 360
treeSmall -23,14 100
treeBig 4,26 330
treeSmall 12,13 270
treeBig -18,8 45
treeBig 11,-10 135
treeSmall 16,5 180
treeBig -13,-17 330
treeSmall -2,14 270
#treeBig 7,9 300
treeSmall 23,-10 240
treeBig -6,18 180
treeSmall 5,27 270
treeBig 14,-11 60
treeSmall 9,-16 180
treeBig -12,22 240
treeBig 18,7 360
treeSmall -24,-4 200
treeBig -8,21 300
treeSmall 12,-19 120
treeBig 6,-12 180
treeSmall -11,10 75
treeBig 9,6 270
treeSmall 8,-14 150
treeBig 3,18 30
treeSmall 17,13 100
treeBig -9,20 90
treeBig 6,-22 330
treeSmall -20,7 45
treeBig 21,11 150
treeSmall 15,-18 270
treeBig -3,-12 200
treeBig 12,-28 330
treeSmall -17,-7 120
treeBig -10,9 300
treeSmall 2,-14 240
treeBig 24,2 360
treeSmall 4,-13 300
treeBig -19,20 90
#treeSmall -11,5 45
treeBig 15,9 180
treeSmall -6,10 240
treeBig 3,15 30
treeSmall 9,-19 150
treeBig -21,-4 330
treeSmall 19,11 270
treeSmall 12,24 110
treeBig -13,15 45
treeSmall 7,-15 240
treeBig 26,-8 300
treeSmall -16,14 120
treeBig 14,18 360
treeSmall 8,21 100
treeBig -8,-18 240
treeSmall 9,15 180
treeBig 10,-20 270
treeSmall 2,27 90
treeBig 18,12 300
treeSmall -10,-14 150
treeBig -15,16 330
treeSmall -9,19 45
treeBig 17,-14 120
treeSmall 5,-25 180
treeBig 7,23 30
treeSmall -14,-12 200
treeBig 6,-16 300
treeSmall -20,-8 100
treeBig 4,11 240
treeSmall 24,-15 90
treeSmall -19,-19 360
treeBig 20,8 45
treeSmall 3,22 270
treeBig 13,-9 180
treeSmall -11,18 150
treeBig -17,-4 300
treeSmall 5,-14 240
treeBig 9,17 330
treeSmall 15,13 90
treeBig -21,18 30
treeSmall 6,20 100
treeBig -16,22 180
treeSmall -5,18 360
treeBig 22,11 45
treeSmall 10,-23 240
treeBig -10,-16 300
treeSmall -17,14 120
treeBig 20,4 150
treeSmall 11,-22 180
treeBig -24,-11 200
treeSmall 14,17 150
treeBig -8,-12 300
treeSmall 7,-18 100
treeBig -5,16 330
treeSmall 16,-14 200
treeBig 18,-8 90
treeSmall -23,-9 45
treeBig 24,10 300
treeSmall -4,19 180
treeBig 12,-5 330
treeSmall -19,16 100
treeBig 14,20 150
treeSmall 9,12 180
treeBig -22,8 60
treeSmall 6,18 360
treeBig 25,-9 45
treeBig -10,12 240
treeSmall 19,-17 100
treeSmall -13,19 90
treeSmall 16,-12 120
treeBig 22,-6 45
treeSmall -18,15 200
treeBig 14,-10 300
treeBig 6,10 330
treeSmall 17,18 90
treeBig -20,4 180
treeBig 19,-16 300
treeSmall -15,9 270
treeBig 12,22 360

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 59 KiB

View File

@@ -0,0 +1,79 @@
package pp.mdga;
import java.util.ResourceBundle;
/**
* Provides access to the resource bundle of the game.
*
* @see #BUNDLE
*/
public class Resources {
/**
* Create Resources constants.
*/
public static final int MAX_PLAYERS = 4;
public static final int MAX_PIECES = 4;
public static final int MAX_EYES = 6;
/**
* The resource bundle for the MDGA game.
*/
public static final ResourceBundle BUNDLE = ResourceBundle.getBundle("mdga"); //NON-NLS
/**
* Gets a string for the given key from the resource bundle in {@linkplain #BUNDLE}.
*
* @param key the key for the desired string
* @return the string for the given key
* @throws NullPointerException if {@code key} is {@code null}
* @throws java.util.MissingResourceException if no object for the given key can be found
* @throws ClassCastException if the object found for the given key is not a string
*/
public static String stringLookup(String key) {
return BUNDLE.getString(key);
}
/**
* Gets a int for the given key from the resource bundle in {@linkplain #BUNDLE}.
*
* @param key the key for the desired string
* @return the string for the given key
* @throws NullPointerException if {@code key} is {@code null}
* @throws java.util.MissingResourceException if no object for the given key can be found
* @throws ClassCastException if the object found for the given key is not a string
*/
public static int intLookup(String key) {
return Integer.parseInt(BUNDLE.getString(key));
}
/**
* Gets a boolean for the given key from the resource bundle in {@linkplain #BUNDLE}.
*
* @param key the key for the desired string
* @return the string for the given key
* @throws NullPointerException if {@code key} is {@code null}
* @throws java.util.MissingResourceException if no object for the given key can be found
* @throws ClassCastException if the object found for the given key is not a string
*/
public static boolean boolLookup(String key) {
return Boolean.parseBoolean(BUNDLE.getString(key));
}
/**
* Gets a double for the given key from the resource bundle in {@linkplain #BUNDLE}.
*
* @param key the key for the desired string
* @return the string for the given key
* @throws NullPointerException if {@code key} is {@code null}
* @throws java.util.MissingResourceException if no object for the given key can be found
* @throws ClassCastException if the object found for the given key is not a string
*/
public static double doubleLookup(String key) {
return Double.parseDouble(BUNDLE.getString(key));
}
/**
* Private constructor to prevent instantiation.
*/
private Resources() { /* do not instantiate */ }
}

View File

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

View File

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

View File

@@ -37,159 +37,155 @@ public String toString(){
@Override @Override
public void received(ActivePlayerMessage msg) { public void received(ActivePlayerMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(AnyPieceMessage msg) { public void received(AnyPieceMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(BriefingMessage msg) { public void received(BriefingMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(CeremonyMessage msg) { public void received(CeremonyMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(DieMessage msg) { public void received(DieMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(DiceAgainMessage msg) { public void received(DiceAgainMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(DiceNowMessage msg) { public void received(DiceNowMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(EndOfTurnMessage msg) { public void received(EndOfTurnMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(LobbyAcceptMessage msg) { public void received(LobbyAcceptMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(LobbyDenyMessage msg) { public void received(LobbyDenyMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(LobbyPlayerJoinedMessage msg) { public void received(LobbyPlayerJoinedMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(LobbyPlayerLeaveMessage msg) { public void received(LobbyPlayerLeaveMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(MoveMessage msg) { public void received(MoveMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(NoTurnMessage msg) { public void received(NoTurnMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(PauseGameMessage msg) { public void received(PauseGameMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(PlayCardMessage msg) { public void received(PlayCardMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(PossibleCardMessage msg) { public void received(PossibleCardMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(PossiblePieceMessage msg) { public void received(PossiblePieceMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(RankingResponseMessage msg) { public void received(RankingResponseMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(RankingRollAgainMessage msg) { public void received(RankingRollAgainMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(ReconnectBriefingMessage msg) { public void received(ReconnectBriefingMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(ResumeGameMessage msg) { public void received(ResumeGameMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(ServerStartGameMessage msg) { public void received(ServerStartGameMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(ShutdownMessage msg) {LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);} public void received(ShutdownMessage msg) {LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());}
@Override @Override
public void received(StartPieceMessage msg) { public void received(StartPieceMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(UpdateReadyMessage msg) { public void received(UpdateReadyMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(UpdateTSKMessage msg) { public void received(UpdateTSKMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(SpectatorMessage msg) { public void received(SpectatorMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(SelectPieceMessage msg) { public void received(SelectPieceMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(WaitPieceMessage msg) { public void received(WaitPieceMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
} }
@Override @Override
public void received(StartBriefingMessage msg) { public void received(IncorrectRequestMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
public void received(PlayerDataMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
} }
public void selectPiece(Piece piece) { public void selectPiece(Piece piece) {
@@ -252,6 +248,11 @@ public void selectResume(){
LOGGER.log(Level.DEBUG, "Resume not allowed"); LOGGER.log(Level.DEBUG, "Resume not allowed");
} }
/**
* This method is used to create a CeremonyNotification
*
* @return the created CeremonyNotification
*/
protected CeremonyNotification createCeremonyNotification(){ protected CeremonyNotification createCeremonyNotification(){
CeremonyNotification notification = new CeremonyNotification(); CeremonyNotification notification = new CeremonyNotification();
for (var player : logic.getGame().getPlayers().entrySet()){ for (var player : logic.getGame().getPlayers().entrySet()){

View File

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

View File

@@ -3,8 +3,10 @@
import pp.mdga.client.gameState.*; import pp.mdga.client.gameState.*;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.InterruptNotification; import pp.mdga.notification.InterruptNotification;
import pp.mdga.notification.StartDialogNotification;
public class GameState extends ClientState { public class GameState extends ClientState {
@@ -27,7 +29,6 @@ public class GameState extends ClientState {
*/ */
public GameState(ClientState parent, ClientGameLogic logic) { public GameState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
state = determineStartPlayerState;
} }
/** /**
@@ -35,7 +36,7 @@ public GameState(ClientState parent, ClientGameLogic logic) {
*/ */
@Override @Override
public void enter() { public void enter() {
this.setState(this.determineStartPlayerState);
} }
/** /**
@@ -52,137 +53,278 @@ public void exit() {
* @param newState the state to be set * @param newState the state to be set
*/ */
public void setState(GameStates newState){ public void setState(GameStates newState){
state.exit(); if(this.state != null){
state.enter(); this.state.exit();
}
newState.enter();
state = newState; state = newState;
} }
/**
* This method is used to call the selectAnimationEnd method of the current state
*/
@Override @Override
public void selectAnimationEnd(){ public void selectAnimationEnd(){
state.selectAnimationEnd(); state.selectAnimationEnd();
} }
/**
* This method is used to call the selectDice method of the current state
*/
@Override @Override
public void selectDice(){ public void selectDice(){
state.selectDice(); state.selectDice();
} }
/**
* This method is used to call the selectPiece method of the current state
*
* @param piece the piece to be selected
*/
@Override @Override
public void selectPiece(Piece piece){ public void selectPiece(Piece piece){
state.selectPiece(piece); state.selectPiece(piece);
} }
/**
* This method is used to call the selectCard method of the current state
*
* @param card the card to be selected
*/
@Override @Override
public void selectCard(BonusCard card){ public void selectCard(BonusCard card){
state.selectCard(card); state.selectCard(card);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(PauseGameMessage msg){ public void received(PauseGameMessage msg){
logic.enterInterrupt(); logic.enterInterrupt();
logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor())); logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor()));
} }
@Override
public void selectLeave(){
logic.send(new LeaveGameMessage());
logic.addNotification(new StartDialogNotification());
logic.setState(logic.getDialogs());
}
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(RankingRollAgainMessage msg){ public void received(RankingRollAgainMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(RankingResponseMessage msg){ public void received(RankingResponseMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(SelectPieceMessage msg){ public void received(SelectPieceMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(WaitPieceMessage msg){ public void received(WaitPieceMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(StartPieceMessage msg){ public void received(StartPieceMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(NoTurnMessage msg){ public void received(NoTurnMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(CeremonyMessage msg){ public void received(CeremonyMessage msg){
state.received(msg); logic.addNotification(createCeremonyNotification());
logic.setState(logic.getCeremony());
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(EndOfTurnMessage msg){ public void received(EndOfTurnMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(SpectatorMessage msg){ public void received(SpectatorMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(DiceAgainMessage msg){ public void received(DiceAgainMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(PossibleCardMessage msg){ public void received(PossibleCardMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(PlayCardMessage msg){ public void received(PlayCardMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(DiceNowMessage msg){ public void received(DiceNowMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method is used to call the received method of the current state
*
* @param msg the message to be received
*/
@Override @Override
public void received(ActivePlayerMessage msg){ public void received(ActivePlayerMessage msg){
state.received(msg); state.received(msg);
} }
/**
* This method returns the current state
*
* @return the current state
*/
public GameStates getState(){ public GameStates getState(){
return state; return state;
} }
/**
* This method returns the AnimationState
*
* @return the AnimationState
*/
public AnimationState getAnimation() { public AnimationState getAnimation() {
return animationState; return animationState;
} }
/**
* This method returns the DetermineStartPlayerState
*
* @return the DetermineStartPlayerState
*/
public DetermineStartPlayerState getDetermineStartPlayer() { public DetermineStartPlayerState getDetermineStartPlayer() {
return determineStartPlayerState; return determineStartPlayerState;
} }
/**
* This method returns the SpectatorState
*
* @return the SpectatorState
*/
public SpectatorState getSpectator() { public SpectatorState getSpectator() {
return spectatorState; return spectatorState;
} }
/**
* This method returns the TurnState
*
* @return the TurnState
*/
public TurnState getTurn() { public TurnState getTurn() {
return turnState; return turnState;
} }
/**
* This method returns the WaitingState
*
* @return the WaitingState
*/
public WaitingState getWaiting() { public WaitingState getWaiting() {
return waitingState; return waitingState;
} }

View File

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

View File

@@ -10,9 +10,7 @@
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.LobbyPlayerJoinedMessage; import pp.mdga.message.server.LobbyPlayerJoinedMessage;
import pp.mdga.message.server.LobbyPlayerLeaveMessage; import pp.mdga.message.server.LobbyPlayerLeaveMessage;
import pp.mdga.message.server.PlayerDataMessage;
import pp.mdga.message.server.ServerStartGameMessage; import pp.mdga.message.server.ServerStartGameMessage;
import pp.mdga.message.server.StartBriefingMessage;
import pp.mdga.message.server.UpdateReadyMessage; import pp.mdga.message.server.UpdateReadyMessage;
import pp.mdga.message.server.UpdateTSKMessage; import pp.mdga.message.server.UpdateTSKMessage;
import pp.mdga.notification.*; import pp.mdga.notification.*;
@@ -30,7 +28,7 @@ public LobbyState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
logic.send(new JoinedLobbyMessage(parent.getOwnPlayerName())); logic.send(new JoinedLobbyMessage(logic.getOwnPlayerName()));
} }
@Override @Override
@@ -66,55 +64,46 @@ public void selectUnready(){
@Override @Override
public void selectStart(){ public void selectStart(){
if(logic.isHost() && logic.getGame().allReady()){ if(logic.isHost() && logic.getGame().areAllReady()){
logic.send(new StartGameMessage(false)); logic.send(new StartGameMessage(false));
} else if(logic.isHost() && !logic.getGame().allReady()) { } else if(logic.isHost() && !logic.getGame().areAllReady()) {
logic.send(new StartGameMessage(true)); logic.send(new StartGameMessage(true));
} else { } else {
LOGGER.log(System.Logger.Level.ERROR, "You are not the host"); LOGGER.log(System.Logger.Level.ERROR, "You are not the host");
} }
} }
@Override
public void received(StartBriefingMessage msg){
logic.getGame().setBoard(msg.getBoard());
}
public void received(PlayerDataMessage msg){
logic.getGame().getBoard().addPlayerData(msg.getColor(), msg.getPlayerData());
}
@Override @Override
public void received(ServerStartGameMessage msg){ public void received(ServerStartGameMessage msg){
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(parent.getOwnPlayerId()).getColor())); logic.getGame().setBoard(msg.getBoard());
for (Map.Entry<Color, PlayerData> entry : logic.getGame().getBoard().getPlayerData().entrySet()) { logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
List<UUID> pieceList = new ArrayList<>(); for (Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()) {
for(Piece piece : entry.getValue().getPieces()){ List<UUID> pieces = new ArrayList<>();
System.out.println(piece.getUuid()); for (Piece piece : logic.getGame().getBoard().getPlayerData().get(entry.getValue().getColor()).getPieces()) {
pieceList.add(piece.getUuid()); pieces.add(piece.getUuid());
} }
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceList , logic.getGame().getPlayerByColor(entry.getKey()).getName())); logic.addNotification(new PlayerInGameNotification(entry.getValue().getColor(), pieces, entry.getValue().getName()));
} }
parent.startGame(); logic.setState(logic.getGameState());
} }
@Override @Override
public void received(LobbyPlayerJoinedMessage msg){ public void received(LobbyPlayerJoinedMessage msg){
if(msg.getPlayer().getName().equals(parent.getOwnPlayerName())){ if(msg.getPlayer().getName().equals(logic.getOwnPlayerName())){
parent.setOwnPlayerId(msg.getId()); logic.setOwnPlayerId(msg.getId());
} }
if (msg.isHost() && msg.getId() == parent.getOwnPlayerId()){ if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()){
logic.setHost(true); logic.setHost(true);
} }
logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), msg.getPlayer().getName().equals(parent.getOwnPlayerName()))); logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), msg.getPlayer().getName().equals(logic.getOwnPlayerName())));
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer()); logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
} }
@Override @Override
public void received(UpdateTSKMessage msg){ public void received(UpdateTSKMessage msg){
if(msg.isTaken()) { if(msg.isTaken()) {
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId())); logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), logic.getOwnPlayerId()== msg.getId()));
} else { } else {
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor())); logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
} }

View File

@@ -1,34 +1,72 @@
package pp.mdga.client.dialogState; package pp.mdga.client.dialogState;
import pp.mdga.Resources;
import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.client.DialogsState; import pp.mdga.client.DialogsState;
import pp.mdga.message.server.LobbyAcceptMessage;
import pp.mdga.message.server.LobbyDenyMessage;
import pp.mdga.notification.InfoNotification;
import pp.mdga.notification.LobbyDialogNotification; import pp.mdga.notification.LobbyDialogNotification;
public class NetworkDialogState extends DialogStates { public class NetworkDialogState extends DialogStates {
private final DialogsState parent; private final DialogsState parent;
/**
* Constructor for the NetworkDialogState
* @param parent the parent state
* @param logic the logic
*/
public NetworkDialogState(ClientState parent, ClientGameLogic logic) { public NetworkDialogState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
this.parent = (DialogsState) parent; this.parent = (DialogsState) parent;
} }
/**
* Enter the state
*/
@Override @Override
public void enter() { public void enter() {
LOGGER.log(System.Logger.Level.INFO, "Entered {0}", this);
} }
/**
* Exit the state
*/
@Override @Override
public void exit() { public void exit() {
} }
/**
* Select the leave option
*/
@Override @Override
public void selectLeave() { public void selectLeave() {
parent.setState(parent.getStartDialog()); parent.setState(parent.getStartDialog());
} }
public void selectJoin(String IP) { /**
* This method is called when the server accepts the client into the lobby
*
* @param msg the LobbyAcceptMessage
*/
@Override
public void received(LobbyAcceptMessage msg) {
logic.getGame().setHost(msg.getHost());
logic.setHost(logic.getGame().isHost());
parent.setState(parent.getLobby()); parent.setState(parent.getLobby());
logic.addNotification(new LobbyDialogNotification()); logic.addNotification(new LobbyDialogNotification());
} }
/**
* This method is called when the server denies the client into the lobby
*
* @param msg the LobbyDenyMessage
*/
@Override
public void received(LobbyDenyMessage msg) {
logic.addNotification(new InfoNotification(Resources.stringLookup("lobby.deny.join")));
parent.setState(parent.getStartDialog());
}
} }

View File

@@ -8,41 +8,44 @@ public class StartDialogState extends DialogStates {
private final DialogsState parent; private final DialogsState parent;
/**
* Constructor for the StartDialogState
* @param parent the parent state
* @param logic the logic
*/
public StartDialogState(ClientState parent, ClientGameLogic logic) { public StartDialogState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
this.parent = (DialogsState) parent; this.parent = (DialogsState) parent;
} }
/**
* Enter the state
*/
@Override @Override
public void enter() { public void enter() {
} }
/**
* Exit the state
*/
@Override @Override
public void exit() { public void exit() {
}
@Override
public void selectJoin(String name) {
parent.setOwnPlayerName(name);
parent.setState(parent.getNetworkDialog());
logic.setHost(false);
}
@Override
public void selectHost(String name) {
parent.setOwnPlayerName(name);
parent.setState(parent.getLobby());
logic.setHost(true);
} }
/**
* Set the name
*
* @param name the name
*/
@Override @Override
public void setName(String name) { public void setName(String name) {
logic.setOwnPlayerName(name);
parent.setState(parent.getNetworkDialog()); parent.setState(parent.getNetworkDialog());
parent.setOwnPlayerName(name);
} }
/**
* Select the leave option
*/
@Override @Override
public void selectLeave() { public void selectLeave() {
parent.exit(); parent.exit();

View File

@@ -25,7 +25,7 @@ public DetermineStartPlayerState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
state = rollRankingDiceState; this.setState(this.rollRankingDiceState);
} }
@Override @Override
@@ -34,7 +34,9 @@ public void exit() {
} }
public void setState(DetermineStartPlayerStates state) { public void setState(DetermineStartPlayerStates state) {
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }

View File

@@ -36,8 +36,7 @@ protected void handlePowerCard(PlayCardMessage msg){
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece);
logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece); logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece);
} }
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard()); logic.getGame().getDiscardPile().add(logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard()));
logic.getGame().getDiscardPile().add(msg.getCard());
} }
protected void throwPiece(Piece piece){ protected void throwPiece(Piece piece){

View File

@@ -31,7 +31,7 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
state = powerCardState; this.setState(this.powerCardState);
} }
@Override @Override
@@ -40,7 +40,9 @@ public void exit() {
} }
public void setState(TurnStates state){ public void setState(TurnStates state){
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }

View File

@@ -6,6 +6,7 @@
import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.DieMessage; import pp.mdga.message.server.DieMessage;
import pp.mdga.notification.DiceNowNotification; import pp.mdga.notification.DiceNowNotification;
import pp.mdga.notification.RollDiceNotification;
public class RollRankingDiceState extends DetermineStartPlayerStates { public class RollRankingDiceState extends DetermineStartPlayerStates {
@@ -23,16 +24,17 @@ public void enter() {
@Override @Override
public void exit() { public void exit() {
} }
@Override @Override
public void selectDice(){ public void selectDice(){
System.out.println("selectDice");
logic.send(new RequestDieMessage()); logic.send(new RequestDieMessage());
} }
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg){
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
parent.setState(parent.getWaitRanking()); parent.setState(parent.getWaitRanking());
} }
} }

View File

@@ -24,7 +24,7 @@ public ChoosePieceState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
currentState = noPieceState; this.setState(this.noPieceState);
} }
@Override @Override
@@ -34,9 +34,11 @@ public void exit() {
} }
public void setState(ChoosePieceStates state){ public void setState(ChoosePieceStates state){
if(currentState != null){
currentState.exit(); currentState.exit();
}
state.enter();
currentState = state; currentState = state;
currentState.enter();
} }
@Override @Override

View File

@@ -31,7 +31,7 @@ public PowerCardState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
state = choosePowerCardState; this.setState(this.choosePowerCardState);
} }
public void exit() { public void exit() {
@@ -40,7 +40,9 @@ public void exit() {
} }
public void setState(PowerCardStates state) { public void setState(PowerCardStates state) {
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }

View File

@@ -29,7 +29,7 @@ public Board() {
} else if (i == 4 || i == 14 || i == 24 || i == 34) { } else if (i == 4 || i == 14 || i == 24 || i == 34) {
infield[i] = new BonusNode(); infield[i] = new BonusNode();
} else { } else {
infield[i] = new Node(); infield[i] = new Node(null);
} }
} }
} }

View File

@@ -8,6 +8,6 @@
@Serializable @Serializable
public class BonusNode extends Node { public class BonusNode extends Node {
BonusNode(){ BonusNode(){
super(); super(null);
} }
} }

View File

@@ -1,9 +1,12 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* This enumeration will be used to show the four different TSK which can be picked from a player. * This enumeration will be used to show the four different TSK which can be picked from a player.
* In Addition, the NONE color will be used to show a none color. * In Addition, the NONE color will be used to show a none color.
*/ */
@Serializable
public enum Color { public enum Color {
/** /**
* Represents the air force color. * Represents the air force color.

View File

@@ -1,7 +1,11 @@
package pp.mdga.game; package pp.mdga.game;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.random.RandomGenerator; import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory; import java.util.random.RandomGeneratorFactory;
import java.util.stream.IntStream;
/** /**
* This class represents a simple die with the possibilities to shuffle and return the roll result. * This class represents a simple die with the possibilities to shuffle and return the roll result.
@@ -43,6 +47,14 @@ public class Die {
*/ */
private int lastNumberOfDice; private int lastNumberOfDice;
/**
* Predefined rolls for testing.
*/
private Iterator<Integer> rolls;
/**
* If the results of the die should be locked.
*/
private final boolean lock; private final boolean lock;
/** /**
@@ -74,6 +86,17 @@ public Die(int roll) {
this.lock = true; this.lock = true;
} }
/**
* Constructor.
*
* @param rolls as a variable list of rolls which will be used by test cases as an Array of Integers.
*/
public Die(int... rolls) {
this.random = RandomGeneratorFactory.of("Random").create();
this.rolls = IntStream.of(rolls).iterator();
this.lock = false;
}
/** /**
* This method will be used to return a random number generated by the random attribute of Die class. * This method will be used to return a random number generated by the random attribute of Die class.
* *
@@ -84,6 +107,11 @@ public int shuffle() {
return this.lastNumberOfDice; return this.lastNumberOfDice;
} }
if (this.rolls != null && this.rolls.hasNext()) {
this.lastNumberOfDice = this.rolls.next();
return this.lastNumberOfDice;
}
this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1; this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1;
return this.lastNumberOfDice; return this.lastNumberOfDice;

View File

@@ -43,14 +43,11 @@ public class Game {
private Die die; private Die die;
// The host of this game // The host of this game
private int host; private int host = -1;
// The color of the active player. // The color of the active player.
private Color activeColor; private Color activeColor;
// A flag indicating whether all players are ready.
private boolean allReady = false;
/** /**
* This constructor creates a new Game object. * This constructor creates a new Game object.
*/ */
@@ -65,6 +62,7 @@ public Game() {
drawPile.add(BonusCard.SHIELD); drawPile.add(BonusCard.SHIELD);
} }
board = new Board(); board = new Board();
die = new Die();
} }
/** /**
@@ -96,6 +94,38 @@ public void updatePlayerActiveState(int id, boolean active) {
this.players.get(id).setActive(active); this.players.get(id).setActive(active);
} }
/**
* This method will be used to check if the given color parameter is already taken.
* If yes it will return true, otherwise false.
*
* @param color as the color which should be checked if taken as a Color enumeration.
* @return true or false.
*/
public boolean isColorTaken(Color color) {
for (Map.Entry<Integer, Player> entry : this.players.entrySet()) {
if (entry.getValue().getColor() == color) {
return true;
}
}
return false;
}
/**
* This method will be used to return the first unused color if possible.
*
* @return color as a Color enumeration.
*/
public Color getFirstUnusedColor() {
for (Color color : Color.values()) {
if (!isColorTaken(color)) {
return color;
}
}
return null;
}
/** /**
* This method will be used to return the player which has the given id parameter. * This method will be used to return the player which has the given id parameter.
* *
@@ -122,6 +152,32 @@ public Player getPlayerByColor(Color color) {
return null; return null;
} }
/**
* This method will be used to return the id of the active player depending on the activeColor attribute of Game
* class.
*
* @return the id of the active player as an Integer.
*/
public int getActivePlayerId() {
return this.getPlayerIdByColor(this.activeColor);
}
/**
* This method will be used to return the id of the Player defined by the given color parameter.
*
* @param color as the color of the player as a Color enumeration.
* @return the id of the player as an Integer.
*/
public int getPlayerIdByColor(Color color) {
for (Map.Entry<Integer, Player> entry : this.players.entrySet()) {
if (entry.getValue().getColor() == color) {
return entry.getKey();
}
}
return -1;
}
/** /**
* This method will be used to return the number of active players of this game. * This method will be used to return the number of active players of this game.
* *
@@ -138,6 +194,22 @@ public int getNumberOfActivePlayers() {
return activePlayers; return activePlayers;
} }
/**
* This method will be used to check if all players are ready.
* If yes it will return true, otherwise false.
*
* @return true or false.
*/
public boolean areAllReady() {
for (Map.Entry<Integer, Player> entry : this.players.entrySet()) {
if (!entry.getValue().isReady()) {
return false;
}
}
return true;
}
/** /**
* This method will be used to return a piece based on the UUID. * This method will be used to return a piece based on the UUID.
* *
@@ -154,6 +226,15 @@ public Piece getPieceThroughUUID(UUID pieceId) {
return null; return null;
} }
/**
* This method will be used to check if this client is the host for the game.
*
* @return true or false.
*/
public boolean isHost() {
return this.host != -1;
}
/** /**
* This method returns the dice modifier. * This method returns the dice modifier.
* *
@@ -333,22 +414,4 @@ public void setDie(Die die) {
public void setHost(int host) { public void setHost(int host) {
this.host = host; this.host = host;
} }
/**
* This method returns the all ready state.
*
* @return the already state
*/
public Boolean allReady() {
return allReady;
}
/**
* This method sets the all ready state.
*
* @param allReady the new all-ready state
*/
public void setAllReady(Boolean allReady) {
this.allReady = allReady;
}
} }

View File

@@ -8,6 +8,6 @@
@Serializable @Serializable
public class HomeNode extends Node { public class HomeNode extends Node {
public HomeNode() { public HomeNode() {
super(); super(null);
} }
} }

View File

@@ -9,8 +9,12 @@
public class Node { public class Node {
protected Piece occupant; protected Piece occupant;
public Node(){ public Node(Piece piece){
occupant = piece;
}
private Node(){
occupant = new Piece(Color.AIRFORCE, PieceState.WAITING);
} }
/** /**
@@ -49,4 +53,14 @@ public void clearOccupant() {
public boolean isOccupied() { public boolean isOccupied() {
return occupant != null; return occupant != null;
} }
/**
* This method will be used to check if the node is occupied by a piece of the given color.
*
* @param color as the color of the piece as a Color object.
* @return true or false.
*/
public boolean isOccupied(Color color) {
return this.occupant != null && this.occupant.getColor() == color;
}
} }

View File

@@ -12,17 +12,17 @@ public class Piece {
/** /**
* The shield state of the piece. * The shield state of the piece.
*/ */
private int shield; private ShieldState shield;
/** /**
* The current state of the piece. * The current state of the piece.
*/ */
private int state; private PieceState state;
/** /**
* The color of the piece. * The color of the piece.
*/ */
private final int color; private final Color color;
/** /**
* The unique identifier of the piece. * The unique identifier of the piece.
@@ -35,16 +35,19 @@ public class Piece {
* @param color the color of the piece * @param color the color of the piece
* @param state the state of the piece * @param state the state of the piece
*/ */
public Piece(Color color, PieceState state, int id) { public Piece(Color color, PieceState state) {
this.color = color.ordinal(); this.color = color;
this.state = state.ordinal(); this.state = state;
shield = ShieldState.NONE.ordinal(); shield = ShieldState.NONE;
} }
/**
* Constructor.
*/
private Piece() { private Piece() {
color = Color.NONE.ordinal(); color = Color.NONE;
state = PieceState.WAITING.ordinal(); state = PieceState.WAITING;
shield = ShieldState.NONE.ordinal(); shield = ShieldState.NONE;
} }
/** /**
@@ -53,7 +56,7 @@ private Piece() {
* @return the color of the piece * @return the color of the piece
*/ */
public void setShield(ShieldState shield) { public void setShield(ShieldState shield) {
this.shield = shield.ordinal(); this.shield = shield;
} }
/** /**
@@ -62,7 +65,7 @@ public void setShield(ShieldState shield) {
* @return the color of the piece * @return the color of the piece
*/ */
public ShieldState getShield() { public ShieldState getShield() {
return ShieldState.values()[shield]; return shield;
} }
/** /**
@@ -71,7 +74,7 @@ public ShieldState getShield() {
* @param state the state of the piece * @param state the state of the piece
*/ */
public void setState(PieceState state) { public void setState(PieceState state) {
this.state = state.ordinal(); this.state = state;
} }
/** /**
@@ -80,7 +83,7 @@ public void setState(PieceState state) {
* @return the color of the piece * @return the color of the piece
*/ */
public PieceState getState() { public PieceState getState() {
return PieceState.values()[state]; return state;
} }
/** /**
@@ -89,7 +92,7 @@ public PieceState getState() {
* @return the color of the piece * @return the color of the piece
*/ */
public boolean isShielded() { public boolean isShielded() {
return shield == ShieldState.ACTIVE.ordinal(); return shield == ShieldState.ACTIVE;
} }
/** /**
@@ -98,7 +101,7 @@ public boolean isShielded() {
* @return the color of the piece * @return the color of the piece
*/ */
public boolean isSuppressed() { public boolean isSuppressed() {
return shield == ShieldState.SUPPRESSED.ordinal(); return shield == ShieldState.SUPPRESSED;
} }
/** /**
@@ -107,7 +110,7 @@ public boolean isSuppressed() {
* @return the color of the piece * @return the color of the piece
*/ */
public Color getColor() { public Color getColor() {
return Color.values()[color]; return color;
} }
/** /**

View File

@@ -5,6 +5,7 @@
/** /**
* Represents the state of a piece. * Represents the state of a piece.
*/ */
@Serializable
public enum PieceState { public enum PieceState {
/** /**
* The piece is active. * The piece is active.
@@ -22,20 +23,4 @@ public enum PieceState {
* The piece is finished. * The piece is finished.
*/ */
HOMEFINISHED; HOMEFINISHED;
PieceState(){
}
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];
}
} }

View File

@@ -1,6 +1,7 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.mdga.Resources;
import java.util.ArrayList; import java.util.ArrayList;
@@ -17,12 +18,12 @@ public class Player {
/** /**
* The statistics of the player. * The statistics of the player.
*/ */
private Statistic playerStatistic; private Statistic playerStatistic = new Statistic();
/** /**
* The hand cards of the player. * The hand cards of the player.
*/ */
private ArrayList<BonusCard> handCards; private ArrayList<BonusCard> handCards = new ArrayList<>();
/** /**
* The color of the player. * The color of the player.
@@ -32,13 +33,21 @@ public class Player {
/** /**
* Indicates if the player is ready. * Indicates if the player is ready.
*/ */
private boolean isReady; private boolean ready = false;
/** /**
* Indicates if the player is active. * Indicates if the player is active.
*/ */
private boolean active = true; private boolean active = true;
/**
* Node and piece attributes
*/
private int startNodeIndex = -1;
private HomeNode[] homeNodes = new HomeNode[Resources.MAX_PIECES];
private Piece[] waitingArea = new Piece[Resources.MAX_PIECES];
private Piece[] pieces = new Piece[Resources.MAX_PIECES];
/** /**
* This constructor constructs a new Player object * This constructor constructs a new Player object
* *
@@ -46,8 +55,6 @@ public class Player {
*/ */
public Player(String name) { public Player(String name) {
this.name = name; this.name = name;
playerStatistic = new Statistic();
handCards = new ArrayList<>();
} }
/** /**
@@ -58,39 +65,14 @@ public Player() {
} }
/** /**
* This method returns the give name of the Player * This method will be used to initialize all nodes and pieces of the Player class.
*
* @return the name of the player as a String
*/ */
public String getName() { public void initialize() {
return name; for (int index = 0; index < Resources.MAX_PIECES; index++) {
this.homeNodes[index] = new HomeNode();
this.pieces[index] = new Piece(this.color, PieceState.WAITING);
this.waitingArea[index] = this.pieces[index];
} }
/**
* This method sets the name of the player
*
* @param name the new name of the player
*/
public void setName(String name) {
this.name = name;
}
/**
* This methode returns the statistics of the player
*
* @return the statistics of the player
*/
public Statistic getPlayerStatistic() {
return playerStatistic;
}
/**
* This method returns the current handCards of the player
*
* @return the handCards of the player
*/
public ArrayList<BonusCard> getHandCards() {
return handCards;
} }
/** /**
@@ -116,6 +98,58 @@ public BonusCard removeHandCard(BonusCard card) {
return cardToRemove; return cardToRemove;
} }
/**
* This method will be used to add the given piece parameter to the first free slot inside the waitingArea attribute
* of Player class.
*
* @param piece as the piece which should be added to the waitingArea attribute of Player class as a Piece object.
*/
public void addWaitingPiece(Piece piece) {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (this.waitingArea[i] == null) {
this.waitingArea[i] = piece;
return;
}
}
}
/**
* This method will be used to check if the player is finished.
* ToDo: Currently return always false. Implement logic!
*
* @return true or false.
*/
public boolean isFinished() {
return false;
}
/**
* This method returns the give name of the Player
*
* @return the name of the player as a String
*/
public String getName() {
return name;
}
/**
* This methode returns the statistics of the player
*
* @return the statistics of the player
*/
public Statistic getPlayerStatistic() {
return playerStatistic;
}
/**
* This method returns the current handCards of the player
*
* @return the handCards of the player
*/
public ArrayList<BonusCard> getHandCards() {
return handCards;
}
/** /**
* This method returns the color of the player * This method returns the color of the player
* *
@@ -125,22 +159,13 @@ public Color getColor() {
return color; return color;
} }
/**
* This method sets the color of the player
*
* @param color the new color of the player
*/
public void setColor(Color color) {
this.color = color;
}
/** /**
* This method returns if the player is ready * This method returns if the player is ready
* *
* @return true if the player is ready, false otherwise * @return true if the player is ready, false otherwise
*/ */
public boolean isReady() { public boolean isReady() {
return isReady; return ready;
} }
/** /**
@@ -152,13 +177,67 @@ public boolean isActive() {
return this.active; return this.active;
} }
/**
* This method will be used to return startNodeIndex of Player class.
*
* @return startNodeIndex as an Integer.
*/
public int getStartNodeIndex() {
return this.startNodeIndex;
}
/**
* This method will be used to return homeNodes attribute of Player class.
*
* @return homeNodes as an Array of Node objects.
*/
public Node[] getHomeNodes() {
return this.homeNodes;
}
/**
* This method will be used to return waitingArea attribute of Player class.
*
* @return waitingArea as an Array of Piece objects.
*/
public Piece[] getWaitingArea() {
return this.waitingArea;
}
/**
* This method will be used to return pieces attribute of Player class.
*
* @return pieces as an Array of Piece objects.
*/
public Piece[] getPieces() {
return this.pieces;
}
/**
* This method sets the name of the player
*
* @param name the new name of the player
*/
public void setName(String name) {
this.name = name;
}
/**
* This method sets the color of the player
*
* @param color the new color of the player
*/
public void setColor(Color color) {
this.color = color;
}
/** /**
* This method sets the player to ready * This method sets the player to ready
* *
* @param ready true if the player is ready, false otherwise * @param ready true if the player is ready, false otherwise
*/ */
public void setReady(boolean ready) { public void setReady(boolean ready) {
isReady = ready; this.ready = ready;
} }
/** /**

View File

@@ -1,6 +1,7 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.mdga.Resources;
/** /**
* This class is used to represent PlayerData related to the board * This class is used to represent PlayerData related to the board
@@ -33,20 +34,33 @@ public class PlayerData {
* @param color the color of the player * @param color the color of the player
*/ */
public PlayerData(Color color) { public PlayerData(Color color) {
homeNodes = new HomeNode[4]; homeNodes = new HomeNode[Resources.MAX_PIECES];
pieces = new Piece[4]; pieces = new Piece[Resources.MAX_PIECES];
waitingArea = new Piece[4]; waitingArea = new Piece[Resources.MAX_PIECES];
for (int i = 0; i < 4; i++) { for (int i = 0; i < Resources.MAX_PIECES; i++) {
homeNodes[i] = new HomeNode(); homeNodes[i] = new HomeNode();
pieces[i] = new Piece(color, PieceState.WAITING, i); pieces[i] = new Piece(color, PieceState.WAITING);
waitingArea[i] = pieces[i]; waitingArea[i] = pieces[i];
} }
} }
/**
* Constructor.
*/
private PlayerData() { private PlayerData() {
homeNodes = null; homeNodes = new HomeNode[Resources.MAX_PIECES];
waitingArea = null; waitingArea = new Piece[Resources.MAX_PIECES];
pieces = null; pieces = new Piece[Resources.MAX_PIECES];
}
/**
* This method will be used to check if the player is finished.
* ToDo: Currently return always false. Implement logic!
*
* @return true or false.
*/
public boolean isFinished() {
return false;
} }
/** /**
@@ -100,7 +114,7 @@ public Piece[] getPieces() {
* @param piece the piece to be added to the waiting area * @param piece the piece to be added to the waiting area
*/ */
public void addWaitingPiece(Piece piece) { public void addWaitingPiece(Piece piece) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (waitingArea[i] == null) { if (waitingArea[i] == null) {
waitingArea[i] = piece; waitingArea[i] = piece;
return; return;
@@ -114,7 +128,7 @@ public void addWaitingPiece(Piece piece) {
* @return the piece that was removed from the waiting area * @return the piece that was removed from the waiting area
*/ */
public Piece removePieceFromWaitingArea() { public Piece removePieceFromWaitingArea() {
for (int i = 0; i < 4; i++) { for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (waitingArea[i] != null) { if (waitingArea[i] != null) {
Piece piece = waitingArea[i]; Piece piece = waitingArea[i];
waitingArea[i] = null; waitingArea[i] = null;
@@ -135,26 +149,30 @@ public void setPieceInHome(int index, Piece piece) {
} }
/** /**
* This method returns the homeNodes * This method will be used to return if the given piece parameter is inside the homNodes attribute of PlayerData
* class.
* If yes it will return true, otherwise false.
* *
* @return the homeNodes * @return true or false.
*/ */
public boolean homeIncludes(Piece piece) { public boolean homeIncludes(Piece piece) {
for (int i = 0; i < 4; i++) { for (Node node : this.homeNodes) {
if (homeNodes[i].getOccupant() == piece) { if (node.getOccupant() == piece) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* This method returns the homeNodes * This method will be used to return the index of the given piece parameter in the homeNodes attribute of
* PlayerData class.
* *
* @return the homeNodes * @return index as an Integer.
*/ */
public int getIndexInHome(Piece piece) { public int getIndexInHome(Piece piece) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (homeNodes[i].getOccupant() == piece) { if (homeNodes[i].getOccupant() == piece) {
return i; return i;
} }
@@ -163,9 +181,10 @@ public int getIndexInHome(Piece piece) {
} }
/** /**
* This method returns the homeNodes * This method will be usd to check if the waitingArea attribute of PlayerData class is empty.
* If yes it will return false, otherwise true.
* *
* @return the homeNodes * @return true or false.
*/ */
public boolean hasPieceInWaitingArea() { public boolean hasPieceInWaitingArea() {
for (Piece piece : waitingArea) { for (Piece piece : waitingArea) {

View File

@@ -1,11 +1,8 @@
package pp.mdga.game; package pp.mdga.game;
import com.jme3.network.serializing.Serializable;
/** /**
* Represents the state of a piece's shield. * Represents the state of a piece's shield.
*/ */
@Serializable
public enum ShieldState { public enum ShieldState {
/** /**
* The shield is not active. * The shield is not active.
@@ -19,19 +16,4 @@ public enum ShieldState {
* The shield is suppressed, when the piece is on a start node. * The shield is suppressed, when the piece is on a start node.
*/ */
SUPPRESSED; SUPPRESSED;
ShieldState(){
}
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];
}
} }

View File

@@ -10,7 +10,7 @@ public class StartNode extends Node {
/** /**
* The color of the node. * The color of the node.
*/ */
private int color; private Color color;
/** /**
* Creates a new start node with the given color. * Creates a new start node with the given color.
@@ -18,11 +18,13 @@ public class StartNode extends Node {
* @param color the color of the node * @param color the color of the node
*/ */
public StartNode(Color color) { public StartNode(Color color) {
this.color = color.ordinal(); super(null);
this.color = color;
} }
private StartNode() { private StartNode() {
color = Color.NONE.ordinal(); super(null);
color = Color.NONE;
} }
/** /**
@@ -31,7 +33,7 @@ private StartNode() {
* @return the color of the node * @return the color of the node
*/ */
public Color getColor() { public Color getColor() {
return Color.values()[color]; return color;
} }
/** /**
@@ -40,6 +42,6 @@ public Color getColor() {
* @param color the new color of the node * @param color the new color of the node
*/ */
public void setColor(Color color) { public void setColor(Color color) {
this.color = color.ordinal(); this.color = color;
} }
} }

View File

@@ -0,0 +1,58 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class IncorrectRequestMessage extends ServerMessage {
/**
* Create IncorrectRequestMessage attributes.
*/
private final int id;
/**
* Constructor.
*
* @param id as the id of the error message as an Integer.
*/
public IncorrectRequestMessage(int id) {
this.id = id;
}
/**
* Constructor.
*/
public IncorrectRequestMessage() {
this.id = 0;
}
/**
* 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 "";
}
/**
* This method will be used to return necessary class information in a more readable format.
*
* @return information as a String.
*/
@Override
public String toString() {
return "IncorrectRequestMessage with id: %d".formatted(this.id);
}
}

View File

@@ -7,13 +7,39 @@
*/ */
@Serializable @Serializable
public class LobbyAcceptMessage extends ServerMessage { public class LobbyAcceptMessage extends ServerMessage {
/**
* Create LobbyAcceptMessage attributes.
*/
private final int host;
/** /**
* Constructs a new LobbyAccept instance. * Constructs a new LobbyAccept instance.
*/ */
public LobbyAcceptMessage() { public LobbyAcceptMessage() {
super(); super();
this.host = -1;
} }
/**
* Constructor.
*
* @param host as the id of the host as an Integer.
*/
public LobbyAcceptMessage(int host) {
super();
this.host = host;
}
/**
* This method will be used return host attribute of LobbyAcceptMessage class.
*
* @return host as an Integer.
*/
public int getHost() {
return this.host;
}
/** /**
* Accepts a visitor to process this message. * Accepts a visitor to process this message.
* *
@@ -31,7 +57,7 @@ public void accept(ServerInterpreter interpreter) {
*/ */
@Override @Override
public String toString() { public String toString() {
return ""; return "Lobby Accept";
} }
/** /**

View File

@@ -31,7 +31,7 @@ public void accept(ServerInterpreter interpreter) {
*/ */
@Override @Override
public String toString() { public String toString() {
return ""; return "LobbyDeny";
} }
/** /**

View File

@@ -1,40 +0,0 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Color;
import pp.mdga.game.PlayerData;
@Serializable
public class PlayerDataMessage extends ServerMessage{
private final PlayerData playerData;
private final Color color;
public PlayerDataMessage(PlayerData playerData, Color color){
super();
this.playerData = playerData;
this.color = color;
}
private PlayerDataMessage(){
this(null, null);
}
@Override
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
return "";
}
public PlayerData getPlayerData(){
return playerData;
}
public Color getColor(){
return color;
}
}

View File

@@ -211,11 +211,14 @@ public interface ServerInterpreter {
/** /**
* Handles a SelectTSK message received from the server. * Handles a SelectTSK message received from the server.
* *
* @param shutdownMessage the SelectTSK message received. * @param msg the SelectTSK message received.
*/ */
void received(ShutdownMessage shutdownMessage); void received(ShutdownMessage msg);
void received(StartBriefingMessage msg); /**
* Handles a IncorrectRequest message received from the server.
void received(PlayerDataMessage msg); *
* @param msg the IncorrectRequest message received.
*/
void received(IncorrectRequestMessage msg);
} }

View File

@@ -8,13 +8,38 @@
*/ */
@Serializable @Serializable
public class ServerStartGameMessage extends ServerMessage { public class ServerStartGameMessage extends ServerMessage {
/**
* Create ServerStartGameMessage attributes.
*/
private final Board board;
/** /**
* Constructs a new ServerStartGame instance. * Constructs a new ServerStartGame instance.
*/ */
public ServerStartGameMessage() { public ServerStartGameMessage() {
super(); super();
this.board = new Board();
} }
/**
* Constructor.
*
* @param board as the board of the game as a Board object.
*/
public ServerStartGameMessage(Board board) {
super();
this.board = board;
}
/**
* This method will return board attribute of ServerStartGameMessage class.
*
* @return board as a Board object.
*/
public Board getBoard() {
return this.board;
}
/** /**
* Accepts a visitor to process this message. * Accepts a visitor to process this message.
* *

View File

@@ -1,33 +0,0 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Board;
@Serializable
public class StartBriefingMessage extends ServerMessage {
private final Board board;
public StartBriefingMessage(Board board) {
super();
this.board = board;
}
private StartBriefingMessage() {
this(null);
}
public Board getBoard() {
return this.board;
}
@Override
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
return "";
}
}

View File

@@ -0,0 +1,33 @@
package pp.mdga.notification;
import pp.mdga.game.BonusCard;
/**
* Notification that is to give information to the player.
*/
public class InfoNotification extends Notification{
private final String message;
private boolean isError = false;
/**
* Constructor.
*/
public InfoNotification(String info) {
this.message = info;
}
/**
* Constructor.
*/
public InfoNotification(String info, boolean isError) {
this.message = info;
this.isError = isError;
}
public String getMessage() {
return message;
}
public boolean isError() { return isError; }
}

View File

@@ -11,6 +11,7 @@ public class RollDiceNotification extends Notification{
private int eyes; private int eyes;
private boolean turbo; private boolean turbo;
private int multiplier; private int multiplier;
private boolean isRanking;
/** /**
* Constructor. * Constructor.
@@ -22,6 +23,15 @@ public RollDiceNotification(Color color, int eyes) {
this.eyes = eyes; this.eyes = eyes;
this.turbo = false; this.turbo = false;
this.multiplier = -1; this.multiplier = -1;
this.isRanking = false;
}
public RollDiceNotification(Color color, int eyes, boolean isRanking) {
this.color = color;
this.eyes = eyes;
this.turbo = false;
this.multiplier = -1;
this.isRanking = isRanking;
} }
public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier) { public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier) {
@@ -29,6 +39,7 @@ public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier
this.eyes = eyes; this.eyes = eyes;
this.turbo = turbo; this.turbo = turbo;
this.multiplier = multiplier; this.multiplier = multiplier;
this.isRanking = false;
} }
/** /**
@@ -54,4 +65,6 @@ public int getMultiplier() {
public boolean isTurbo() { public boolean isTurbo() {
return turbo; return turbo;
} }
public boolean isRanking() { return isRanking; }
} }

View File

@@ -28,4 +28,9 @@ public interface ServerSender {
* @param id as the connection id of the client as an Integer. * @param id as the connection id of the client as an Integer.
*/ */
void disconnectClient(int id); void disconnectClient(int id);
/**
* This method will be used to shut down the server.
*/
void shutdown();
} }

View File

@@ -4,6 +4,7 @@
import pp.mdga.message.client.DisconnectedMessage; import pp.mdga.message.client.DisconnectedMessage;
import pp.mdga.message.client.LeaveGameMessage; import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.message.server.PauseGameMessage; import pp.mdga.message.server.PauseGameMessage;
import pp.mdga.server.automaton.game.AnimationState; import pp.mdga.server.automaton.game.AnimationState;
import pp.mdga.server.automaton.game.DetermineStartPlayerState; import pp.mdga.server.automaton.game.DetermineStartPlayerState;
@@ -82,6 +83,7 @@ public void received(DisconnectedMessage msg, int from) {
public void received(LeaveGameMessage msg, int from) { public void received(LeaveGameMessage msg, int from) {
this.logic.getGame().updatePlayerActiveState(from, false); this.logic.getGame().updatePlayerActiveState(from, false);
if (this.logic.getGame().getNumberOfActivePlayers() == 1) { if (this.logic.getGame().getNumberOfActivePlayers() == 1) {
this.logic.getServerSender().broadcast(new CeremonyMessage());
this.logic.setCurrentState(this.logic.getCeremonyState()); this.logic.setCurrentState(this.logic.getCeremonyState());
} }
} }

View File

@@ -7,7 +7,6 @@
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
/** /**
@@ -49,7 +48,7 @@ public void exit() {
* This method will be used to initialize the game and all necessary objects. * This method will be used to initialize the game and all necessary objects.
*/ */
public void initializeGame() { public void initializeGame() {
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) { 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.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
} }
} }
@@ -80,18 +79,13 @@ public void received(JoinedLobbyMessage msg, int from) {
*/ */
@Override @Override
public void received(SelectTSKMessage msg, int from) { public void received(SelectTSKMessage msg, int from) {
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) { if (msg.getColor() != Color.NONE && !this.logic.getGame().isColorTaken(msg.getColor())) {
if (entry.getValue().getColor() == msg.getColor()) { this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE, false));
return;
}
}
if(this.logic.getGame().getPlayerById(from).getColor() != Color.NONE) {
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, this.logic.getGame().getPlayerById(from).getColor(), false));
}
this.logic.getGame().getPlayerById(from).setColor(msg.getColor()); this.logic.getGame().getPlayerById(from).setColor(msg.getColor());
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor(), true)); this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor(), true));
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(0));
}
} }
/** /**
@@ -116,44 +110,22 @@ public void received(DeselectTSKMessage msg, int from) {
*/ */
@Override @Override
public void received(LobbyReadyMessage msg, int from) { public void received(LobbyReadyMessage msg, int from) {
//assign a free color if (this.logic.getGame().getPlayerById(from).getColor() == Color.NONE) {
if(this.logic.getGame().getPlayerById(from).getColor() == Color.NONE) { Color color = this.logic.getGame().getFirstUnusedColor();
ArrayList<Color> colors = new ArrayList<>();
colors.add(Color.ARMY);
colors.add(Color.AIRFORCE);
colors.add(Color.NAVY);
colors.add(Color.CYBER);
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) { if (color != null) {
if(colors.contains(entry.getValue().getColor())) { this.logic.getGame().getPlayerById(from).setColor(color);
colors.remove(entry.getValue().getColor()); this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, color, true));
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(1));
} }
} }
if(colors.size() < 1) {
throw new RuntimeException("can not assign a color");
}
this.logic.getGame().getPlayerById(from).setColor(colors.get(0));
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, colors.get(0), true));
}
this.logic.getGame().getPlayerById(from).setReady(true); this.logic.getGame().getPlayerById(from).setReady(true);
this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, true)); this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, true));
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) { if (this.logic.getGame().areAllReady()) {
if (!entry.getValue().isReady()) {
return;
}
}
this.logic.getGame().setAllReady(true);
if (this.logic.getGame().allReady()) {
this.logic.getServerSender().broadcast(new StartBriefingMessage(this.logic.getGame().getBoard()));
this.initializeGame(); this.initializeGame();
for (Map.Entry<Color, PlayerData> entry : logic.getGame().getBoard().getPlayerData().entrySet()) { this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
this.logic.getServerSender().broadcast(new PlayerDataMessage(entry.getValue(), entry.getKey())); this.logic.setCurrentState(this.logic.getGameState());
}
this.logic.getServerSender().broadcast(new ServerStartGameMessage());
} }
} }
@@ -167,27 +139,9 @@ public void received(LobbyReadyMessage msg, int from) {
@Override @Override
public void received(LobbyNotReadyMessage msg, int from) { public void received(LobbyNotReadyMessage msg, int from) {
this.logic.getGame().getPlayerById(from).setReady(false); this.logic.getGame().getPlayerById(from).setReady(false);
this.logic.getGame().setAllReady(false);
this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, false)); this.logic.getServerSender().broadcast(new UpdateReadyMessage(from, false));
} }
/**
* This method will be called whenever the server received an LeaveGameMessage message.
* It will also get the client id of the player who send this message.
*
* @param msg as the message which was sent by the player as a LeaveGameMessage object.
* @param from as the client id of the player as an Integer.
*/
@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);
}
/** /**
* This method will be called whenever the server received a StartGame message. * This method will be called whenever the server received a StartGame message.
* It will also get the client id of the player who send this message. * It will also get the client id of the player who send this message.
@@ -197,9 +151,9 @@ public void received(LeaveGameMessage msg, int from) {
*/ */
@Override @Override
public void received(StartGameMessage msg, int from) { public void received(StartGameMessage msg, int from) {
if (msg.isForceStartGame() || this.logic.getGame().allReady()) { if (msg.isForceStartGame() || this.logic.getGame().areAllReady()) {
this.initializeGame(); this.initializeGame();
this.logic.getServerSender().broadcast(new ServerStartGameMessage()); this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
this.logic.setCurrentState(this.logic.getGameState()); this.logic.setCurrentState(this.logic.getGameState());
} }
} }

View File

@@ -1,6 +1,8 @@
package pp.mdga.server.automaton; package pp.mdga.server.automaton;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
import pp.mdga.message.server.ShutdownMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
/** /**
@@ -75,7 +77,15 @@ public void received(JoinedLobbyMessage msg, int from) {}
* @param msg as the message which was sent by the player as a LeaveGameMessage object. * @param msg as the message which was sent by the player as a LeaveGameMessage object.
* @param from as the client id of the player as an Integer. * @param from as the client id of the player as an Integer.
*/ */
public void received(LeaveGameMessage msg, int from) {} public void received(LeaveGameMessage msg, int from) {
if (from == this.logic.getGame().getHost()) {
this.logic.getServerSender().broadcast(new ShutdownMessage());
this.logic.getServerSender().shutdown();
}
this.logic.getGame().removePlayer(from);
this.logic.getServerSender().broadcast(new LobbyPlayerLeaveMessage(from));
this.logic.getServerSender().disconnectClient(from);
}
/** /**
* This method will be called whenever the server received a LobbyReadyMessage message. * This method will be called whenever the server received a LobbyReadyMessage message.

View File

@@ -11,10 +11,15 @@
*/ */
public class AnimationState extends GameAutomatonState { public class AnimationState extends GameAutomatonState {
/** /**
* Create FirstRollState constants. * Create AnimationState constants.
*/ */
private static final System.Logger LOGGER = System.getLogger(AnimationState.class.getName()); private static final System.Logger LOGGER = System.getLogger(AnimationState.class.getName());
/**
* Create AnimationState attributes.
*/
private int messageReceived = 0;
/** /**
* Constructs a server state of the specified game logic. * Constructs a server state of the specified game logic.
* *
@@ -33,6 +38,7 @@ public void enter() {
@Override @Override
public void exit() { public void exit() {
LOGGER.log(System.Logger.Level.DEBUG, "Exited AnimationState state."); LOGGER.log(System.Logger.Level.DEBUG, "Exited AnimationState state.");
this.messageReceived = 0;
} }
/** /**
@@ -44,7 +50,11 @@ public void exit() {
*/ */
@Override @Override
public void received(AnimationEndMessage msg, int from) { public void received(AnimationEndMessage msg, int from) {
this.logic.getServerSender().send(from, new DiceNowMessage()); if (this.messageReceived == this.logic.getGame().getPlayers().size()) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState()); this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
} else {
this.messageReceived++;
}
} }
} }

View File

@@ -3,6 +3,7 @@
import pp.mdga.game.Player; import pp.mdga.game.Player;
import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ActivePlayerMessage; import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage; import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.EndOfTurnMessage; import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -48,6 +49,8 @@ public void enter() {
@Override @Override
public void exit() { public void exit() {
LOGGER.log(System.Logger.Level.DEBUG, "Exited DetermineStartPlayerState state."); LOGGER.log(System.Logger.Level.DEBUG, "Exited DetermineStartPlayerState state.");
this.diceResults.clear();
this.playersHaveToRoll.clear();
} }
/** /**
@@ -60,13 +63,12 @@ public void exit() {
@Override @Override
public void received(RequestDieMessage msg, int from) { public void received(RequestDieMessage msg, int from) {
int roll = this.logic.getGame().getDie().shuffle(); int roll = this.logic.getGame().getDie().shuffle();
this.logic.getServerSender().send(from, new DieMessage(roll));
this.diceResults.put(from, roll); this.diceResults.put(from, roll);
int maximumRoll = 0;
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) { if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
int maximumRoll = 0;
for (Map.Entry<Integer, Integer> entry: this.diceResults.entrySet()) { for (Map.Entry<Integer, Integer> entry: this.diceResults.entrySet()) {
if (maximumRoll == 0) { if (maximumRoll <= entry.getValue()) {
maximumRoll = this.diceResults.get(entry.getKey());
} else if (maximumRoll < entry.getValue()) {
maximumRoll = entry.getValue(); maximumRoll = entry.getValue();
} else { } else {
this.playersHaveToRoll.remove(entry.getKey()); this.playersHaveToRoll.remove(entry.getKey());
@@ -76,10 +78,12 @@ public void received(RequestDieMessage msg, int from) {
if (this.playersHaveToRoll.size() == 1) { if (this.playersHaveToRoll.size() == 1) {
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor())); this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor()));
this.gameAutomaton.setCurrentState(this.gameAutomaton.getAnimationState());
} else { } else {
for (Integer id: this.playersHaveToRoll) { for (Integer id: this.playersHaveToRoll) {
this.logic.getServerSender().send(id, new DieMessage(roll)); this.logic.getServerSender().send(id, new DiceNowMessage());
} }
diceResults.clear();
} }
} }
} }

View File

@@ -23,4 +23,13 @@ public GameAutomatonState(GameState gameAutomaton, ServerGameLogic logic) {
super(logic); super(logic);
this.gameAutomaton = gameAutomaton; this.gameAutomaton = gameAutomaton;
} }
/**
* This method will be used to return gameAutomaton attribute of GameAutomatonState object.
*
* @return gameAutomaton as a GameState object.
*/
public GameState getGameAutomaton() {
return this.gameAutomaton;
}
} }

View File

@@ -36,6 +36,7 @@ public TurnState(GameState gameAutomaton, ServerGameLogic logic) {
this.rollDiceState = new RollDiceState(this, logic); this.rollDiceState = new RollDiceState(this, logic);
this.choosePieceState = new ChoosePieceState(this, logic); this.choosePieceState = new ChoosePieceState(this, logic);
this.movePieceState = new MovePieceState(this, logic); this.movePieceState = new MovePieceState(this, logic);
this.setCurrentState(this.powerCardState);
} }
@Override @Override

View File

@@ -13,11 +13,20 @@ public abstract class TurnAutomatonState extends ServerState {
/** /**
* Constructs a server state of the specified game logic. * Constructs a server state of the specified game logic.
* *
* @param turnAutomaton as the automaton of the turn state as a GameState object. * @param turnAutomaton as the automaton of the turn state as a TurnState object.
* @param logic the game logic * @param logic the game logic
*/ */
public TurnAutomatonState(TurnState turnAutomaton, ServerGameLogic logic) { public TurnAutomatonState(TurnState turnAutomaton, ServerGameLogic logic) {
super(logic); super(logic);
this.turnAutomaton = turnAutomaton; this.turnAutomaton = turnAutomaton;
} }
/**
* This method will be used to return turnAutomaton attribute of TurnAutomatonState object.
*
* @return turnAutomaton as a TurnState object
*/
public TurnState getTurnAutomaton() {
return this.turnAutomaton;
}
} }

View File

@@ -0,0 +1,9 @@
lobby.deny.join=The lobby is already full.
server.shutdown=The server has shut down.
incorrect.request.0=The selected TSK is already occupied.
incorrect.request.1=No TSK is available for selection.

View File

@@ -0,0 +1,5 @@
lobby.deny.join=Die Lobby ist bereits voll.
server.shutdown=Der Server wurde heruntergefahren.
incorrect.request.1=Die ausgewählte TSK ist bereits belegt.
incorrect.request.2=Es gibt keine freie TSK mehr, welche ausgewählt werden kann.