mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-10-19 19:07:47 +02:00
Compare commits
44 Commits
Testhandbu
...
559afcaffd
Author | SHA1 | Date | |
---|---|---|---|
|
559afcaffd | ||
|
15f5f91ddb | ||
|
067a8063a5 | ||
|
35e367ba24 | ||
|
fe68d991fc | ||
|
88dc633e8e | ||
|
0b9cbb0f5f | ||
|
c3a33b4402 | ||
|
e12f00aad6 | ||
|
47bac0185f | ||
|
dafe1dab2a | ||
|
8ba4ea2819 | ||
|
f6f708fd5b | ||
|
1203077aed | ||
|
ddbf79c928 | ||
|
aa47dd579f | ||
|
cdce478d77 | ||
|
f11f4a59f1 | ||
|
d631e8df1e | ||
|
af80d40700 | ||
|
3a6f8a945a | ||
|
bb9727d54a | ||
|
7da8b3e545 | ||
|
b6968df451 | ||
|
aa986fb948 | ||
|
6e63de6e99 | ||
|
962ecd08fa | ||
|
580a26b3ea | ||
|
0cda6b5fa0 | ||
|
cc8c3795b8 | ||
|
3c21165efb | ||
|
818fdf4670 | ||
|
b7d679b492 | ||
|
a42093df23 | ||
|
6157db51da | ||
|
843052989b | ||
|
8e01fa3192 | ||
|
e2126a7ea7 | ||
|
0b46d14650 | ||
|
9e28deedf7 | ||
|
9c0172b413 | ||
|
2933d022aa | ||
|
bdefb7193e | ||
|
69b68a6975 |
18
Projekte/.run/MonopolyApp.run.xml
Normal file
18
Projekte/.run/MonopolyApp.run.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="MonopolyApp" type="Application" factoryName="Application" singleton="false"
|
||||
nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="pp.monopoly.client.MonopolyApp"/>
|
||||
<module name="Projekte.monopoly.client.main"/>
|
||||
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/>
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pp.monopoly.client.*"/>
|
||||
<option name="ENABLED" value="true"/>
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true"/>
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
17
Projekte/.run/MonopolyServer.run.xml
Normal file
17
Projekte/.run/MonopolyServer.run.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="MonopolyServer" type="Application" factoryName="Application"
|
||||
nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="pp.monopoly.server.MonopolyServer"/>
|
||||
<module name="Projekte.monopoly.server.main"/>
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pp.monopoly.server.*"/>
|
||||
<option name="ENABLED" value="true"/>
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true"/>
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
@@ -7,24 +7,23 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import pp.battleship.server.BattleshipServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
|
||||
/**
|
||||
* Represents a dialog for setting up a network connection in the Battleship game.
|
||||
* Allows users to specify the host and port for connecting to a game server.
|
||||
@@ -32,7 +31,7 @@ import static pp.battleship.Resources.lookup;
|
||||
class NetworkDialog extends SimpleDialog {
|
||||
private static final Logger LOGGER = System.getLogger(NetworkDialog.class.getName());
|
||||
private static final String LOCALHOST = "localhost"; //NON-NLS
|
||||
private static final String DEFAULT_PORT = "1234"; //NON-NLS
|
||||
private static final String DEFAULT_PORT = "42069"; //NON-NLS
|
||||
private final NetworkSupport network;
|
||||
private final TextField host = new TextField(LOCALHOST);
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
|
@@ -7,12 +7,11 @@
|
||||
|
||||
package pp.battleship;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import pp.util.config.Config;
|
||||
|
||||
/**
|
||||
* Provides access to the configuration settings for the Battleship game.
|
||||
@@ -31,7 +30,7 @@ public class BattleshipConfig extends Config {
|
||||
* The default port number for the Battleship server.
|
||||
*/
|
||||
@Property("port")
|
||||
private int port = 1234;
|
||||
private int port = 12234;
|
||||
|
||||
/**
|
||||
* The width of the game map in terms of grid units.
|
||||
|
@@ -10,7 +10,7 @@
|
||||
# This file defines the configuration settings for the Battleship server.
|
||||
#
|
||||
# The port number on which the server will listen for incoming connections.
|
||||
port=1234
|
||||
port=42069
|
||||
#
|
||||
# The dimensions of the game map.
|
||||
# 'map.width' defines the number of columns, and 'map.height' defines the number of rows.
|
||||
|
@@ -20,6 +20,8 @@ def sliderBgColor = color(0.5, 0.75, 0.75, 1)
|
||||
def gradientColor = color(0.5, 0.75, 0.85, 0.5)
|
||||
def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1)
|
||||
def solidWhiteBackground = new QuadBackgroundComponent(color(1, 1, 1, 1)) // Solid white
|
||||
def greyBackground = color(0.8, 0.8, 0.8, 1) // Grey background color
|
||||
def redBorderColor = color(1, 0, 0, 1) // Red border color
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +36,7 @@ doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradie
|
||||
generateMips: false)
|
||||
|
||||
def orangeBorder = TbtQuadBackgroundComponent.create(
|
||||
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", // Replace with an appropriate texture if needed
|
||||
texture(name: "/com/simsilica/lemur/icons/border.png", // Replace with an appropriate texture if needed
|
||||
generateMips: false),
|
||||
1, 1, 1, 126, 126,
|
||||
1f, false)
|
||||
@@ -54,6 +56,7 @@ selector("header", "pp") {
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
color = color(1, 0.5, 0, 1)
|
||||
textHAlignment = HAlignment.Center
|
||||
textVAlignment = VAlignment.Center
|
||||
}
|
||||
|
||||
selector("container", "pp") {
|
||||
@@ -144,6 +147,8 @@ selector("title", "pp") {
|
||||
background.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
|
||||
generateMips: false)
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
textHAlignment = HAlignment.Center
|
||||
textVAlignment = VAlignment.Center
|
||||
|
||||
buttonCommands = stdButtonCommands
|
||||
}
|
||||
@@ -158,6 +163,8 @@ selector("button", "pp") {
|
||||
|
||||
// Use insets to create a margin/padding effect for the inner background
|
||||
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
|
||||
textHAlignment = HAlignment.Center
|
||||
textVAlignment = VAlignment.Center
|
||||
buttonCommands = stdButtonCommands
|
||||
}
|
||||
|
||||
@@ -233,4 +240,14 @@ selector("tab.button", "pp") {
|
||||
selector("settings-title", "pp") {
|
||||
fontSize = 48 // Set font size
|
||||
background = new QuadBackgroundComponent(color(0.4157f, 0.4235f, 0.4392f, 1.0f)) // Grey background
|
||||
}
|
||||
textHAlignment = HAlignment.Center
|
||||
textVAlignment = VAlignment.Center
|
||||
}
|
||||
|
||||
selector("menu-button", "pp") {
|
||||
fontSize = 40 // Set font size
|
||||
background = new QuadBackgroundComponent(color(0.4157f, 0.4235f, 0.4392f, 1.0f)) // Grey background
|
||||
textHAlignment = HAlignment.Center
|
||||
textVAlignment = VAlignment.Center
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,12 @@ dependencies {
|
||||
implementation project(":monopoly:model")
|
||||
implementation project(":monopoly:server")
|
||||
|
||||
implementation 'com.simsilica:lemur-proto:1.13.0'
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.lemur
|
||||
implementation libs.lemurproto
|
||||
|
||||
implementation libs.selenium
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
|
@@ -0,0 +1,122 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
import com.jme3.asset.AssetLoadException;
|
||||
import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
/**
|
||||
* Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio.
|
||||
*/
|
||||
public class GameMusic extends AbstractAppState{
|
||||
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||
private static final String ENABLED_PREF = "enabled"; //NON-NLS
|
||||
private static final String VOLUME_PREF = "volume"; //NON-NLS
|
||||
|
||||
private AudioNode music;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return {@code true} if sound is enabled, {@code false} otherwise.
|
||||
*/
|
||||
public static boolean enabledInPreferences() {
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return float to which the volume is set
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the sound effects for the game.
|
||||
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
|
||||
*
|
||||
* @param stateManager The state manager
|
||||
* @param app The application
|
||||
*/
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app) {
|
||||
super.initialize(stateManager, app);
|
||||
music = loadSound(app, "Sound/background.ogg");
|
||||
setVolume(volumeInPreferences());
|
||||
music.setLooping(true);
|
||||
if (isEnabled() && music != null) {
|
||||
music.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a sound from the specified file.
|
||||
*
|
||||
* @param app The application
|
||||
* @param name The name of the sound file.
|
||||
* @return The loaded AudioNode.
|
||||
*/
|
||||
private AudioNode loadSound(Application app, String name) {
|
||||
try {
|
||||
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
||||
sound.setLooping(false);
|
||||
sound.setPositional(false);
|
||||
return sound;
|
||||
}
|
||||
catch (AssetLoadException | AssetNotFoundException ex) {
|
||||
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
*
|
||||
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
|
||||
if (music != null) {
|
||||
if (enabled) {
|
||||
music.play();
|
||||
} else {
|
||||
music.stop();
|
||||
}
|
||||
}
|
||||
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume of music
|
||||
* @param vol the volume to which the music should be set
|
||||
*/
|
||||
public void setVolume(float vol){
|
||||
music.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
}
|
||||
}
|
@@ -31,9 +31,17 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
private static final Preferences PREFERENCES = getPreferences(GameSound.class);
|
||||
private static final String ENABLED_PREF = "enabled"; //NON-NLS
|
||||
|
||||
private AudioNode splashSound;
|
||||
private AudioNode shipDestroyedSound;
|
||||
private AudioNode explosionSound;
|
||||
private AudioNode passStartSound;
|
||||
private AudioNode eventCardSound;
|
||||
private AudioNode gulagSound;
|
||||
private AudioNode diceRollSound;
|
||||
private AudioNode moneyCollectSound;
|
||||
private AudioNode moneyLostSound;
|
||||
private AudioNode tradeAcceptedSound;
|
||||
private AudioNode tradeRejectedSound;
|
||||
private AudioNode winnerSound;
|
||||
private AudioNode looserSound;
|
||||
private AudioNode buttonSound;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
@@ -75,6 +83,17 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app) {
|
||||
super.initialize(stateManager, app);
|
||||
passStartSound = loadSound(app, "Sound/Effects/passStart.ogg");
|
||||
eventCardSound = loadSound(app, "Sound/Effects/eventCard.ogg");
|
||||
gulagSound = loadSound(app, "Sound/Effects/gulag.ogg");
|
||||
diceRollSound = loadSound(app, "Sound/Effects/diceRoll.ogg");
|
||||
moneyCollectSound = loadSound(app, "Sound/Effects/moneyCollect.ogg");
|
||||
moneyLostSound = loadSound(app, "Sound/Effects/moneyLost.ogg");
|
||||
tradeAcceptedSound = loadSound(app, "Sound/Effects/tradeAccepted.ogg");
|
||||
tradeRejectedSound = loadSound(app, "Sound/Effects/tradeRejected.ogg");
|
||||
winnerSound = loadSound(app, "Sound/Effects/winner.ogg");
|
||||
looserSound = loadSound(app, "Sound/Effects/looser.ogg");
|
||||
buttonSound = loadSound(app, "Sound/Effects/button.ogg");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,32 +117,97 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the splash sound effect.
|
||||
* Plays the passStart sound effect.
|
||||
*/
|
||||
public void splash() {
|
||||
if (isEnabled() && splashSound != null)
|
||||
splashSound.playInstance();
|
||||
public void passStart() {
|
||||
if (isEnabled() && passStartSound != null)
|
||||
passStartSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the explosion sound effect.
|
||||
* Plays the eventCard sound effect.
|
||||
*/
|
||||
public void explosion() {
|
||||
if (isEnabled() && explosionSound != null)
|
||||
explosionSound.playInstance();
|
||||
public void eventCard() {
|
||||
if (isEnabled() && eventCardSound != null)
|
||||
eventCardSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays sound effect when a ship has been destroyed.
|
||||
* Plays the gulag sound effect.
|
||||
*/
|
||||
public void shipDestroyed() {
|
||||
if (isEnabled() && shipDestroyedSound != null)
|
||||
shipDestroyedSound.playInstance();
|
||||
public void gulag() {
|
||||
if (isEnabled() && gulagSound != null)
|
||||
gulagSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the diceRoll sound effect.
|
||||
*/
|
||||
public void diceRoll() {
|
||||
if (isEnabled() && diceRollSound != null)
|
||||
diceRollSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the moneyCollect sound effect.
|
||||
*/
|
||||
public void moneyCollect() {
|
||||
if (isEnabled() && moneyCollectSound != null)
|
||||
moneyCollectSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the moneyLost sound effect.
|
||||
*/
|
||||
public void moneyLost() {
|
||||
if (isEnabled() && moneyLostSound != null)
|
||||
moneyLostSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the tradeAccepted sound effect.
|
||||
*/
|
||||
public void tradeAccepted() {
|
||||
if (isEnabled() && tradeAcceptedSound != null)
|
||||
tradeAcceptedSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the tradeRejected sound effect.
|
||||
*/
|
||||
public void tradeRejected() {
|
||||
if (isEnabled() && tradeRejectedSound != null)
|
||||
tradeRejectedSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the winner sound effect.
|
||||
*/
|
||||
public void winner() {
|
||||
if (isEnabled() && winnerSound != null)
|
||||
winnerSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the looser sound effect.
|
||||
*/
|
||||
public void looser() {
|
||||
if (isEnabled() && looserSound != null)
|
||||
looserSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Plays the button sound effect.
|
||||
*/
|
||||
public void button() {
|
||||
if (isEnabled() && buttonSound != null)
|
||||
buttonSound.playInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(SoundEvent event) {
|
||||
switch (event.sound()) {
|
||||
case PASS_START -> passStart();
|
||||
case EVENT_CARD -> eventCard();
|
||||
case GULAG -> eventCard();
|
||||
case DICE_ROLL -> eventCard();
|
||||
case MONEY_COLLECTED -> eventCard();
|
||||
case MONEY_LOST -> eventCard();
|
||||
case TRADE_ACCEPTED -> eventCard();
|
||||
case TRADE_REJECTED -> eventCard();
|
||||
case WINNER -> eventCard();
|
||||
case LOSER -> eventCard();
|
||||
case BUTTON -> eventCard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
|
||||
import pp.dialog.DialogBuilder;
|
||||
@@ -24,8 +23,10 @@ import pp.monopoly.game.client.MonopolyClient;
|
||||
import pp.monopoly.game.client.ServerConnection;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
|
||||
public class MonopolyApp extends SimpleApplication implements MonopolyClient, GameEventListener {
|
||||
|
||||
private BitmapText topText;
|
||||
private final ServerConnection serverConnection;
|
||||
private final ClientGameLogic logic;
|
||||
@@ -38,15 +39,17 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
private TestWorld testWorld;
|
||||
private boolean isSettingsMenuOpen = false;
|
||||
private boolean inputBlocked = false;
|
||||
private MonopolyServer monopolyServer;
|
||||
private NetworkSupport networkSupport;
|
||||
|
||||
/**
|
||||
* Path to the styles script for GUI elements.
|
||||
*/
|
||||
private static final String STYLES_SCRIPT = "Interface/Lemur/pp-styles.groovy"; //NON-NLS
|
||||
private static final String STYLES_SCRIPT = "Interface/Lemur/pp-styles.groovy"; // NON-NLS
|
||||
/**
|
||||
* Path to the font resource used in the GUI.
|
||||
*/
|
||||
private static final String FONT = "Interface/Fonts/Default.fnt"; //NON-NLS
|
||||
|
||||
private static final String FONT = "Interface/Fonts/Default.fnt"; // NON-NLS
|
||||
|
||||
public static void main(String[] args) {
|
||||
new MonopolyApp().start();
|
||||
@@ -55,7 +58,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
public MonopolyApp() {
|
||||
this.draw = new Draw(assetManager);
|
||||
config = new MonopolyAppConfig();
|
||||
serverConnection = new NetworkSupport(this);
|
||||
networkSupport = new NetworkSupport(this); // Initialize NetworkSupport
|
||||
serverConnection = networkSupport;
|
||||
logic = new ClientGameLogic(serverConnection);
|
||||
logic.addListener(this);
|
||||
setShowSettings(config.getShowSettings());
|
||||
@@ -72,6 +76,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
return logic;
|
||||
}
|
||||
|
||||
public NetworkSupport getNetworkSupport() {
|
||||
return networkSupport;
|
||||
}
|
||||
|
||||
private AppSettings makeSettings() {
|
||||
final AppSettings settings = new AppSettings(true);
|
||||
settings.setTitle("Monopoly Game");
|
||||
@@ -84,8 +92,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
public void simpleInitApp() {
|
||||
GuiGlobals.initialize(this);
|
||||
BaseStyles.loadStyleResources(STYLES_SCRIPT);
|
||||
GuiGlobals.getInstance().getStyles().setDefaultStyle("pp"); //NON-NLS
|
||||
final BitmapFont normalFont = assetManager.loadFont(FONT); //NON-NLS
|
||||
GuiGlobals.getInstance().getStyles().setDefaultStyle("pp"); // NON-NLS
|
||||
final BitmapFont normalFont = assetManager.loadFont(FONT); // NON-NLS
|
||||
|
||||
setupInput();
|
||||
setupGui();
|
||||
@@ -125,18 +133,16 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void blockInputs() {
|
||||
if (!inputBlocked) {
|
||||
System.out.println("Blockiere Eingaben...");
|
||||
inputManager.setCursorVisible(true); // Cursor sichtbar machen
|
||||
inputManager.clearMappings(); // Alle Mappings entfernen
|
||||
inputManager.clearMappings(); // Alle Mappings entfernen
|
||||
inputBlocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void unblockInputs() {
|
||||
if (inputBlocked) {
|
||||
System.out.println("Aktiviere Eingaben...");
|
||||
@@ -200,11 +206,32 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
public void startTestWorld() {
|
||||
guiNode.detachAllChildren(); // Entferne GUI
|
||||
testWorld = new TestWorld(this); // Erstelle eine Instanz von TestWorld
|
||||
testWorld.initializeScene(); // Initialisiere die Szene
|
||||
testWorld.initializeScene(); // Initialisiere die Szene
|
||||
}
|
||||
|
||||
public void returnToMenu() {
|
||||
guiNode.detachAllChildren(); // Entferne die GUI
|
||||
StartMenu.createStartMenu(this); // Zeige das Startmenü erneut
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Server in einem neuen Thread.
|
||||
*/
|
||||
public void startServer() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MonopolyServer.main(new String[0]); // Startet den MonopolyServer
|
||||
} catch (Exception e) {
|
||||
errorDialog("Fehler: Server konnte nicht gestartet werden.");
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public MonopolyServer getMonopolyServer() {
|
||||
return monopolyServer;
|
||||
}
|
||||
|
||||
public ServerConnection getServerConnection() {
|
||||
return serverConnection;
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import pp.dialog.SimpleDialog;
|
||||
class NetworkDialog extends SimpleDialog {
|
||||
private static final Logger LOGGER = System.getLogger(NetworkDialog.class.getName());
|
||||
private static final String LOCALHOST = "localhost";
|
||||
private static final String DEFAULT_PORT = "1234";
|
||||
private static final String DEFAULT_PORT = "42069";
|
||||
private final NetworkSupport network;
|
||||
private final TextField host = new TextField(LOCALHOST);
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
|
@@ -18,7 +18,7 @@ import pp.monopoly.message.server.ServerMessage;
|
||||
* Manages the network connection for the Monopoly application.
|
||||
* Handles connecting to and disconnecting from the server, and sending messages.
|
||||
*/
|
||||
class NetworkSupport implements MessageListener<Client>, ClientStateListener, ServerConnection {
|
||||
public class NetworkSupport implements MessageListener<Client>, ClientStateListener, ServerConnection {
|
||||
private static final Logger LOGGER = System.getLogger(NetworkSupport.class.getName());
|
||||
private final MonopolyApp app;
|
||||
private Client client;
|
||||
@@ -141,4 +141,40 @@ class NetworkSupport implements MessageListener<Client>, ClientStateListener, Se
|
||||
client.send(message);
|
||||
}
|
||||
}
|
||||
public void startServerAndJoin() {
|
||||
new Thread(() -> {
|
||||
// Server starten
|
||||
app.startServer();
|
||||
|
||||
// Warten, bis der Server tatsächlich betriebsbereit ist
|
||||
int retries = 5;
|
||||
while (retries > 0) {
|
||||
try {
|
||||
initNetwork("localhost", app.getConfig().getPort());
|
||||
app.enqueue(() -> app.setInfoText("Erfolgreich verbunden!"));
|
||||
return; // Verbindung erfolgreich
|
||||
} catch (IOException e) {
|
||||
retries--;
|
||||
try {
|
||||
Thread.sleep(1000); // Eine Sekunde warten und erneut versuchen
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // Abbrechen, wenn der Thread unterbrochen wird
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn alle Versuche fehlschlagen
|
||||
app.enqueue(() -> app.errorDialog("Fehler: Verbindung zum Server fehlgeschlagen."));
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void connectToServer(String host, int port) {
|
||||
try {
|
||||
initNetwork(host, port); // Verbindung initialisieren
|
||||
app.setInfoText("Erfolgreich mit Server verbunden!");
|
||||
} catch (IOException e) {
|
||||
app.errorDialog("Fehler: Verbindung zum Server fehlgeschlagen.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
|
@@ -12,22 +12,21 @@ import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.StartMenu;
|
||||
|
||||
|
||||
/**
|
||||
* CreateGameMenu class represents the menu for creating a new game.
|
||||
*/
|
||||
public class CreateGameMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
private Label serverStatusLabel;
|
||||
|
||||
/**
|
||||
* Konstruktor für das CreateGameMenu.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
*/
|
||||
public CreateGameMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
|
||||
@@ -39,8 +38,10 @@ public class CreateGameMenu {
|
||||
menuContainer.setPreferredSize(new Vector3f(600, 400, 0)); // Feste Größe des Containers
|
||||
|
||||
// Titel
|
||||
Label title = menuContainer.addChild(new Label("Neues Spiel"));
|
||||
title.setFontSize(48);
|
||||
Label title = menuContainer.addChild(new Label("Neues Spiel", new ElementId("header")));
|
||||
title.setFont(app.getAssetManager().loadFont("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt"));
|
||||
title.setFontSize(50);
|
||||
|
||||
|
||||
// Eingabefelder-Container
|
||||
Container inputContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
||||
@@ -48,12 +49,12 @@ public class CreateGameMenu {
|
||||
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
||||
|
||||
inputContainer.addChild(new Label("Server-Adresse:"));
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("localhost"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
|
||||
playerNameField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
inputContainer.addChild(new Label("Port:"));
|
||||
TextField portField = inputContainer.addChild(new TextField("42069"));
|
||||
portField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
// Button-Container
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
@@ -65,25 +66,49 @@ public class CreateGameMenu {
|
||||
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
cancelButton.addClickCommands(source -> goBackToStartMenu());
|
||||
|
||||
// "Spiel hosten"-Button
|
||||
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
|
||||
// "Selber hosten"-Button
|
||||
Button hostButton = buttonContainer.addChild(new Button("Selber hosten"));
|
||||
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
hostButton.addClickCommands(source -> {
|
||||
closeCreateGameMenu(); // Schließt das Menü
|
||||
app.startTestWorld(); // Starte die TestWorld im selben Fenster
|
||||
});
|
||||
hostButton.addClickCommands(source -> app.getNetworkSupport().startServerAndJoin());
|
||||
|
||||
// "Beitreten"-Button
|
||||
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
// Placeholder für die Beitrittslogik
|
||||
joinButton.addClickCommands(source -> {
|
||||
try {
|
||||
String host = playerNameField.getText().trim();
|
||||
int port = Integer.parseInt(serverAddressField.getText().trim());
|
||||
app.getNetworkSupport().connectToServer(host, port);
|
||||
|
||||
// LobbyMenu öffnen
|
||||
app.enqueue(() -> {
|
||||
app.getGuiNode().detachAllChildren(); // Bestehende GUI entfernen
|
||||
new LobbyMenu(app); // LobbyMenu erstellen
|
||||
});
|
||||
} catch (NumberFormatException e) {
|
||||
app.errorDialog("Port muss eine Zahl sein.");
|
||||
}
|
||||
});
|
||||
|
||||
// Serverstatus-Label
|
||||
serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
|
||||
serverStatusLabel.setFontSize(24);
|
||||
|
||||
// Zentrierung des Containers
|
||||
menuContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
app.getInputManager().addMapping("OpenTestWorld", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_T));
|
||||
app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() {
|
||||
@Override
|
||||
public void onAction(String name, boolean isPressed, float tpf) {
|
||||
if (name.equals("OpenTestWorld") && isPressed) {
|
||||
app.startTestWorld(); // Öffnet die TestWorld
|
||||
}
|
||||
}
|
||||
}, "OpenTestWorld");
|
||||
|
||||
app.getGuiNode().attachChild(menuContainer);
|
||||
}
|
||||
@@ -107,15 +132,8 @@ public class CreateGameMenu {
|
||||
* Geht zum Startmenü zurück, wenn "Abbrechen" angeklickt wird.
|
||||
*/
|
||||
private void goBackToStartMenu() {
|
||||
closeCreateGameMenu(); // Schließt das Menü
|
||||
StartMenu.createStartMenu(app); // Zeige das Startmenü
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt das CreateGameMenu und dessen Hintergrund.
|
||||
*/
|
||||
private void closeCreateGameMenu() {
|
||||
app.getGuiNode().detachChild(menuContainer); // Entfernt den Menü-Container
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
StartMenu.createStartMenu(app);
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
public class GameMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
|
||||
/**
|
||||
* Constructs the SettingsMenu dialog for the Monopoly application.
|
||||
*
|
||||
* @param app the MonopolyApp instance
|
||||
*/
|
||||
public GameMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Add a title label for Settings
|
||||
Label settingsTitle = new Label("Einstellungen", new ElementId("settings-title"));
|
||||
settingsTitle.setFontSize(48); // Set font size for the title
|
||||
settingsTitle.setColor(ColorRGBA.White);
|
||||
|
||||
// Add any settings-related components here, such as volume control, toggles, etc.
|
||||
|
||||
// Add a back button to return to StartMenu
|
||||
Button backButton = new Button("Zurück", new ElementId("menu-button"));
|
||||
backButton.setColor(ColorRGBA.White);
|
||||
backButton.setFontSize(24);
|
||||
backButton.addClickCommands(source -> returnToStartMenu());
|
||||
|
||||
// Add components to this dialog
|
||||
addChild(settingsTitle);
|
||||
addChild(backButton);
|
||||
|
||||
// You can add more settings components here, like checkboxes or sliders.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns to the StartMenu when the back button is clicked.
|
||||
*/
|
||||
private void returnToStartMenu() {
|
||||
app.getDialogManager().close(this); // Close the current settings dialog
|
||||
//TODO return zum Ausgangsmenü
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
public class LobbyMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
|
||||
public LobbyMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
|
||||
// Entfernt das CreateGameMenu (inklusive Hintergrund)
|
||||
app.getGuiNode().detachAllChildren();
|
||||
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
addBackgroundImage();
|
||||
|
||||
// Hauptcontainer für das Menü
|
||||
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
menuContainer.setPreferredSize(new Vector3f(600, 400, 0)); // Feste Größe des Containers
|
||||
|
||||
// Titel
|
||||
Label title = menuContainer.addChild(new Label("Lobby"));
|
||||
title.setFontSize(48);
|
||||
|
||||
// Spielerstatus anzeigen
|
||||
Container playerListContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
||||
playerListContainer.addChild(new Label("Spieler in der Lobby:"));
|
||||
Label playersLabel = playerListContainer.addChild(new Label("Noch keine Spieler verbunden.")); // Beispieltext
|
||||
|
||||
// Buttons
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
buttonContainer.setPreferredSize(new Vector3f(400, 50, 0));
|
||||
|
||||
// "Bereit"-Button
|
||||
Button readyButton = buttonContainer.addChild(new Button("Bereit"));
|
||||
readyButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
readyButton.addClickCommands(source -> toggleReady(playersLabel));
|
||||
|
||||
// "Zurück"-Button
|
||||
Button backButton = buttonContainer.addChild(new Button("Zurück"));
|
||||
backButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
backButton.addClickCommands(source -> goBackToCreateGame());
|
||||
|
||||
// Zentrierung des Containers
|
||||
menuContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(menuContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||
*/
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
background = new Geometry("Background", quad);
|
||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
||||
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet den "Bereit"-Status um.
|
||||
*/
|
||||
private void toggleReady(Label playersLabel) {
|
||||
// Beispiel-Logik für das Umschalten des Status
|
||||
playersLabel.setText("Spielerstatus aktualisiert."); // Beispieltext
|
||||
}
|
||||
|
||||
/**
|
||||
* Geht zurück zum CreateGameMenu.
|
||||
*/
|
||||
private void goBackToCreateGame() {
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
new CreateGameMenu(app);
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package pp.monopoly.client.gui;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.simsilica.lemur.Button;
|
||||
@@ -12,7 +13,9 @@ import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.Slider;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import com.simsilica.lemur.ValueRenderer;
|
||||
|
||||
import com.simsilica.lemur.Selector;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
@@ -23,6 +26,7 @@ public class SettingsMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container settingsContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
public SettingsMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
@@ -32,10 +36,17 @@ public class SettingsMenu extends Dialog {
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
|
||||
// Hauptcontainer für das Menü
|
||||
settingsContainer = new Container();
|
||||
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f)));
|
||||
|
||||
|
||||
|
||||
// Titel
|
||||
Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
|
||||
settingsTitle.setFontSize(48);
|
||||
@@ -44,24 +55,59 @@ public class SettingsMenu extends Dialog {
|
||||
Container effectSoundContainer = settingsContainer.addChild(new Container());
|
||||
effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
|
||||
effectSoundContainer.addChild(new Slider());
|
||||
effectSoundContainer.addChild(new Checkbox("Aktivieren")).setChecked(true);
|
||||
|
||||
effectSoundContainer.addChild(new Checkbox("Soundeffekte an")).setChecked(true);
|
||||
effectSoundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
// Hintergrundmusik: Slider und Checkbox
|
||||
Container backgroundMusicContainer = settingsContainer.addChild(new Container());
|
||||
backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label")));
|
||||
backgroundMusicContainer.addChild(new Slider());
|
||||
backgroundMusicContainer.addChild(new Checkbox("Aktivieren")).setChecked(true);
|
||||
backgroundMusicContainer.addChild(new Checkbox("Musik an")).setChecked(true);
|
||||
backgroundMusicContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
/*Selector<String> dropdown = new Selector<>();
|
||||
backgroundMusicContainer.addChild(dropdown);
|
||||
|
||||
Vector3f dimens = settingsContainer.getPreferredSize();
|
||||
Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX(dimens.getX());
|
||||
dropdown.getPopupContainer().setPreferredSize(dimens2);*/
|
||||
// Create the dropdown menu
|
||||
Selector<String> dropdown = new Selector<>();
|
||||
|
||||
// Generate and add numbered examples to the dropdown
|
||||
for (int i = 1; i <= 10; i++) { // Generate 10 examples
|
||||
dropdown.getModel().add("Example " + i);
|
||||
}
|
||||
|
||||
|
||||
// Add the dropdown to the container
|
||||
backgroundMusicContainer.addChild(dropdown);
|
||||
|
||||
// Adjust the dropdown's popup container size if necessary
|
||||
Vector3f dimens = settingsContainer.getPreferredSize();
|
||||
Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX(dimens.getX());
|
||||
dropdown.getPopupContainer().setPreferredSize(dimens2);
|
||||
// Beenden-Button
|
||||
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(source -> app.stop());
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(settingsContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
|
||||
// Zentriere das Menü
|
||||
settingsContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
|
||||
1
|
||||
4
|
||||
);
|
||||
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x - padding) / 2,
|
||||
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y+ padding) / 2,
|
||||
3
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(settingsContainer);
|
||||
@@ -90,6 +136,7 @@ public class SettingsMenu extends Dialog {
|
||||
public void close() {
|
||||
System.out.println("Schließe SettingsMenu..."); // Debugging-Ausgabe
|
||||
app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
|
||||
app.unblockInputs(); // Eingaben wieder aktivieren
|
||||
|
@@ -80,7 +80,7 @@ public class TestWorld {
|
||||
|
||||
// Setze das Material mit Textur
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
Texture texture = app.getAssetManager().loadTexture("Pictures/board.png");
|
||||
Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||
mat.setTexture("ColorMap", texture);
|
||||
geom.setMaterial(mat);
|
||||
|
||||
|
@@ -3,20 +3,22 @@ package pp.monopoly.client.gui;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
* Die Buttons bewegen den Würfel auf dem Spielfeld.
|
||||
*/
|
||||
public class Toolbar {
|
||||
public class Toolbar extends Dialog {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container toolbarContainer;
|
||||
@@ -35,6 +37,7 @@ public class Toolbar {
|
||||
* @param cube Der Würfel, der bewegt werden soll
|
||||
*/
|
||||
public Toolbar(MonopolyApp app, Geometry cube) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
this.cube = cube;
|
||||
|
||||
@@ -44,13 +47,41 @@ public class Toolbar {
|
||||
// Setze die Position am unteren Rand und die Breite
|
||||
toolbarContainer.setLocalTranslation(
|
||||
0, // Links bündig
|
||||
100, // Höhe über dem unteren Rand
|
||||
200, // Höhe über dem unteren Rand
|
||||
0 // Z-Ebene
|
||||
);
|
||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); // Volle Breite
|
||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite
|
||||
|
||||
// Hintergrund Grau
|
||||
toolbarContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f)));
|
||||
|
||||
// Füge Buttons zur Toolbar hinzu
|
||||
initializeButtons();
|
||||
//initializeButtons();
|
||||
|
||||
|
||||
// Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten"
|
||||
Container accountContainer = toolbarContainer.addChild(new Container());
|
||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label")));
|
||||
accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label")));
|
||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Menü-Container: Ein Container für Übersicht
|
||||
Container overviewContainer = toolbarContainer.addChild(new Container());
|
||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label")));
|
||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Menü-Container: Ein Container für Würfel
|
||||
Container diceContainer = toolbarContainer.addChild(new Container());
|
||||
diceContainer.addChild(new Label("Wo Würfel?", new ElementId("label")));
|
||||
diceContainer.addChild(addDiceRollButton());
|
||||
diceContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Menü-Container: Ein Nested-Container für Handeln, Grundstücke und Zug beenden
|
||||
Container menuContainer = toolbarContainer.addChild(new Container());
|
||||
menuContainer.addChild(new Button("Handeln"));
|
||||
menuContainer.addChild(new Button("Grundstücke"));
|
||||
menuContainer.addChild(new Button("Zug beenden"));
|
||||
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Füge die Toolbar zur GUI hinzu
|
||||
app.getGuiNode().attachChild(toolbarContainer);
|
||||
@@ -64,9 +95,10 @@ public class Toolbar {
|
||||
* Initialisiert die Buttons in der Toolbar.
|
||||
*/
|
||||
private void initializeButtons() {
|
||||
addButton("Vorwärts", 1); // Bewegung nach vorne
|
||||
addButton("Rückwärts", -1); // Bewegung nach hinten
|
||||
addTradeMenuButton(); // Bewegung nach vorne
|
||||
addEndTurnButton(); // Bewegung nach hinten
|
||||
addDiceRollButton(); // Würfel-Button
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,21 +107,44 @@ public class Toolbar {
|
||||
* @param label Der Text des Buttons
|
||||
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts)
|
||||
*/
|
||||
private void addButton(String label, int step) {
|
||||
|
||||
/*private void addButton(String label, int step) {
|
||||
Button button = new Button(label);
|
||||
button.setPreferredSize(new Vector3f(150, 50, 0)); // Größe der Buttons
|
||||
button.addClickCommands(source -> moveCube(step));
|
||||
toolbarContainer.addChild(button);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Fügt den Würfel-Button hinzu, der die Figur entsprechend der gewürfelten Zahl bewegt.
|
||||
*/
|
||||
private void addDiceRollButton() {
|
||||
private Button addDiceRollButton() {
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
toolbarContainer.addChild(diceButton);
|
||||
return diceButton;
|
||||
}
|
||||
|
||||
private void addTradeMenuButton() {
|
||||
Button diceButton = new Button("Handeln");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
private void addEndTurnButton() {
|
||||
Button diceButton = new Button("Grundstücke");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
private void addPropertyMenuButton() {
|
||||
Button diceButton = new Button("Zug beenden");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,168 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
* Die Buttons bewegen den Würfel auf dem Spielfeld.
|
||||
*/
|
||||
public class Toolbar2 {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container toolbarContainer;
|
||||
private final Geometry cube; // Referenz auf den Würfel
|
||||
private final BitmapText positionText; // Anzeige für die aktuelle Position
|
||||
private final float boardLimit = 0.95f; // Grenzen des Bretts
|
||||
private final float stepSize = 0.18f; // Schrittgröße pro Bewegung
|
||||
private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld
|
||||
private final int positionsPerSide = 10; // Anzahl der Positionen pro Seite
|
||||
private final Random random = new Random(); // Zufallsgenerator für den Würfelwurf
|
||||
|
||||
/**
|
||||
* Konstruktor für die Toolbar.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
* @param cube Der Würfel, der bewegt werden soll
|
||||
*/
|
||||
public Toolbar2(MonopolyApp app, Geometry cube) {
|
||||
this.app = app;
|
||||
this.cube = cube;
|
||||
|
||||
// Erstelle die Toolbar
|
||||
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
|
||||
// Setze die Position am unteren Rand und die Breite
|
||||
toolbarContainer.setLocalTranslation(
|
||||
0, // Links bündig
|
||||
100, // Höhe über dem unteren Rand
|
||||
0 // Z-Ebene
|
||||
);
|
||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); // Volle Breite
|
||||
|
||||
// Füge Buttons zur Toolbar hinzu
|
||||
initializeButtons();
|
||||
|
||||
// Füge die Toolbar zur GUI hinzu
|
||||
app.getGuiNode().attachChild(toolbarContainer);
|
||||
|
||||
// Erstelle die Position-Anzeige
|
||||
positionText = createPositionDisplay();
|
||||
updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert die Buttons in der Toolbar.
|
||||
*/
|
||||
private void initializeButtons() {
|
||||
addButton("Vorwärts", 1); // Bewegung nach vorne
|
||||
addButton("Rückwärts", -1); // Bewegung nach hinten
|
||||
addDiceRollButton(); // Würfel-Button
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt einen Button mit einer Bewegung hinzu.
|
||||
*
|
||||
* @param label Der Text des Buttons
|
||||
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts)
|
||||
*/
|
||||
private void addButton(String label, int step) {
|
||||
Button button = new Button(label);
|
||||
button.setPreferredSize(new Vector3f(150, 50, 0)); // Größe der Buttons
|
||||
button.addClickCommands(source -> moveCube(step));
|
||||
toolbarContainer.addChild(button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt den Würfel-Button hinzu, der die Figur entsprechend der gewürfelten Zahl bewegt.
|
||||
*/
|
||||
private void addDiceRollButton() {
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(source -> rollDice());
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simuliert einen Würfelwurf und bewegt die Figur entsprechend.
|
||||
*/
|
||||
private void rollDice() {
|
||||
int diceRoll = random.nextInt(6) + 1; // Zahl zwischen 1 und 6
|
||||
System.out.println("Gewürfelt: " + diceRoll);
|
||||
moveCube(diceRoll); // Bewege die Figur um die gewürfelte Zahl
|
||||
}
|
||||
|
||||
/**
|
||||
* Bewegt den Würfel basierend auf der aktuellen Position auf dem Brett.
|
||||
*
|
||||
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts oder andere Werte)
|
||||
*/
|
||||
private void moveCube(int step) {
|
||||
currentPosition = (currentPosition + step + 4 * positionsPerSide) % (4 * positionsPerSide);
|
||||
Vector3f newPosition = calculatePosition(currentPosition);
|
||||
cube.setLocalTranslation(newPosition);
|
||||
updatePositionDisplay(); // Aktualisiere die Positionsanzeige
|
||||
System.out.println("Würfelposition: " + newPosition + " (Feld-ID: " + currentPosition + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die neue Position des Würfels basierend auf der aktuellen Brettseite und Position.
|
||||
*
|
||||
* @param position Aktuelle Position auf dem Spielfeld
|
||||
* @return Die berechnete Position als Vector3f
|
||||
*/
|
||||
private Vector3f calculatePosition(int position) {
|
||||
int side = position / positionsPerSide; // Seite des Bretts (0 = unten, 1 = rechts, 2 = oben, 3 = links)
|
||||
int offset = position % positionsPerSide; // Position auf der aktuellen Seite
|
||||
|
||||
switch (side) {
|
||||
case 0: // Unten (positive x-Achse)
|
||||
return new Vector3f(-boardLimit + offset * stepSize, 0.1f, -boardLimit + 0.05f);
|
||||
case 1: // Rechts (positive z-Achse)
|
||||
return new Vector3f(boardLimit - 0.05f, 0.1f, -boardLimit + offset * stepSize);
|
||||
case 2: // Oben (negative x-Achse)
|
||||
return new Vector3f(boardLimit - offset * stepSize, 0.1f, boardLimit - 0.05f);
|
||||
case 3: // Links (negative z-Achse)
|
||||
return new Vector3f(-boardLimit + 0.05f, 0.1f, boardLimit - offset * stepSize);
|
||||
default:
|
||||
throw new IllegalArgumentException("Ungültige Position: " + position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die Anzeige für die aktuelle Position.
|
||||
*
|
||||
* @return Das BitmapText-Objekt für die Anzeige
|
||||
*/
|
||||
private BitmapText createPositionDisplay() {
|
||||
BitmapText text = new BitmapText(app.getAssetManager().loadFont("Interface/Fonts/Default.fnt"), false);
|
||||
text.setSize(20); // Schriftgröße
|
||||
text.setLocalTranslation(10, app.getCamera().getHeight() - 10, 0); // Oben links
|
||||
app.getGuiNode().attachChild(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Anzeige für die aktuelle Position.
|
||||
*/
|
||||
private void updatePositionDisplay() {
|
||||
positionText.setText("Feld-ID: " + currentPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt die Toolbar.
|
||||
*/
|
||||
public void remove() {
|
||||
app.getGuiNode().detachChild(toolbarContainer);
|
||||
app.getGuiNode().detachChild(positionText);
|
||||
}
|
||||
}
|
BIN
Projekte/monopoly/client/src/main/resources/Pictures/board2.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/board2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Projekte/monopoly/client/src/main/resources/Sound/background.ogg
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Sound/background.ogg
Normal file
Binary file not shown.
@@ -7,9 +7,4 @@ description = 'Monopoly common model'
|
||||
dependencies {
|
||||
api project(":common")
|
||||
api libs.jme3.networking
|
||||
testImplementation libs.mockito.core
|
||||
|
||||
testImplementation project(":monopoly:client")
|
||||
testImplementation project(":monopoly:model")
|
||||
testImplementation project(":monopoly:server")
|
||||
}
|
||||
}
|
||||
|
@@ -28,19 +28,19 @@ public class MonopolyConfig extends Config {
|
||||
* The default port number for the Monopoly server.
|
||||
*/
|
||||
@Property("port")
|
||||
private int port = 42069;
|
||||
private int port = 4321;
|
||||
|
||||
/**
|
||||
* The width of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.width")
|
||||
private int mapWidth = 10;
|
||||
private int mapWidth = 12;
|
||||
|
||||
/**
|
||||
* The height of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.height")
|
||||
private int mapHeight = 10;
|
||||
private int mapHeight = 12;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code MonopolyConfig} with default settings.
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
public class ActiveState extends ClientState{
|
||||
|
||||
ActiveState(ClientGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
@@ -21,6 +21,7 @@ import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameOver;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.message.server.TimeOutWarning;
|
||||
@@ -54,9 +55,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||
private Board board;
|
||||
|
||||
private ClientState state = new ClientState(this) {
|
||||
|
||||
};
|
||||
private ClientState state = new LobbyState(this);
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
@@ -256,5 +255,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NextPlayerTurn msg) {
|
||||
state = new ActiveState(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
public class LobbyState extends ClientState{
|
||||
|
||||
LobbyState(ClientGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
public class WaitForTurnState extends ClientState{
|
||||
|
||||
WaitForTurnState(ClientGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
@@ -307,7 +307,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
*/
|
||||
@@ -438,7 +438,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
getOutOfJailCard--;
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class BankruptState implements PlayerState {
|
||||
@@ -460,7 +460,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
@@ -482,6 +482,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package pp.monopoly.game.server;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -50,6 +51,14 @@ public class PlayerHandler {
|
||||
return players.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retuns all players
|
||||
* @return List of all players
|
||||
*/
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chechs if all players are ready to start the game
|
||||
* @return {@code true} if all players are ready, otherwise {@code false}
|
||||
@@ -134,4 +143,11 @@ public class PlayerHandler {
|
||||
}
|
||||
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
||||
}
|
||||
|
||||
/**
|
||||
* Arranges the players turns in a random order
|
||||
*/
|
||||
void randomOrder() {
|
||||
Collections.shuffle(players);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,20 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.*;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.message.client.TradeOffer;
|
||||
import pp.monopoly.message.client.TradeResponse;
|
||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
import pp.monopoly.message.server.TradeRequest;
|
||||
@@ -9,13 +22,6 @@ import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
/**
|
||||
* Controls the server-side game logic for Monopoly.
|
||||
* Manages game states, player interactions, and message handling.
|
||||
@@ -26,7 +32,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
private final MonopolyConfig config;
|
||||
private final PlayerHandler playerHandler = new PlayerHandler(this);
|
||||
private final ServerSender serverSender;
|
||||
private ServerState state = ServerState.CREATEGAME;
|
||||
private ServerState state = ServerState.LOBBY;
|
||||
private static final int MAX_PLAYERS = 6;
|
||||
private BoardManager boardManager = new BoardManager();
|
||||
|
||||
@@ -120,6 +126,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount());
|
||||
|
||||
return player;
|
||||
}
|
||||
@@ -159,7 +166,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||
playerHandler.nextPlayer();
|
||||
Player next = playerHandler.nextPlayer();
|
||||
send(next, new NextPlayerTurn(next));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,10 +182,17 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
player.setName(msg.getName());
|
||||
player.setColor(msg.getColor());
|
||||
player.setName(msg.getName());
|
||||
playerHandler.setPlayerReady(player, true);
|
||||
LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName());
|
||||
}
|
||||
|
||||
if(playerHandler.allPlayersReady()) {
|
||||
for (Player p : playerHandler.getPlayers()) {
|
||||
send(p, new GameStart(playerHandler.getPlayers()));
|
||||
}
|
||||
playerHandler.randomOrder();
|
||||
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,11 +251,12 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
*/
|
||||
@Override
|
||||
public void received(ViewAssetsRequest msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", player.getName());
|
||||
Player sender = playerHandler.getPlayerById(from);
|
||||
Player player = msg.getPlayer();
|
||||
if (sender != null && player != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
|
||||
|
||||
send(player, new ViewAssetsResponse(player.getProperties(), player.getAccountBalance(), player.getNumJailCard()));
|
||||
send(sender, new ViewAssetsResponse(boardManager, player.getProperties(), player.getAccountBalance(), player.getNumJailCard()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,50 +1,38 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
|
||||
/**
|
||||
* Represents a message indicating the player is ready to play.
|
||||
*/
|
||||
public class PlayerReady extends ClientMessage{
|
||||
public class PlayerReady extends ClientMessage {
|
||||
private boolean isReady;
|
||||
private String name;
|
||||
private PlayerColor color;
|
||||
private String figure;
|
||||
|
||||
/**
|
||||
* Constructs a PlayerReady message.
|
||||
*
|
||||
* @param isReady true if the player is ready, false otherwise
|
||||
* @param name the name of the player
|
||||
* @param color the color of the player (can be null)
|
||||
*/
|
||||
public PlayerReady(boolean isReady) {
|
||||
public PlayerReady(boolean isReady, String name, String figure) {
|
||||
this.isReady = isReady;
|
||||
this.name = name;
|
||||
this.figure = figure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Name
|
||||
* @return the Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Playercolor
|
||||
* @return the Playercolor
|
||||
*/
|
||||
public PlayerColor getColor() {
|
||||
return color;
|
||||
public String getFigure() {
|
||||
return figure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is ready.
|
||||
*
|
||||
* @return true if ready, false otherwise
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return isReady;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
|
@@ -1,12 +1,25 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents a request from a player to view their assets.
|
||||
*/
|
||||
public class ViewAssetsRequest extends ClientMessage{
|
||||
|
||||
private final Player player;
|
||||
|
||||
public ViewAssetsRequest(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,21 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
public class GameStart extends ServerMessage{
|
||||
|
||||
private final List<Player> players;
|
||||
|
||||
public GameStart(List<Player> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
public class NextPlayerTurn extends ServerMessage{
|
||||
|
||||
private final Player player;
|
||||
|
||||
public NextPlayerTurn(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
@@ -89,4 +89,11 @@ public interface ServerInterpreter {
|
||||
* @param msg the TradeRequest message received
|
||||
*/
|
||||
void received(TradeRequest msg);
|
||||
|
||||
/**
|
||||
* Handles a NextPlayerTurn message received from the server.
|
||||
*
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(NextPlayerTurn msg);
|
||||
}
|
||||
|
@@ -2,13 +2,16 @@ package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
/**
|
||||
* Represents a response containing the player's assets.
|
||||
*/
|
||||
public class ViewAssetsResponse extends ServerMessage{
|
||||
|
||||
private final List<PropertyField> properties;
|
||||
private final BoardManager board;
|
||||
private final int accountBalance;
|
||||
private final int jailCards;
|
||||
|
||||
@@ -18,7 +21,8 @@ public class ViewAssetsResponse extends ServerMessage{
|
||||
* @param properties a List of PropertyField objects representing the player's properties
|
||||
* @param accountBalance the player's current account balance
|
||||
*/
|
||||
public ViewAssetsResponse(List<PropertyField> properties, int accountBalance, int jailCards) {
|
||||
public ViewAssetsResponse(BoardManager board, List<PropertyField> properties, int accountBalance, int jailCards) {
|
||||
this.board = board;
|
||||
this.properties = properties;
|
||||
this.accountBalance = accountBalance;
|
||||
this.jailCards = jailCards;
|
||||
@@ -47,4 +51,7 @@ public class ViewAssetsResponse extends ServerMessage{
|
||||
return jailCards;
|
||||
}
|
||||
|
||||
public BoardManager getboard() {
|
||||
return board;
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ public class Card {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@@ -22,49 +22,49 @@ public class BoardManager {
|
||||
* Creates a Monopoly GameBoard
|
||||
* @return the List of Fields in correct Order
|
||||
*/
|
||||
private static List<Field> createBoard() {
|
||||
private List<Field> createBoard() {
|
||||
ArrayList<Field> fields = new ArrayList<>();
|
||||
|
||||
fields.add(new GoField());
|
||||
fields.add(new BuildingProperty("Gym", 1, 600, 20));
|
||||
fields.add(new BuildingProperty("Gym", 1, 600, 20, 500, FieldColor.BROWN));
|
||||
fields.add(new EventField("Hausfeier", 2));
|
||||
fields.add(new BuildingProperty("Sportplatz", 3, 600, 40));
|
||||
fields.add(new BuildingProperty("Sportplatz", 3, 600, 40, 500, FieldColor.BROWN));
|
||||
fields.add(new FineField("Diszi", 4, 2000));
|
||||
fields.add(new GateField("Südtor", 5));
|
||||
fields.add(new BuildingProperty("Studium+", 6, 1000, 60));
|
||||
fields.add(new BuildingProperty("Studium+", 6, 1000, 60, 500, FieldColor.BLUE_LIGHT));
|
||||
fields.add(new EventField("Üvas", 7));
|
||||
fields.add(new BuildingProperty("PhysikHörsaal", 8, 1000, 60));
|
||||
fields.add(new BuildingProperty("Audimax", 9, 1200, 80));
|
||||
fields.add(new BuildingProperty("PhysikHörsaal", 8, 1000, 60, 500, FieldColor.BLUE_LIGHT));
|
||||
fields.add(new BuildingProperty("Audimax", 9, 1200, 80, 500, FieldColor.BLUE_LIGHT));
|
||||
fields.add(new GulagField());
|
||||
fields.add(new BuildingProperty("99er", 11, 1400, 100));
|
||||
fields.add(new BuildingProperty("99er", 11, 1400, 100, 1000, FieldColor.PINK));
|
||||
fields.add(new FoodField("Brandl", 12));
|
||||
fields.add(new BuildingProperty("12er", 13, 1400, 100));
|
||||
fields.add(new BuildingProperty("23er", 14, 1600, 120));
|
||||
fields.add(new BuildingProperty("12er", 13, 1400, 100, 1000, FieldColor.PINK));
|
||||
fields.add(new BuildingProperty("23er", 14, 1600, 120, 1000, FieldColor.PINK));
|
||||
fields.add(new GateField("HauptWache", 15));
|
||||
fields.add(new BuildingProperty("Schwimmhalle", 16, 1800, 140));
|
||||
fields.add(new BuildingProperty("CISM-Bahn", 17, 1800, 140));
|
||||
fields.add(new BuildingProperty("Schwimmhalle", 16, 1800, 140, 1000, FieldColor.ORANGE));
|
||||
fields.add(new BuildingProperty("CISM-Bahn", 17, 1800, 140, 1000, FieldColor.ORANGE));
|
||||
fields.add(new EventField("Marine-Welcome-Party", 18));
|
||||
fields.add(new BuildingProperty("Kletterturm", 19, 2000, 160));
|
||||
fields.add(new BuildingProperty("Kletterturm", 19, 2000, 160, 1000, FieldColor.ORANGE));
|
||||
fields.add(new TestStreckeField());
|
||||
fields.add(new BuildingProperty("StudFBer C", 21, 2200, 180));
|
||||
fields.add(new BuildingProperty("StudFBer C", 21, 2200, 180, 1500, FieldColor.RED));
|
||||
fields.add(new EventField("Üvas", 22));
|
||||
fields.add(new BuildingProperty("StudFBer B", 23, 2200, 180));
|
||||
fields.add(new BuildingProperty("StudFBer A", 24, 2400, 200));
|
||||
fields.add(new BuildingProperty("StudFBer B", 23, 2200, 180, 1500, FieldColor.RED));
|
||||
fields.add(new BuildingProperty("StudFBer A", 24, 2400, 200, 1500, FieldColor.RED));
|
||||
fields.add(new GateField("Nordtor", 25));
|
||||
fields.add(new BuildingProperty("Cascada", 26, 2600, 220));
|
||||
fields.add(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220));
|
||||
fields.add(new BuildingProperty("Cascada", 26, 2600, 220, 1500, FieldColor.YELLOW));
|
||||
fields.add(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220, 1500, FieldColor.YELLOW));
|
||||
fields.add(new FoodField("Truppenküche", 28));
|
||||
fields.add(new BuildingProperty("Prüfungsamt", 29, 2800, 240));
|
||||
fields.add(new BuildingProperty("Prüfungsamt", 29, 2800, 240, 1500, FieldColor.YELLOW));
|
||||
fields.add(new WacheField());
|
||||
fields.add(new BuildingProperty("Feuerwehr", 31, 3000, 260));
|
||||
fields.add(new BuildingProperty("SanZ", 32, 300, 260));
|
||||
fields.add(new BuildingProperty("Feuerwehr", 31, 3000, 260, 2000, FieldColor.GREEN));
|
||||
fields.add(new BuildingProperty("SanZ", 32, 300, 260, 2000, FieldColor.GREEN));
|
||||
fields.add(new EventField("Maibock", 33));
|
||||
fields.add(new BuildingProperty("Rechenzentrum", 34, 3200, 280));
|
||||
fields.add(new BuildingProperty("Rechenzentrum", 34, 3200, 280, 2000, FieldColor.GREEN));
|
||||
fields.add(new GateField("Osttor", 35));
|
||||
fields.add(new EventField("Üvas", 36));
|
||||
fields.add(new BuildingProperty("2er", 37, 3500, 350));
|
||||
fields.add(new BuildingProperty("2er", 37, 3500, 350, 2000, FieldColor.BLUE_DARK));
|
||||
fields.add(new FineField("EZM", 38, 1000));
|
||||
fields.add(new BuildingProperty("20er", 39, 4000, 500));
|
||||
fields.add(new BuildingProperty("20er", 39, 4000, 500, 2000, FieldColor.BLUE_DARK));
|
||||
|
||||
return fields;
|
||||
}
|
||||
@@ -88,4 +88,8 @@ public class BoardManager {
|
||||
if (board.contains(field)) return field.getId();
|
||||
else throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public List<Field> getBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,42 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
public class BuildingProperty extends PropertyField {
|
||||
|
||||
private int houses;
|
||||
private boolean hotel = false;
|
||||
private final int housePrice;
|
||||
private final FieldColor color;
|
||||
private final int rentFactor1 = 5;
|
||||
private final int rentFactor2 = 15;
|
||||
private final int rentFactor3 = 40;
|
||||
private final int rentFactor4 = 55;
|
||||
private final int rentFactorHotel = 70;
|
||||
|
||||
BuildingProperty(String name, int id, int price, int rent) {
|
||||
BuildingProperty(String name, int id, int price, int rent, int housePrice, FieldColor color) {
|
||||
super(name, id, price, rent);
|
||||
this.housePrice = housePrice;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calcRent() {
|
||||
if (hotel) {
|
||||
return (int) Math.round(rent*70/10)*10;
|
||||
return (int) Math.round(rent*rentFactorHotel/10)*10;
|
||||
}
|
||||
switch (houses) {
|
||||
case 1:
|
||||
return (int) Math.round(rent*5/10)*10;
|
||||
return (int) Math.round(rent*rentFactor1/10)*10;
|
||||
case 2:
|
||||
return (int) Math.round(rent*15/10)*10;
|
||||
return (int) Math.round(rent*rentFactor2/10)*10;
|
||||
case 3:
|
||||
return (int) Math.round(rent*40/10)*10;
|
||||
return (int) Math.round(rent*rentFactor3/10)*10;
|
||||
case 4:
|
||||
return (int) Math.round(rent*55/10)*10;
|
||||
return (int) Math.round(rent*rentFactor4/10)*10;
|
||||
|
||||
default:
|
||||
return rent;
|
||||
@@ -67,4 +79,23 @@ public class BuildingProperty extends PropertyField {
|
||||
public void accept(Player player) {
|
||||
player.visit(this);
|
||||
}
|
||||
|
||||
public List<Integer> getAllRent() {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.add(rent);
|
||||
list.add((int) Math.round(rent*rentFactor1/10)*10);
|
||||
list.add((int) Math.round(rent*rentFactor2/10)*10);
|
||||
list.add((int) Math.round(rent*rentFactor3/10)*10);
|
||||
list.add((int) Math.round(rent*rentFactor4/10)*10);
|
||||
list.add((int) Math.round(rent*rentFactorHotel/10)*10);
|
||||
return list;
|
||||
}
|
||||
|
||||
public FieldColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getHousePrice() {
|
||||
return housePrice;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
|
||||
/**
|
||||
* Enum representing eight distinct colors for properties in the game.
|
||||
*/
|
||||
enum FieldColor {
|
||||
BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)),
|
||||
GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)),
|
||||
YELLOW(new ColorRGBA(252 / 255f, 241 / 255f, 1 / 255f, 1)),
|
||||
BLUE_LIGHT(new ColorRGBA(170 / 255f, 223 / 255f, 246 / 255f, 1)),
|
||||
PINK(new ColorRGBA(214 / 255f, 60 / 255f, 153 / 255f, 1)),
|
||||
ORANGE(new ColorRGBA(244 / 255f, 147 / 255f, 32 / 255f, 1)),
|
||||
RED(new ColorRGBA(232 / 255f, 27 / 255f, 30 / 255f, 1)),
|
||||
BLUE_DARK(new ColorRGBA(2 / 255f, 112 / 255f, 191 / 255f, 1));
|
||||
|
||||
private final ColorRGBA color;
|
||||
|
||||
/**
|
||||
* Constructs a FieldColor with the specified ColorRGBA value.
|
||||
*
|
||||
* @param color the ColorRGBA value associated with the field color
|
||||
*/
|
||||
FieldColor(ColorRGBA color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ColorRGBA value of the field color.
|
||||
*
|
||||
* @return the ColorRGBA value
|
||||
*/
|
||||
public ColorRGBA getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
@@ -0,0 +1,385 @@
|
||||
package pp.monopoly;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
public class Testhandbuch {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// T001 UC-game-01 - testStartApplication
|
||||
@Test
|
||||
public void testStartApplication() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
assertNotNull(mainMenu);
|
||||
}
|
||||
|
||||
// T002 UC-game-02 - testOpenStartMenu
|
||||
@Test
|
||||
public void testOpenStartMenu() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
mainMenu.showMenu();
|
||||
assertTrue(mainMenu.isMenuVisible());
|
||||
}
|
||||
|
||||
// T003 UC-game-03 - testNavigateToPlayOption
|
||||
@Test
|
||||
public void testNavigateToPlayOption() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
mainMenu.showMenu();
|
||||
mainMenu.startNewGame();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
assertNotNull(newGameMenu);
|
||||
}
|
||||
|
||||
// T004 UC-game-04 - testExitApplicationFromMenu
|
||||
@Test
|
||||
public void testExitApplicationFromMenu() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
mainMenu.showMenu();
|
||||
mainMenu.exitGame();
|
||||
assertTrue(app.isClosed());
|
||||
}
|
||||
|
||||
// T005 UC-game-05 - testOpenSettingsFromMenu
|
||||
@Test
|
||||
public void testOpenSettingsFromMenu() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
mainMenu.showMenu();
|
||||
mainMenu.openSettings();
|
||||
SettingMenu settingMenu = app.getStateManager().getState(SettingMenu.class);
|
||||
assertNotNull(settingMenu);
|
||||
}
|
||||
|
||||
// T006 UC-game-06 - testOpenGameMenuWithESC
|
||||
@Test
|
||||
public void testOpenGameMenuWithESC() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
app.simpleUpdate(0.1f);
|
||||
GameMenu gameMenu = app.getStateManager().getState(GameMenu.class);
|
||||
assertTrue(gameMenu.isVisible());
|
||||
}
|
||||
|
||||
// T007 UC-game-07 - testEnterHostName
|
||||
@Test
|
||||
public void testEnterHostName() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.enterHostName("localhost");
|
||||
assertEquals("localhost", newGameMenu.getHostName());
|
||||
}
|
||||
|
||||
// T008 UC-game-07 - testEnterPortNumber
|
||||
@Test
|
||||
public void testEnterPortNumber() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.enterPortNumber(12345);
|
||||
assertEquals(12345, newGameMenu.getPortNumber());
|
||||
}
|
||||
|
||||
// T009 UC-game-07 - testCancelGameCreation
|
||||
@Test
|
||||
public void testCancelGameCreation() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.cancel();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
assertTrue(mainMenu.isMenuVisible());
|
||||
}
|
||||
|
||||
// T010 UC-game-08 - testEnterPlayerLobby
|
||||
@Test
|
||||
public void testEnterPlayerLobby() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
app.getStateManager().getState(NetworkDialog.class).connect();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
assertNotNull(lobby);
|
||||
}
|
||||
|
||||
// T011 UC-game-09 - testEnterStartingCapital
|
||||
@Test
|
||||
public void testEnterStartingCapital() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.enterStartingCapital(1500);
|
||||
assertEquals(1500, newGameMenu.getStartingCapital());
|
||||
}
|
||||
|
||||
// T012 UC-game-09 - testIncreaseStartingCapital
|
||||
@Test
|
||||
public void testIncreaseStartingCapital() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.enterStartingCapital(1500);
|
||||
newGameMenu.increaseStartingCapital(100);
|
||||
assertEquals(1600, newGameMenu.getStartingCapital());
|
||||
}
|
||||
|
||||
// T013 UC-game-09 - testDecreaseStartingCapital
|
||||
@Test
|
||||
public void testDecreaseStartingCapital() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
NewGameMenu newGameMenu = app.getStateManager().getState(NewGameMenu.class);
|
||||
newGameMenu.showMenu();
|
||||
newGameMenu.enterStartingCapital(1500);
|
||||
newGameMenu.decreaseStartingCapital(100);
|
||||
assertEquals(1400, newGameMenu.getStartingCapital());
|
||||
}
|
||||
|
||||
// T014 UC-game-10 - testDefaultPlayerName
|
||||
@Test
|
||||
public void testDefaultPlayerName() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
app.getStateManager().getState(Lobby.class).initializePlayerNames();
|
||||
assertEquals("Spieler 1", app.getStateManager().getState(Lobby.class).getPlayerName(0));
|
||||
assertEquals("Spieler 2", app.getStateManager().getState(Lobby.class).getPlayerName(1));
|
||||
}
|
||||
|
||||
// T015 UC-game-11 - testEnterDisplayName
|
||||
@Test
|
||||
public void testEnterDisplayName() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.enterDisplayName("TestPlayer");
|
||||
assertEquals("TestPlayer", lobby.getPlayerName(0));
|
||||
}
|
||||
|
||||
// T016 UC-game-11 - testDuplicateNameEntry
|
||||
@Test
|
||||
public void testDuplicateNameEntry() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.enterDisplayName("Player1");
|
||||
assertTrue(lobby.isDuplicateName("Player1"));
|
||||
}
|
||||
|
||||
// T017 UC-game-12 - testSelectPlayerColor
|
||||
@Test
|
||||
public void testSelectPlayerColor() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.selectColor("Red");
|
||||
assertEquals("Red", lobby.getPlayerColor(0));
|
||||
}
|
||||
|
||||
// T018 UC-game-12 - testSelectOccupiedColor
|
||||
@Test
|
||||
public void testSelectOccupiedColor() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.selectColor("Red");
|
||||
assertTrue(lobby.isColorOccupied("Red"));
|
||||
}
|
||||
|
||||
// T019 UC-game-13 - testSelectPlayerToken
|
||||
@Test
|
||||
public void testSelectPlayerToken() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.selectToken("Ship");
|
||||
assertEquals("Ship", lobby.getPlayerToken(0));
|
||||
}
|
||||
|
||||
// T020 UC-game-13 - testSelectOccupiedToken
|
||||
@Test
|
||||
public void testSelectOccupiedToken() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.selectToken("Ship");
|
||||
assertTrue(lobby.isTokenOccupied("Ship"));
|
||||
}
|
||||
|
||||
// T021 UC-game-14 - testCancelPlayerLobby
|
||||
@Test
|
||||
public void testCancelPlayerLobby() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.cancel();
|
||||
MainMenu mainMenu = app.getStateManager().getState(MainMenu.class);
|
||||
assertTrue(mainMenu.isMenuVisible());
|
||||
}
|
||||
|
||||
// T022 UC-game-15 - testOpenLobbyMenuWithESC
|
||||
@Test
|
||||
public void testOpenLobbyMenuWithESC() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
app.simpleUpdate(0.1f);
|
||||
LobbyMenu lobbyMenu = app.getStateManager().getState(LobbyMenu.class);
|
||||
assertTrue(lobbyMenu.isVisible());
|
||||
}
|
||||
|
||||
// T023 UC-game-16 - testPlayerReadyConfirmation
|
||||
@Test
|
||||
public void testPlayerReadyConfirmation() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.setPlayerReady(true);
|
||||
assertTrue(lobby.isPlayerReady(0));
|
||||
}
|
||||
|
||||
// T024 UC-game-17 - testStartGame
|
||||
@Test
|
||||
public void testStartGame() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Lobby lobby = app.getStateManager().getState(Lobby.class);
|
||||
lobby.startGame();
|
||||
assertEquals(GameState.InGame, lobby.getGameState());
|
||||
}
|
||||
|
||||
// T025 UC-game-18 - testPlayerMovement
|
||||
@Test
|
||||
public void testPlayerMovement() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
player.move(5);
|
||||
assertEquals(5, player.getPosition());
|
||||
}
|
||||
|
||||
// T026 UC-game-19 - testPurchaseProperty
|
||||
@Test
|
||||
public void testPurchaseProperty() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
Property property = game.getProperty(0);
|
||||
player.buyProperty(property);
|
||||
assertTrue(player.getProperties().contains(property));
|
||||
}
|
||||
|
||||
// T027 UC-game-20 - testMovePlayerOnDiceRoll
|
||||
@Test
|
||||
public void testMovePlayerOnDiceRoll() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
int initialPosition = player.getPosition();
|
||||
player.rollDice();
|
||||
assertTrue(player.getPosition() > initialPosition);
|
||||
}
|
||||
|
||||
// T028 UC-game-21 - testPassGo
|
||||
@Test
|
||||
public void testPassGo() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
player.move(40); // Assuming 40 steps moves player to Go
|
||||
assertTrue(player.passedGo());
|
||||
}
|
||||
|
||||
// T029 UC-game-22 - testCollectMoneyFromGo
|
||||
@Test
|
||||
public void testCollectMoneyFromGo() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
int initialBalance = player.getBalance();
|
||||
player.move(40); // Move to Go
|
||||
assertTrue(player.getBalance() > initialBalance);
|
||||
}
|
||||
|
||||
// T030 UC-game-23 - testPayRent
|
||||
@Test
|
||||
public void testPayRent() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
PropertyField property = (PropertyField) game.getField(1);
|
||||
player.move(1);
|
||||
int initialBalance = player.getBalance();
|
||||
player.payRent(property);
|
||||
assertTrue(player.getBalance() < initialBalance);
|
||||
}
|
||||
|
||||
// T031 UC-game-24 - testDeclareBankruptcy
|
||||
@Test
|
||||
public void testDeclareBankruptcy() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
player.declareBankruptcy();
|
||||
assertEquals(PlayerState.Bankrupt, player.getState());
|
||||
}
|
||||
|
||||
// T032 UC-game-25 - testTradeProperty
|
||||
@Test
|
||||
public void testTradeProperty() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player1 = game.getPlayer(0);
|
||||
Player player2 = game.getPlayer(1);
|
||||
Property property = game.getProperty(0);
|
||||
player1.offerTrade(player2, property);
|
||||
assertTrue(player2.hasProperty(property));
|
||||
}
|
||||
|
||||
// T033 UC-game-26 - testGameOverCondition
|
||||
@Test
|
||||
public void testGameOverCondition() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
player.declareBankruptcy();
|
||||
assertTrue(game.isGameOver());
|
||||
}
|
||||
|
||||
// T034 UC-game-27 - testPlayerInJail
|
||||
@Test
|
||||
public void testPlayerInJail() {
|
||||
MonopolyApp app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
Game game = app.getStateManager().getState(Game.class);
|
||||
Player player = game.getPlayer(0);
|
||||
game.sendToJail(player);
|
||||
assertEquals(PlayerState.InJail, player.getState());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,106 +1,30 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import com.jme3.input.KeyInput;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.Node;
|
||||
import com.simsilica.lemur.Button;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class ClientLogicTest {
|
||||
|
||||
private MonopolyApp app;
|
||||
private Node guiNodeMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Erstelle eine Mock-Instanz der MonopolyApp
|
||||
app = spy(new MonopolyApp());
|
||||
|
||||
// Mock GuiNode
|
||||
guiNodeMock = mock(Node.class);
|
||||
doReturn(guiNodeMock).when(app).getGuiNode();
|
||||
|
||||
// Initialisiere die App
|
||||
doNothing().when(app).simpleInitApp();
|
||||
app = new MonopolyApp();
|
||||
app.simpleInitApp();
|
||||
}
|
||||
|
||||
@Test
|
||||
// T001: UC-game-01 - Überprüft, ob die Anwendung erfolgreich gestartet wird und das Hauptmenü angezeigt wird
|
||||
public void testStartApplication() {
|
||||
// Mock des Hauptmenü-Kindes
|
||||
Spatial mainMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("MainMenu")).thenReturn(mainMenuMock);
|
||||
|
||||
// Test, ob das Hauptmenü angezeigt wird
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte sichtbar sein", mainMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü nach dem Start der Anwendung angezeigt wird
|
||||
public void testOpenStartMenu() {
|
||||
// Mock des Startmenü-Kindes
|
||||
Spatial startMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("StartMenu")).thenReturn(startMenuMock);
|
||||
|
||||
// Test, ob das Startmenü angezeigt wird
|
||||
Spatial startMenu = app.getGuiNode().getChild("StartMenu");
|
||||
assertNotNull("Das Startmenü sollte sichtbar sein", startMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T003: UC-game-03 - Überprüft, ob der „Spiel starten“-Button das Spielerstellungsmenü öffnet
|
||||
public void testNavigateToPlayOption() {
|
||||
// Mock des Spielerstellungsmenü-Kindes
|
||||
Spatial playMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("PlayMenu")).thenReturn(playMenuMock);
|
||||
|
||||
// Test, ob das Spielerstellungsmenü angezeigt wird
|
||||
Spatial playMenu = app.getGuiNode().getChild("PlayMenu");
|
||||
assertNotNull("Das Spielerstellungsmenü sollte sichtbar sein", playMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T004: UC-game-04 - Testet, ob die Anwendung geschlossen wird, wenn „Beenden“ im Hauptmenü gewählt wird
|
||||
public void testExitApplicationFromMenu() {
|
||||
// Simuliere den Schließen-Aufruf
|
||||
doNothing().when(app).closeApp();
|
||||
|
||||
// Rufe die Schließen-Methode auf
|
||||
app.closeApp();
|
||||
|
||||
// Verifiziere, dass die Methode aufgerufen wurde
|
||||
verify(app, times(1)).closeApp();
|
||||
}
|
||||
|
||||
@Test
|
||||
// T005: UC-game-05 - Überprüft, ob das Einstellungen-Menü aus dem Hauptmenü aufgerufen werden kann
|
||||
public void testOpenSettingsFromMenu() {
|
||||
// Mock des Einstellungsmenü-Kindes
|
||||
Spatial settingsMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("SettingsMenu")).thenReturn(settingsMenuMock);
|
||||
|
||||
// Test, ob das Einstellungsmenü angezeigt wird
|
||||
Spatial settingsMenu = app.getGuiNode().getChild("SettingsMenu");
|
||||
assertNotNull("Das Einstellungsmenü sollte sichtbar sein", settingsMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T006: UC-game-06 - Testet, ob das Spielmenü geöffnet wird, wenn der Spieler im Spiel „ESC“ drückt
|
||||
public void testOpenGameMenuWithESC() {
|
||||
// Simuliere den ESC-Tastendruck
|
||||
doNothing().when(app).handleEscape(true);
|
||||
|
||||
// Rufe die ESC-Tastenmethode auf
|
||||
app.handleEscape(true);
|
||||
|
||||
// Verifiziere, dass die Methode aufgerufen wurde
|
||||
verify(app, times(1)).handleEscape(true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü nach dem Start der Anwendung angezeigt wird
|
||||
@@ -109,7 +33,6 @@ public class ClientLogicTest {
|
||||
assertNotNull("Das Startmenü sollte sichtbar sein", startMenu);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü (MainMenu) angezeigt wird und die Buttons korrekt funktionieren
|
||||
public void testMainMenuButtons() {
|
||||
@@ -235,5 +158,4 @@ public void testMainMenuButtons() {
|
||||
throw new AssertionError("'ReturnButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@@ -1,123 +1,606 @@
|
||||
package pp.monopoly.game.client;
|
||||
/*
|
||||
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
import pp.monopoly.client.ClientSender;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests the client-side logic of the Monopoly game.
|
||||
*/
|
||||
/*
|
||||
public class ClientGameLogicTest {
|
||||
|
||||
private ClientGameLogic logic;
|
||||
private MonopolyApp app;
|
||||
|
||||
@Mock
|
||||
private MonopolyServer serverMock;
|
||||
|
||||
@Mock
|
||||
private ClientSender clientSenderMock;
|
||||
private MonopolyApp app;
|
||||
private NewGameMenu newGameMenu;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
logic = new ClientGameLogic(clientSenderMock);
|
||||
app = new MonopolyApp();
|
||||
app.simpleInitApp(); // Initialisiert die App mit GUI und Spielzuständen
|
||||
newGameMenu = new NewGameMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
// T006: UC-game-06 - Testet, ob das Spielmenü geöffnet wird, wenn der Spieler im Spiel „ESC“ drückt
|
||||
public void testOpenGameMenuWithESC() {
|
||||
app.escape(true); // Simuliert das Drücken der ESC-Taste
|
||||
|
||||
Spatial gameMenu = app.getGuiNode().getChild("GameMenu");
|
||||
assertNotNull("Das Spielmenü sollte sichtbar sein, nachdem ESC gedrückt wurde", gameMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T007: UC-game-07 - Testet, ob der Spieler erfolgreich den Namen des Hosts eingeben kann
|
||||
public void testEnterHostName() {
|
||||
String hostName = "localhost";
|
||||
logic.setHostName(hostName);
|
||||
Spatial hostNameField = app.getGuiNode().getChild("HostNameField");
|
||||
assertNotNull("Das Eingabefeld für den Hostnamen sollte sichtbar sein", hostNameField);
|
||||
|
||||
assertEquals("The hostname should be correctly set.", hostName, logic.getHostName());
|
||||
if (hostNameField instanceof TextField) {
|
||||
TextField hostNameInput = (TextField) hostNameField;
|
||||
hostNameInput.setText("TestHost");
|
||||
|
||||
assertEquals("Der eingegebene Hostname sollte 'TestHost' sein", "TestHost", hostNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'HostNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T008: UC-game-08 - Testet, ob der Spieler die Portnummer des Hosts eingeben kann
|
||||
public void testEnterPortNumber() {
|
||||
int portNumber = 12345;
|
||||
logic.setPortNumber(portNumber);
|
||||
Spatial portNumberField = app.getGuiNode().getChild("PortNumberField");
|
||||
assertNotNull("Das Eingabefeld für die Portnummer sollte sichtbar sein", portNumberField);
|
||||
|
||||
assertEquals("The port number should be correctly set.", portNumber, logic.getPortNumber());
|
||||
if (portNumberField instanceof TextField) {
|
||||
TextField portNumberInput = (TextField) portNumberField;
|
||||
portNumberInput.setText("12345");
|
||||
|
||||
assertEquals("Die eingegebene Portnummer sollte '12345' sein", "12345", portNumberInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PortNumberField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T009: UC-game-09 - Testet, ob der Spieler das Erstellen eines Spiels abbrechen kann
|
||||
public void testCancelGameCreation() {
|
||||
doNothing().when(clientSenderMock).returnToMainMenu();
|
||||
Spatial cancelButtonSpatial = app.getGuiNode().getChild("CancelButton");
|
||||
assertNotNull("Der 'Abbrechen'-Button sollte existieren", cancelButtonSpatial);
|
||||
|
||||
logic.cancelGameCreation();
|
||||
if (cancelButtonSpatial instanceof Button) {
|
||||
Button cancelButton = (Button) cancelButtonSpatial;
|
||||
cancelButton.click();
|
||||
|
||||
verify(clientSenderMock, times(1)).returnToMainMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterPlayerLobby() {
|
||||
doNothing().when(clientSenderMock).enterLobby();
|
||||
|
||||
logic.enterLobby();
|
||||
|
||||
verify(clientSenderMock, times(1)).enterLobby();
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte nach dem Abbrechen des Spiels sichtbar sein", mainMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'CancelButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
// T010: UC-game-10 - Testet, ob der Spieler die Spielerlobby betreten kann
|
||||
public void testEnterPlayerLobby() {
|
||||
app.receivedEvent(new pp.monopoly.notification.ClientStateEvent(pp.monopoly.notification.ClientStateEvent.State.LOBBY));
|
||||
|
||||
Spatial playerLobby = app.getGuiNode().getChild("PlayerLobby");
|
||||
assertNotNull("Die Spielerlobby sollte nach dem Beitritt sichtbar sein", playerLobby);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
// T010: UC-game-10 - Testet, ob der Spieler die Spielerlobby betreten kann
|
||||
public void testEnterPlayerLobby() {
|
||||
// Simuliert den Empfang eines ClientStateEvent für den Lobby-State
|
||||
app.receivedEvent(new ClientStateEvent(ClientStateEvent.State.LOBBY));
|
||||
|
||||
// Überprüft, ob das Lobby-UI sichtbar ist
|
||||
Spatial playerLobby = app.getGuiNode().getChild("PlayerLobby");
|
||||
assertNotNull("Die Spielerlobby sollte nach dem Beitritt sichtbar sein", playerLobby);
|
||||
*/
|
||||
@Test
|
||||
// T011: UC-game-11 - Testet, ob der hostende Spieler einen Startbetrag eingeben kann
|
||||
public void testEnterStartingCapital() {
|
||||
int startingCapital = 1500;
|
||||
logic.setStartingCapital(startingCapital);
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
assertNotNull("Das Eingabefeld für den Startbetrag sollte existieren", startingCapitalField);
|
||||
|
||||
assertEquals("The starting capital should be correctly set.", startingCapital, logic.getStartingCapital());
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
startingCapitalInput.setText("1500");
|
||||
|
||||
assertEquals("Der eingegebene Startbetrag sollte '1500' sein", "1500", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T012: UC-game-12 - Testet, ob der Spieler den Startbetrag um 100 € erhöhen kann
|
||||
public void testIncreaseStartingCapital() {
|
||||
logic.setStartingCapital(1500);
|
||||
logic.increaseStartingCapital();
|
||||
Spatial increaseButton = app.getGuiNode().getChild("IncreaseCapitalButton");
|
||||
assertNotNull("Der 'Erhöhen'-Button sollte existieren", increaseButton);
|
||||
|
||||
assertEquals("The starting capital should increase by 100.", 1600, logic.getStartingCapital());
|
||||
if (increaseButton instanceof Button) {
|
||||
Button increaseCapitalButton = (Button) increaseButton;
|
||||
increaseCapitalButton.click();
|
||||
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
assertEquals("Der Startbetrag sollte um 100 erhöht worden sein", "1600", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'IncreaseCapitalButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T013: UC-game-13 - Testet, ob der Spieler den Startbetrag um 100 € senken kann
|
||||
public void testDecreaseStartingCapital() {
|
||||
logic.setStartingCapital(1500);
|
||||
logic.decreaseStartingCapital();
|
||||
Spatial decreaseButton = app.getGuiNode().getChild("DecreaseCapitalButton");
|
||||
assertNotNull("Der 'Senken'-Button sollte existieren", decreaseButton);
|
||||
|
||||
assertEquals("The starting capital should decrease by 100.", 1400, logic.getStartingCapital());
|
||||
if (decreaseButton instanceof Button) {
|
||||
Button decreaseCapitalButton = (Button) decreaseButton;
|
||||
decreaseCapitalButton.click();
|
||||
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
assertEquals("Der Startbetrag sollte um 100 gesenkt worden sein", "1400", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'DecreaseCapitalButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T014: UC-game-14 - Testet, ob die Standard-Spielernamen korrekt voreingestellt sind
|
||||
public void testDefaultPlayerName() {
|
||||
logic.addPlayer("Player 1");
|
||||
Spatial playerNameField = app.getGuiNode().getChild("PlayerNameField");
|
||||
assertNotNull("Das Eingabefeld für den Spielernamen sollte existieren", playerNameField);
|
||||
|
||||
assertTrue("The player name should be correctly set.", logic.getPlayerNames().contains("Player 1"));
|
||||
if (playerNameField instanceof TextField) {
|
||||
TextField playerNameInput = (TextField) playerNameField;
|
||||
assertEquals("Der voreingestellte Spielername sollte 'Spieler 1' sein", "Spieler 1", playerNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PlayerNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T015: UC-game-15 - Testet, ob der Spieler einen Anzeigenamen eingeben kann
|
||||
public void testEnterDisplayName() {
|
||||
String displayName = "JohnDoe";
|
||||
logic.setPlayerName(displayName);
|
||||
Spatial displayNameField = app.getGuiNode().getChild("DisplayNameField");
|
||||
assertNotNull("Das Eingabefeld für den Anzeigenamen sollte existieren", displayNameField);
|
||||
|
||||
assertEquals("The display name should be correctly set.", displayName, logic.getPlayerName());
|
||||
if (displayNameField instanceof TextField) {
|
||||
TextField displayNameInput = (TextField) displayNameField;
|
||||
displayNameInput.setText("MaxMustermann");
|
||||
|
||||
assertEquals("Der eingegebene Anzeigename sollte 'MaxMustermann' sein", "MaxMustermann", displayNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'DisplayNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T016: UC-game-16 - Testet, ob eine Warnung angezeigt wird, wenn ein Spieler einen bereits belegten Namen eingibt
|
||||
public void testDuplicateNameEntry() {
|
||||
logic.addPlayer("Player 1");
|
||||
boolean result = logic.addPlayer("Player 1");
|
||||
Spatial playerNameField = app.getGuiNode().getChild("PlayerNameField");
|
||||
assertNotNull("Das Eingabefeld für den Spielernamen sollte existieren", playerNameField);
|
||||
|
||||
assertTrue("Duplicate names should not be allowed.", !result);
|
||||
if (playerNameField instanceof TextField) {
|
||||
TextField playerNameInput = (TextField) playerNameField;
|
||||
playerNameInput.setText("Spieler 1");
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler hinzufügen
|
||||
playerNameInput.setText("Spieler 1");
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler mit gleichem Namen hinzufügen
|
||||
|
||||
Spatial warning = app.getGuiNode().getChild("DuplicateNameWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn ein Name doppelt vergeben wird", warning);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PlayerNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T017: UC-game-17 - Testet, ob der Spieler eine verfügbare Spielfigurfarbe auswählen kann
|
||||
public void testSelectPlayerColor() {
|
||||
logic.addPlayer("Player 1");
|
||||
boolean result = logic.setPlayerColor("Player 1", "Red");
|
||||
Spatial colorSelector = app.getGuiNode().getChild("ColorSelector");
|
||||
assertNotNull("Der Farbwähler sollte existieren", colorSelector);
|
||||
|
||||
assertTrue("The player should be able to select an available color.", result);
|
||||
if (colorSelector instanceof Button) {
|
||||
Button colorButton = (Button) colorSelector;
|
||||
colorButton.click();
|
||||
|
||||
Spatial selectedColor = app.getGuiNode().getChild("SelectedColor");
|
||||
assertNotNull("Die gewählte Farbe sollte sichtbar sein", selectedColor);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'ColorSelector' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T018: UC-game-18 - Testet, ob eine belegte Spielfigurfarbe nicht ausgewählt werden kann
|
||||
public void testSelectOccupiedColor() {
|
||||
app.getGuiNode().getChild("ColorSelectorRed").click(); // Spieler 1 wählt Rot
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler 1 hinzufügen
|
||||
|
||||
app.getGuiNode().getChild("ColorSelectorRed").click(); // Spieler 2 versucht Rot zu wählen
|
||||
Spatial warning = app.getGuiNode().getChild("ColorOccupiedWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn eine belegte Farbe ausgewählt wird", warning);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T019: UC-game-19 - Testet, ob der Spieler eine Spielfigur auswählen kann
|
||||
public void testSelectPlayerToken() {
|
||||
Spatial tokenSelector = app.getGuiNode().getChild("TokenSelector");
|
||||
assertNotNull("Der Token-Wähler sollte existieren", tokenSelector);
|
||||
|
||||
if (tokenSelector instanceof Button) {
|
||||
Button tokenButton = (Button) tokenSelector;
|
||||
tokenButton.click();
|
||||
|
||||
Spatial selectedToken = app.getGuiNode().getChild("SelectedToken");
|
||||
assertNotNull("Die gewählte Spielfigur sollte sichtbar sein", selectedToken);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'TokenSelector' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T020: UC-game-20 - Testet, ob eine belegte Spielfigur nicht ausgewählt werden kann
|
||||
public void testSelectOccupiedToken() {
|
||||
app.getGuiNode().getChild("TokenSelectorShip").click();
|
||||
app.getGuiNode().getChild("AddPlayerButton").click();
|
||||
|
||||
app.getGuiNode().getChild("TokenSelectorShip").click();
|
||||
Spatial warning = app.getGuiNode().getChild("TokenOccupiedWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn eine belegte Spielfigur ausgewählt wird", warning);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T021: UC-game-14 - Überprüft, ob der Spieler zur „Spiel erstellen“-Ansicht zurückkehrt, wenn Abbrechen gedrückt wird
|
||||
public void testCancelPlayerLobby() {
|
||||
Spatial cancelButtonSpatial = app.getGuiNode().getChild("CancelLobbyButton");
|
||||
assertNotNull("Der 'Abbrechen'-Button in der Lobby sollte existieren", cancelButtonSpatial);
|
||||
|
||||
if (cancelButtonSpatial instanceof Button) {
|
||||
Button cancelButton = (Button) cancelButtonSpatial;
|
||||
cancelButton.click();
|
||||
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte nach dem Abbrechen der Lobby sichtbar sein", mainMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'CancelLobbyButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T022: UC-game-15 - Überprüft, ob das Spielmenü in der Lobby durch Drücken der ESC-Taste geöffnet wird
|
||||
public void testOpenLobbyMenuWithESC() {
|
||||
app.escape(true); // Simuliert das Drücken der ESC-Taste
|
||||
|
||||
Spatial lobbyMenu = app.getGuiNode().getChild("LobbyMenu");
|
||||
assertNotNull("Das Lobby-Menü sollte sichtbar sein, nachdem ESC in der Lobby gedrückt wurde", lobbyMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T023: UC-game-16 - Testet, ob der Spieler die Auswahl der Spielfigur bestätigen kann
|
||||
public void testPlayerReadyConfirmation() {
|
||||
Spatial confirmButtonSpatial = app.getGuiNode().getChild("ConfirmTokenButton");
|
||||
assertNotNull("Der 'Bestätigen'-Button für die Spielfigur sollte existieren", confirmButtonSpatial);
|
||||
|
||||
if (confirmButtonSpatial instanceof Button) {
|
||||
Button confirmButton = (Button) confirmButtonSpatial;
|
||||
confirmButton.click();
|
||||
|
||||
Spatial readyStatus = app.getGuiNode().getChild("PlayerReadyStatus");
|
||||
assertNotNull("Der Status 'Bereit' sollte angezeigt werden, nachdem die Spielfigur bestätigt wurde", readyStatus);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'ConfirmTokenButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
@Test
|
||||
// T024: UC-game-16 - Überprüft, ob das Spiel startet, wenn alle Spieler ihre Auswahl bestätigt haben
|
||||
public void testAllPlayersReady() {
|
||||
app.receivedEvent(new pp.monopoly.notification.ClientStateEvent(pp.monopoly.notification.ClientStateEvent.State.ALL_PLAYERS_READY));
|
||||
|
||||
Spatial gameScreen = app.getGuiNode().getChild("GameScreen");
|
||||
assertNotNull("Das Spiel sollte starten, wenn alle Spieler bereit sind", gameScreen);
|
||||
}
|
||||
@Test
|
||||
// T025: UC-game-17 - Testet, ob das Einstellungen-Menü während des Spiels geöffnet wird
|
||||
public void testOpenMainGameSettings () {
|
||||
app.escape(true);
|
||||
|
||||
Spatial settingsButton = app.getGuiNode().getChild("SettingsButton");
|
||||
assertNotNull("Der 'Einstellungen'-Button sollte im Spielmenü vorhanden sein", settingsButton);
|
||||
|
||||
if (settingsButton instanceof Button) {
|
||||
((Button) settingsButton).click();
|
||||
Spatial settingsMenu = app.getGuiNode().getChild("SettingsMenu");
|
||||
assertNotNull("Das Einstellungen-Menü sollte im Spiel angezeigt werden", settingsMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'SettingsButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T026: UC-gameplay-01 - Überprüft, ob der Spieler erfolgreich würfeln kann
|
||||
public void testRollDice() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
Spatial diceResult = app.getGuiNode().getChild("DiceResult");
|
||||
assertNotNull("Das Ergebnis des Würfelwurfs sollte angezeigt werden", diceResult);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
// T027: UC-gameplay-01 - Überprüft, ob der aktive Spieler die richtige Anzahl an Feldern basierend auf dem Wurf bewegt
|
||||
public void testMovePlayerAutomatically() {
|
||||
Game game = new Game(); // Initialisiert ein neues Spiel
|
||||
PlayerHandler playerHandler = game.getPlayerHandler(); // Holt den PlayerHandler, der die Spieler verwaltet
|
||||
|
||||
Player activePlayer = playerHandler.getActivePlayer(); // Holt den aktuellen aktiven Spieler
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
DiceResult diceResult = game.rollDice(); // Würfelwurf simulieren
|
||||
int steps = diceResult.getTotal();
|
||||
|
||||
int initialPosition = activePlayer.getFieldId(); // Ursprüngliche Position des aktiven Spielers
|
||||
playerHandler.moveActivePlayer(steps); // Bewegt den aktiven Spieler basierend auf dem Wurf
|
||||
|
||||
int expectedPosition = (initialPosition + steps) % game.getGameBoard().getNumberOfFields(); // Zielposition berechnen
|
||||
int newPosition = activePlayer.getFieldId();
|
||||
|
||||
assertEquals("Der aktive Spieler sollte sich korrekt bewegen", expectedPosition, newPosition);
|
||||
|
||||
// Überprüfen, dass alle anderen Spieler im WaitForTurn-State bleiben
|
||||
playerHandler.getPlayers().stream()
|
||||
.filter(player -> player != activePlayer)
|
||||
.forEach(player -> assertTrue("Andere Spieler sollten im WaitForTurn-State sein", player.getState() instanceof WaitForTurnState));
|
||||
}
|
||||
|
||||
@Test
|
||||
// T028: UC-gameplay-02 - Überprüft, ob die Würfel zufällige Zahlen generieren
|
||||
public void testGenerationDice() {
|
||||
boolean isRandom = false;
|
||||
DiceResult previousResult = null;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
DiceResult currentResult = app.getGame().rollDice();
|
||||
|
||||
assertNotNull("Das Würfelergebnis sollte nicht null sein", currentResult);
|
||||
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", currentResult.getDice1() >= 1 && currentResult.getDice1() <= 6);
|
||||
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", currentResult.getDice2() >= 1 && currentResult.getDice2() <= 6);
|
||||
|
||||
if (previousResult != null && (currentResult.getDice1() != previousResult.getDice1() || currentResult.getDice2() != previousResult.getDice2())) {
|
||||
isRandom = true; // Unterschiedliche Würfelwerte gefunden
|
||||
break;
|
||||
}
|
||||
previousResult = currentResult;
|
||||
}
|
||||
assertTrue("Die Würfelergebnisse sollten zufällig sein", isRandom);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T029: UC-gameplay-03 - Überprüft, ob die richtigen Augenzahlen angezeigt werden
|
||||
public void testDisplayResults() {
|
||||
DiceResult result = app.getGame().rollDice();
|
||||
|
||||
assertNotNull("Das Würfelergebnis sollte nicht null sein", result);
|
||||
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", result.getDice1() >= 1 && result.getDice1() <= 6);
|
||||
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", result.getDice2() >= 1 && result.getDice2() <= 6);
|
||||
assertEquals("Die Summe sollte korrekt berechnet werden", result.getDice1() + result.getDice2(), result.getTotal());
|
||||
}
|
||||
@Test
|
||||
// T030: UC-gameplay-04 - Überprüfen, ob die Summe der Würfelergebnisse korrekt berechnet wird
|
||||
public void testSumDiceResults() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
assertNotNull("Die Ergebnisse des Würfelwurfs sollten angezeigt werden", diceResult1);
|
||||
assertNotNull("Die Ergebnisse des Würfelwurfs sollten angezeigt werden", diceResult2);
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
int expectedSum = result1 + result2;
|
||||
|
||||
Spatial sumDisplay = app.getGuiNode().getChild("DiceSum");
|
||||
assertEquals("Die Summe der Würfelergebnisse sollte korrekt angezeigt werden", expectedSum, Integer.parseInt(sumDisplay.getUserData("value").toString()));
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T031: UC-gameplay-05 - Überprüfen, ob die Würfel nach dem Wurf ausgegraut werden
|
||||
public void testGrayOutDiceAfterRoll() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
|
||||
Spatial diceDisplay = app.getGuiNode().getChild("DiceDisplay");
|
||||
assertNotNull("Die Würfelanzeige sollte nach dem Wurf sichtbar sein", diceDisplay);
|
||||
|
||||
boolean isGrayedOut = diceDisplay.getUserData("grayedOut");
|
||||
assertTrue("Die Würfel sollten nach dem Wurf ausgegraut sein", isGrayedOut);
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T032: UC-gameplay-06 - Überprüfen, ob das Würfeln eines Paschs erkannt wird
|
||||
public void testDetectDouble() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
// Simuliert mehrere Würfe, um einen Pasch zu erkennen
|
||||
for (int i = 0; i < 10; i++) {
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) {
|
||||
Spatial doubleIndicator = app.getGuiNode().getChild("DoubleIndicator");
|
||||
assertNotNull("Ein Pasch sollte angezeigt werden, wenn zwei identische Zahlen geworfen werden", doubleIndicator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T033: UC-gameplay-06 - Überprüfen, ob der Spieler bei einem Pasch erneut würfeln darf
|
||||
public void testDoubleRoll() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
// Simuliert das Würfeln eines Paschs
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) { // Überprüft, ob ein Pasch geworfen wurde
|
||||
Spatial rollAgainIndicator = app.getGuiNode().getChild("RollAgainIndicator");
|
||||
assertNotNull("Der Spieler sollte bei einem Pasch erneut würfeln dürfen", rollAgainIndicator);
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T034: UC-gameplay-06 - Überprüfen, ob der Spieler nach dem dritten Pasch ins Gefängnis muss
|
||||
public void testTripleDoubleGulag() {
|
||||
int doubleCount = 0;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) {
|
||||
doubleCount++;
|
||||
}
|
||||
|
||||
if (doubleCount == 3) {
|
||||
Spatial jailIndicator = app.getGuiNode().getChild("JailIndicator");
|
||||
assertNotNull("Der Spieler sollte nach dem dritten Pasch ins Gefängnis gehen", jailIndicator);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Der Spieler sollte drei Paschs geworfen haben", doubleCount == 3);
|
||||
}
|
||||
@Test
|
||||
// T035: UC-gameplay-07 - Überprüfen, ob ein Spieler für Steuerfelder korrekt belastet wird
|
||||
public void testTaxFieldCharges() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
int initialBalance = activePlayer.getAccountBalance();
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(4)); // ID 4: Steuerfeld "Diszi"
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
int expectedBalance = initialBalance - 200; // Beispielsteuer: 200 €
|
||||
assertEquals("Der Spieler sollte für das Steuerfeld korrekt belastet werden", expectedBalance, activePlayer.getAccountBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T036: UC-gameplay-08 - Überprüfen, ob ein Spieler korrekt ins Gefängnis geschickt wird
|
||||
public void testGoToJailField() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(30)); // ID 30: Ab ins Gefängnis
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
assertEquals("Der Spieler sollte ins Gefängnis geschickt werden", 10, activePlayer.getFieldId()); // ID 10: Gefängnis
|
||||
}
|
||||
|
||||
@Test
|
||||
// T037: UC-gameplay-09 - Überprüfen, ob ein Spieler bei "Frei Parken" keine Gebühren zahlt
|
||||
public void testFreeParking() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
int initialBalance = activePlayer.getAccountBalance();
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(20)); // ID 20: Frei Parken
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
assertEquals("Der Spieler sollte bei 'Frei Parken' keine Gebühren zahlen", initialBalance, activePlayer.getAccountBalance());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -10,5 +10,5 @@
|
||||
# This file defines the configuration settings for the Battleship server.
|
||||
#
|
||||
# The port number on which the server will listen for incoming connections.
|
||||
port=1234
|
||||
port=42069
|
||||
|
||||
|
@@ -7,21 +7,6 @@
|
||||
|
||||
package pp.monopoly.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
import com.jme3.network.Message;
|
||||
import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
import com.jme3.network.Server;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
import pp.monopoly.game.server.ServerSender;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -31,6 +16,22 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
import com.jme3.network.Message;
|
||||
import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
import com.jme3.network.Server;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
import pp.monopoly.game.server.ServerSender;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
*/
|
||||
@@ -119,8 +120,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
|
||||
@Override
|
||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
||||
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
||||
logic.addPlayer(hostedConnection.getId());
|
||||
System.out.println("Spieler verbunden: ID = " + hostedConnection.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -25,7 +25,9 @@ dependencyResolutionManagement {
|
||||
library('jme3-effects', 'org.jmonkeyengine', 'jme3-effects').versionRef('jme')
|
||||
|
||||
library('lemur', 'com.simsilica:lemur:1.16.0')
|
||||
library('lemur-proto', 'com.simsilica:lemur-proto:1.13.0')
|
||||
library('lemurproto', 'com.simsilica:lemur-proto:1.13.0')
|
||||
|
||||
library('selenium', 'org.seleniumhq.selenium:selenium-java:4.11.0')
|
||||
|
||||
library('junit4', 'junit:junit:4.13.2')
|
||||
library('gson', 'com.google.code.gson:gson:2.11.0')
|
||||
|
Reference in New Issue
Block a user