Compare commits
32 Commits
f1d52c445b
...
b_schmidt_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c8da2f4a0 | ||
|
|
446cb43abb | ||
|
|
47610d9e11 | ||
|
|
563784dbab | ||
|
|
0e5ffcc501 | ||
|
|
1288d6d1ca | ||
|
|
520b98f693 | ||
|
|
8e02c3919e | ||
|
|
4df5a1a7d1 | ||
|
|
3bdc9c20dc | ||
|
|
f541f3edc0 | ||
|
|
c26d7b5422 | ||
|
|
2e294896d8 | ||
|
|
f02a3107a0 | ||
|
|
141d817421 | ||
|
|
fe1bf7746b | ||
|
|
2c7820491a | ||
|
|
2dd70c10b5 | ||
|
|
6475b63a22 | ||
|
|
ae41ec4007 | ||
|
|
b9309b6f5f | ||
|
|
ae5ba034fe | ||
|
|
682da199e8 | ||
|
|
8a7446d81c | ||
|
|
cb57187f98 | ||
|
|
958f4f6a13 | ||
|
|
af08a84dc3 | ||
|
|
53df6011db | ||
|
|
4bc3b3dc33 | ||
|
|
cf780f0995 | ||
|
|
05618c0793 | ||
|
|
3ee095215a |
@@ -7,14 +7,18 @@ description = 'Battleship Client'
|
||||
dependencies {
|
||||
implementation project(":jme-common")
|
||||
implementation project(":battleship:model")
|
||||
implementation 'org.jmonkeyengine:jme3-core:3.6.0-stable'
|
||||
implementation 'org.jmonkeyengine:jme3-effects:3.6.0-stable'
|
||||
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.jme3.effects
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
runtimeOnly libs.jme3.jogg
|
||||
runtimeOnly libs.jme3.testdata
|
||||
|
||||
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
import pp.battleship.client.gui.BattleAppState;
|
||||
import pp.battleship.client.gui.EditorAppState;
|
||||
import pp.battleship.client.gui.GameMusic;
|
||||
import pp.battleship.client.gui.SeaAppState;
|
||||
import pp.battleship.client.GameMusic;
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
import pp.battleship.game.client.ClientGameLogic;
|
||||
import pp.battleship.game.client.ServerConnection;
|
||||
@@ -269,6 +269,7 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
|
||||
attachGameSound();
|
||||
attachGameMusic();
|
||||
|
||||
stateManager.attachAll(new EditorAppState(), new BattleAppState(), new SeaAppState());
|
||||
}
|
||||
|
||||
@@ -283,12 +284,12 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches the background music state and sets its initial enabled state.
|
||||
* Attaches the music state and sets its initial enabled state.
|
||||
*/
|
||||
private void attachGameMusic() {
|
||||
final GameMusic gameSound = new GameMusic();
|
||||
gameSound.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameSound);
|
||||
final GameMusic gameMusic = new GameMusic();
|
||||
gameMusic.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameMusic);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package pp.battleship.client.gui;
|
||||
package pp.battleship.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;
|
||||
@@ -14,16 +9,25 @@ import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
* Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio.
|
||||
* An application state that plays music.
|
||||
*/
|
||||
public class GameMusic extends AbstractAppState{
|
||||
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;
|
||||
private AudioNode battleMusic;
|
||||
private AudioNode menuMusicModern;
|
||||
private AudioNode menuMusicTraditional;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
@@ -33,18 +37,47 @@ public class GameMusic extends AbstractAppState{
|
||||
public static boolean enabledInPreferences() {
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
/**
|
||||
* Checks enabled volume in preferences.
|
||||
*
|
||||
* @return {@code float} if a volumePreference is set, the volume is set to the Value in PREFERENCES,
|
||||
* {@code 0.25f} if no volumePreference is set in PREFERENCES, the Volume is set to a default of 0.25f
|
||||
*
|
||||
* @return float to which the volume is set
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
|
||||
public static float volumePreference() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.25f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the sound effects for the game.
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
else if (!isEnabled() && enabled) {
|
||||
if (menuMusicModern != null) menuMusicModern.play();
|
||||
} else if (isEnabled() && !enabled) {
|
||||
if (menuMusicModern != null) menuMusicModern.stop();
|
||||
}
|
||||
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Music enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the music.
|
||||
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
|
||||
*
|
||||
* @param stateManager The state manager
|
||||
@@ -53,16 +86,17 @@ public class GameMusic extends AbstractAppState{
|
||||
@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();
|
||||
menuMusicModern =loadSound(app, "Sound/BackgroundMusic/menu-music-modern.ogg");
|
||||
setVolume(volumePreference());
|
||||
menuMusicModern.setLooping(true);
|
||||
if (isEnabled() && menuMusicModern != null) {
|
||||
menuMusicModern.play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a sound from the specified file.
|
||||
* Loads the music from the specified file.
|
||||
*
|
||||
* @param app The application
|
||||
* @param name The name of the sound file.
|
||||
@@ -82,41 +116,14 @@ public class GameMusic extends AbstractAppState{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
* Sets the vol param to the level set in PREFERENCES
|
||||
*
|
||||
* @param vol Volume level of the music as indicated by the Volume control Slider
|
||||
*
|
||||
* @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);
|
||||
menuMusicModern.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,7 +34,6 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
private AudioNode splashSound;
|
||||
private AudioNode shipDestroyedSound;
|
||||
private AudioNode explosionSound;
|
||||
private AudioNode shellFlyingSound;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
@@ -79,7 +78,6 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS
|
||||
splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS
|
||||
explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS
|
||||
shellFlyingSound = loadSound(app, "Sound/Effects/shell_flying.wav");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,27 +124,12 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
shipDestroyedSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the shell flying sound effect.
|
||||
*/
|
||||
public void shellFly() {
|
||||
if (isEnabled() && shellFlyingSound != null) {
|
||||
shellFlyingSound.playInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a recieved {@code SoundEvent} and plays the according sound.
|
||||
*
|
||||
* @param event the Sound event to be processed
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(SoundEvent event) {
|
||||
switch (event.sound()) {
|
||||
case EXPLOSION -> explosion();
|
||||
case SPLASH -> splash();
|
||||
case DESTROYED_SHIP -> shipDestroyed();
|
||||
case SHELL_FLYING -> shellFly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,20 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import pp.battleship.client.gui.GameMusic;
|
||||
import pp.battleship.client.gui.VolumeSlider;
|
||||
import pp.battleship.client.gui.VolumeControl;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.dialog.TextInputDialog;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
@@ -35,29 +34,35 @@ class Menu extends Dialog {
|
||||
private final BattleshipApp app;
|
||||
private final Button loadButton = new Button(lookup("menu.map.load"));
|
||||
private final Button saveButton = new Button(lookup("menu.map.save"));
|
||||
private final VolumeSlider slider;
|
||||
private final VolumeControl volumeSlider;
|
||||
|
||||
/**
|
||||
* Constructs the Menu dialog for the Battleship application.+
|
||||
* Constructs the Menu dialog for the Battleship application.
|
||||
*
|
||||
* @param app the BattleshipApp instance
|
||||
*/
|
||||
public Menu(BattleshipApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
||||
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header")));//NON-NLS
|
||||
|
||||
addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||
|
||||
addChild(slider);
|
||||
|
||||
addChild(loadButton).addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton).addClickCommands(s -> ifTopDialog(this::saveDialog));
|
||||
addChild(new Button(lookup("menu.return-to-game"))).addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button(lookup("menu.quit"))).addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
|
||||
volumeSlider = new VolumeControl(app.getStateManager().getState(GameMusic.class));
|
||||
|
||||
addChild(volumeSlider);
|
||||
|
||||
addChild(loadButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::saveDialog));
|
||||
addChild(new Button(lookup("menu.return-to-game")))
|
||||
.addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button(lookup("menu.quit")))
|
||||
.addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -70,11 +75,15 @@ class Menu extends Dialog {
|
||||
saveButton.setEnabled(app.getGameLogic().maySaveMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position of the volume control slider.
|
||||
*/
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
slider.update();
|
||||
volumeSlider.update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* As an escape action, this method closes the menu if it is the top dialog.
|
||||
*/
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import pp.battleship.server.BattleshipServer;
|
||||
import pp.battleship.client.server.BattleshipSelfhostServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
@@ -36,8 +35,7 @@ class NetworkDialog extends SimpleDialog {
|
||||
private final NetworkSupport network;
|
||||
private final TextField host = new TextField(LOCALHOST);
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
// private final Button serverButton = new Button(lookup("client.server-star"));
|
||||
private final Button serverButton = new Button(lookup("client.server-start"));
|
||||
private static final Checkbox HOST = new Checkbox(lookup("server.host"));
|
||||
private String hostname;
|
||||
private int portNumber;
|
||||
private Future<Object> connectionFuture;
|
||||
@@ -61,6 +59,7 @@ class NetworkDialog extends SimpleDialog {
|
||||
input.addChild(host, 1);
|
||||
input.addChild(new Label(lookup("port.number") + ": "));
|
||||
input.addChild(port, 1);
|
||||
input.addChild(HOST).addClickCommands(s -> ifTopDialog(this::startClientServer));
|
||||
|
||||
DialogBuilder.simple(app.getDialogManager())
|
||||
.setTitle(lookup("server.dialog"))
|
||||
@@ -70,9 +69,6 @@ class NetworkDialog extends SimpleDialog {
|
||||
.setOkClose(false)
|
||||
.setNoClose(false)
|
||||
.build(this);
|
||||
|
||||
//Add the button to start the sever
|
||||
addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,15 +156,15 @@ class NetworkDialog extends SimpleDialog {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the server in a separate thread.
|
||||
* Starts the server of the client in a new thread and catches connectivity issues.
|
||||
*/
|
||||
private void startServerInThread() {
|
||||
serverButton.setEnabled(false);
|
||||
private void startClientServer() {
|
||||
HOST.setEnabled(false);
|
||||
Thread serverThread = new Thread(() -> {
|
||||
try {
|
||||
BattleshipServer.main(null);
|
||||
BattleshipSelfhostServer.main(null);
|
||||
} catch (Exception e) {
|
||||
serverButton.setEnabled(true);
|
||||
HOST.setEnabled(true);
|
||||
LOGGER.log(Level.ERROR, "Server could not be started", e);
|
||||
network.getApp().errorDialog("Could not start server: " + e.getMessage());
|
||||
}
|
||||
@@ -176,3 +172,4 @@ class NetworkDialog extends SimpleDialog {
|
||||
serverThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Sphere;
|
||||
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.Shot;
|
||||
@@ -23,7 +22,6 @@ import pp.util.Position;
|
||||
|
||||
import static com.jme3.material.Materials.UNSHADED;
|
||||
|
||||
|
||||
/**
|
||||
* Synchronizes the visual representation of the ship map with the game model.
|
||||
* It handles the rendering of ships and shots on the map view, updating the view
|
||||
@@ -132,7 +130,7 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
return view.getApp().getDraw().makeFatLine(x1, y1, x2, y2, SHIP_DEPTH, color, SHIP_LINE_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Creates and returns a Spatial representation of the given {@code Shell} object
|
||||
* for 2D visualization in the game. The shell is represented as a circle.
|
||||
*
|
||||
@@ -150,5 +148,6 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
ellipse.setMaterial(mat);
|
||||
ellipse.addControl(new Shell2DControl(view, shell));
|
||||
return ellipse;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh.Type;
|
||||
import com.jme3.effect.shapes.EmitterSphereShape;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
|
||||
/**
|
||||
* Factory class responsible for creating particle effects used in the game.
|
||||
* This centralizes the creation of various types of particle emitters.
|
||||
*/
|
||||
public class ParticleEffectFactory {
|
||||
private static final int COUNT_FACTOR = 1;
|
||||
private static final float COUNT_FACTOR_F = 1f;
|
||||
private static final boolean POINT_SPRITE = true;
|
||||
private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
|
||||
|
||||
private final BattleshipApp app;
|
||||
|
||||
ParticleEffectFactory(BattleshipApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a flame particle emitter.
|
||||
*
|
||||
* @return a configured flame particle emitter
|
||||
*/
|
||||
ParticleEmitter createFlame() {
|
||||
ParticleEmitter flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
|
||||
flame.setSelectRandomImage(true);
|
||||
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
|
||||
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
|
||||
flame.setStartSize(0.1f);
|
||||
flame.setEndSize(0.5f);
|
||||
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
flame.setParticlesPerSec(0);
|
||||
flame.setGravity(0, -5, 0);
|
||||
flame.setLowLife(.4f);
|
||||
flame.setHighLife(.5f);
|
||||
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
|
||||
flame.getParticleInfluencer().setVelocityVariation(1f);
|
||||
flame.setImagesX(2);
|
||||
flame.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flame.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flame.setMaterial(mat);
|
||||
|
||||
return flame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a flash particle emitter.
|
||||
*
|
||||
* @return a configured flash particle emitter
|
||||
*/
|
||||
ParticleEmitter createFlash() {
|
||||
ParticleEmitter flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
|
||||
flash.setSelectRandomImage(true);
|
||||
flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1f / COUNT_FACTOR_F));
|
||||
flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
flash.setStartSize(.1f);
|
||||
flash.setEndSize(0.5f);
|
||||
flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
flash.setParticlesPerSec(0);
|
||||
flash.setGravity(0, 0, 0);
|
||||
flash.setLowLife(.2f);
|
||||
flash.setHighLife(.2f);
|
||||
flash.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 5f, 0));
|
||||
flash.getParticleInfluencer().setVelocityVariation(1);
|
||||
flash.setImagesX(2);
|
||||
flash.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flash.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flash.setMaterial(mat);
|
||||
|
||||
return flash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a round spark particle emitter.
|
||||
*
|
||||
* @return a configured round spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createRoundSpark() {
|
||||
ParticleEmitter roundSpark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
|
||||
roundSpark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
|
||||
roundSpark.setEndColor(new ColorRGBA(0, 0, 0, 0.5f / COUNT_FACTOR_F));
|
||||
roundSpark.setStartSize(0.2f);
|
||||
roundSpark.setEndSize(0.8f);
|
||||
roundSpark.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
roundSpark.setParticlesPerSec(0);
|
||||
roundSpark.setGravity(0, -.5f, 0);
|
||||
roundSpark.setLowLife(1.8f);
|
||||
roundSpark.setHighLife(2f);
|
||||
roundSpark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0));
|
||||
roundSpark.getParticleInfluencer().setVelocityVariation(.5f);
|
||||
roundSpark.setImagesX(1);
|
||||
roundSpark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/roundspark.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
roundSpark.setMaterial(mat);
|
||||
|
||||
return roundSpark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a spark particle emitter.
|
||||
*
|
||||
* @return a configured spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createSpark() {
|
||||
ParticleEmitter spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
|
||||
spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
spark.setStartSize(.5f);
|
||||
spark.setEndSize(.5f);
|
||||
spark.setFacingVelocity(true);
|
||||
spark.setParticlesPerSec(0);
|
||||
spark.setGravity(0, 5, 0);
|
||||
spark.setLowLife(1.1f);
|
||||
spark.setHighLife(1.5f);
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
|
||||
spark.getParticleInfluencer().setVelocityVariation(1);
|
||||
spark.setImagesX(1);
|
||||
spark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/spark.png"));
|
||||
spark.setMaterial(mat);
|
||||
|
||||
return spark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a smoke trail particle emitter.
|
||||
*
|
||||
* @return a configured smoke trail particle emitter
|
||||
*/
|
||||
ParticleEmitter createSmokeTrail() {
|
||||
ParticleEmitter smokeTrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
|
||||
smokeTrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
smokeTrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
smokeTrail.setStartSize(.2f);
|
||||
smokeTrail.setEndSize(1f);
|
||||
smokeTrail.setFacingVelocity(true);
|
||||
smokeTrail.setParticlesPerSec(0);
|
||||
smokeTrail.setGravity(0, 1, 0);
|
||||
smokeTrail.setLowLife(.4f);
|
||||
smokeTrail.setHighLife(.5f);
|
||||
smokeTrail.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 12, 0));
|
||||
smokeTrail.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeTrail.setImagesX(1);
|
||||
smokeTrail.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/smoketrail.png"));
|
||||
smokeTrail.setMaterial(mat);
|
||||
|
||||
return smokeTrail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a debris particle emitter.
|
||||
*
|
||||
* @return a configured debris particle emitter
|
||||
*/
|
||||
ParticleEmitter createDebris() {
|
||||
ParticleEmitter debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
|
||||
debris.setSelectRandomImage(true);
|
||||
debris.setRandomAngle(true);
|
||||
debris.setRotateSpeed(FastMath.TWO_PI * 4);
|
||||
debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, 1.0f / COUNT_FACTOR_F));
|
||||
debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
|
||||
debris.setStartSize(.10f);
|
||||
debris.setEndSize(.15f);
|
||||
debris.setParticlesPerSec(0);
|
||||
debris.setGravity(0, 12f, 0);
|
||||
debris.setLowLife(1.4f);
|
||||
debris.setHighLife(1.5f);
|
||||
debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 15, 0));
|
||||
debris.getParticleInfluencer().setVelocityVariation(.60f);
|
||||
debris.setImagesX(3);
|
||||
debris.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/Debris.png"));
|
||||
debris.setMaterial(mat);
|
||||
|
||||
return debris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a shockwave particle emitter.
|
||||
*
|
||||
* @return a configured shockwave particle emitter
|
||||
*/
|
||||
ParticleEmitter createShockwave() {
|
||||
ParticleEmitter shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
|
||||
shockwave.setFaceNormal(Vector3f.UNIT_Y);
|
||||
shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, .8f / COUNT_FACTOR_F));
|
||||
shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));
|
||||
shockwave.setStartSize(0f);
|
||||
shockwave.setEndSize(3f);
|
||||
shockwave.setParticlesPerSec(0);
|
||||
shockwave.setGravity(0, 0, 0);
|
||||
shockwave.setLowLife(0.5f);
|
||||
shockwave.setHighLife(0.5f);
|
||||
shockwave.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
shockwave.getParticleInfluencer().setVelocityVariation(0f);
|
||||
shockwave.setImagesX(1);
|
||||
shockwave.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/shockwave.png"));
|
||||
shockwave.setMaterial(mat);
|
||||
|
||||
return shockwave;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a moving smoke emitter.
|
||||
*
|
||||
* @return a configured smoke emitter
|
||||
*/
|
||||
ParticleEmitter createMovingSmokeEmitter() {
|
||||
ParticleEmitter smokeEmitter = new ParticleEmitter("SmokeEmitter", Type.Triangle, 300);
|
||||
smokeEmitter.setGravity(0, 0, 0);
|
||||
smokeEmitter.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeEmitter.setLowLife(1);
|
||||
smokeEmitter.setHighLife(1);
|
||||
smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
|
||||
smokeEmitter.setImagesX(15); // Assuming the smoke texture is a sprite sheet with 15 frames
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Smoke/Smoke.png"));
|
||||
smokeEmitter.setMaterial(mat);
|
||||
|
||||
return smokeEmitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a one-time water splash particle emitter.
|
||||
*
|
||||
* @return a configured one-time water splash particle emitter
|
||||
*/
|
||||
public ParticleEmitter createWaterSplash() {
|
||||
// Create a new particle emitter for the splash effect
|
||||
ParticleEmitter waterSplash = new ParticleEmitter("WaterSplash", Type.Triangle, 30);
|
||||
|
||||
// Set the shape of the emitter, making particles emit from a point or small area
|
||||
waterSplash.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.2f));
|
||||
|
||||
// Start and end colors for water (blue, fading out)
|
||||
waterSplash.setStartColor(new ColorRGBA(0.4f, 0.4f, 1f, 1f)); // Light blue at start
|
||||
waterSplash.setEndColor(new ColorRGBA(0.4f, 0.4f, 1f, 0f)); // Transparent at the end
|
||||
|
||||
// Particle size: small at start, larger before fading out
|
||||
waterSplash.setStartSize(0.1f);
|
||||
waterSplash.setEndSize(0.3f);
|
||||
|
||||
// Particle lifespan (how long particles live)
|
||||
waterSplash.setLowLife(0.5f);
|
||||
waterSplash.setHighLife(1f);
|
||||
|
||||
// Gravity: Pull the water particles downwards
|
||||
waterSplash.setGravity(0, -9.81f, 0); // Earth's gravity simulation
|
||||
|
||||
// Velocity: Give particles an initial burst upward (simulates splash)
|
||||
waterSplash.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0));
|
||||
waterSplash.getParticleInfluencer().setVelocityVariation(0.6f); // Add randomness to splash
|
||||
|
||||
// Set how many particles are emitted per second (0 to emit all particles at once)
|
||||
waterSplash.setParticlesPerSec(0);
|
||||
|
||||
// Load a texture for the water splash (assuming a texture exists at this path)
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Splash/splash.png"));
|
||||
waterSplash.setMaterial(mat);
|
||||
|
||||
return waterSplash;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,13 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh.Type;
|
||||
import com.jme3.effect.shapes.EmitterSphereShape;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
@@ -30,16 +34,16 @@ import static pp.util.FloatMath.PI;
|
||||
|
||||
/**
|
||||
* The {@code SeaSynchronizer} class is responsible for synchronizing the graphical
|
||||
* representation of the ships and shots on the sea map with the underlying data model.
|
||||
* representation of the ships and shots on the sea map with the underlying model.
|
||||
* It extends the {@link ShipMapSynchronizer} to provide specific synchronization
|
||||
* logic for the sea map.
|
||||
*/
|
||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
||||
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS
|
||||
private static final String BOAT_SMALL_MODEL = "Models/BoatSmall/12219_boat_v2_L2.j3o"; //NON-NLS
|
||||
private static final String CV_MODEL = "Models/CV/CV.j3o"; //NON-NLS
|
||||
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o";//NON-NLS
|
||||
private static final String SMALL_BOAT_MODEL = "Models/BoatSmall/12219_boat_v2_L2.j3o";
|
||||
private static final String BATTLE_MODEL = "Models/Battle/Battle.j3o"; //NON-NLS
|
||||
private static final String CV_MODEL = "Models/CV/CV.j3o"; //NON-NLS
|
||||
private static final String LIGHTING = "Common/MatDefs/Light/Lighting.j3md";
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
@@ -50,7 +54,273 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
|
||||
private final ShipMap map;
|
||||
private final BattleshipApp app;
|
||||
private final ParticleEffectFactory particleFactory;
|
||||
private Shell shell;
|
||||
private Spatial shellModel;
|
||||
|
||||
private ParticleEmitter flame, flash, spark, roundspark, smoketrail, debris,
|
||||
shockwave;
|
||||
|
||||
|
||||
private static final int COUNT_FACTOR = 1;
|
||||
private static final float COUNT_FACTOR_F = 1f;
|
||||
|
||||
private static final boolean POINT_SPRITE = true;
|
||||
private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
|
||||
|
||||
/**
|
||||
* Creates a Flame texture with indefinite Lifetime
|
||||
* @return flame texture
|
||||
*/
|
||||
private ParticleEmitter createFlame(){
|
||||
flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
|
||||
flame.setSelectRandomImage(true);
|
||||
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
|
||||
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
|
||||
flame.setStartSize(0.1f);
|
||||
flame.setEndSize(0.5f);
|
||||
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
flame.setParticlesPerSec(0);
|
||||
flame.setGravity(0, -5, 0);
|
||||
flame.setLowLife(.4f);
|
||||
flame.setHighLife(.5f);
|
||||
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
|
||||
flame.getParticleInfluencer().setVelocityVariation(1f);
|
||||
flame.setImagesX(2);
|
||||
flame.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flame.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flame.setMaterial(mat);
|
||||
|
||||
return flame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Flash texture
|
||||
* @return flash texture
|
||||
*/
|
||||
private ParticleEmitter createFlash(){
|
||||
flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
|
||||
flash.setSelectRandomImage(true);
|
||||
flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1f / COUNT_FACTOR_F));
|
||||
flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
flash.setStartSize(.1f);
|
||||
flash.setEndSize(0.5f);
|
||||
flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
flash.setParticlesPerSec(0);
|
||||
flash.setGravity(0, 0, 0);
|
||||
flash.setLowLife(.2f);
|
||||
flash.setHighLife(.2f);
|
||||
flash.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 5f, 0));
|
||||
flash.getParticleInfluencer().setVelocityVariation(1);
|
||||
flash.setImagesX(2);
|
||||
flash.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flash.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flash.setMaterial(mat);
|
||||
|
||||
return flash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates small spark particles, that dissipate into the air
|
||||
* @return spark texture
|
||||
*/
|
||||
private ParticleEmitter createRoundSpark(){
|
||||
roundspark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
|
||||
roundspark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
|
||||
roundspark.setEndColor(new ColorRGBA(0, 0, 0, 0.5f / COUNT_FACTOR_F));
|
||||
roundspark.setStartSize(0.2f);
|
||||
roundspark.setEndSize(0.8f);
|
||||
roundspark.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
roundspark.setParticlesPerSec(0);
|
||||
roundspark.setGravity(0, -.5f, 0);
|
||||
roundspark.setLowLife(1.8f);
|
||||
roundspark.setHighLife(2f);
|
||||
roundspark.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 3, 0));
|
||||
roundspark.getParticleInfluencer().setVelocityVariation(.5f);
|
||||
roundspark.setImagesX(1);
|
||||
roundspark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/roundspark.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
roundspark.setMaterial(mat);
|
||||
|
||||
return roundspark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates small, thin smoke trails that enhance the flying debris
|
||||
* @return crates a thin smoke trail texture
|
||||
*/
|
||||
private ParticleEmitter createSpark(){
|
||||
spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
|
||||
spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
spark.setStartSize(.5f);
|
||||
spark.setEndSize(.5f);
|
||||
spark.setFacingVelocity(true);
|
||||
spark.setParticlesPerSec(0);
|
||||
spark.setGravity(0, 5, 0);
|
||||
spark.setLowLife(1.1f);
|
||||
spark.setHighLife(1.5f);
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
|
||||
spark.getParticleInfluencer().setVelocityVariation(1);
|
||||
spark.setImagesX(1);
|
||||
spark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/spark.png"));
|
||||
spark.setMaterial(mat);
|
||||
|
||||
return spark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a dynamic smoke trail
|
||||
* @return smoke texture
|
||||
*/
|
||||
private ParticleEmitter createSmokeTrail(){
|
||||
smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
|
||||
smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
smoketrail.setStartSize(.2f);
|
||||
smoketrail.setEndSize(1f);
|
||||
|
||||
// smoketrail.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
smoketrail.setFacingVelocity(true);
|
||||
smoketrail.setParticlesPerSec(0);
|
||||
smoketrail.setGravity(0, 1, 0);
|
||||
smoketrail.setLowLife(.4f);
|
||||
smoketrail.setHighLife(.5f);
|
||||
smoketrail.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 12, 0));
|
||||
smoketrail.getParticleInfluencer().setVelocityVariation(1);
|
||||
smoketrail.setImagesX(1);
|
||||
smoketrail.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/smoketrail.png"));
|
||||
smoketrail.setMaterial(mat);
|
||||
|
||||
return smoketrail;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates flying debris particles
|
||||
* @return debris texture
|
||||
*/
|
||||
private ParticleEmitter createDebris(){
|
||||
debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
|
||||
debris.setSelectRandomImage(true);
|
||||
debris.setRandomAngle(true);
|
||||
debris.setRotateSpeed(FastMath.TWO_PI * 4);
|
||||
debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, 1.0f / COUNT_FACTOR_F));
|
||||
debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
|
||||
debris.setStartSize(.10f);
|
||||
debris.setEndSize(.15f);
|
||||
|
||||
// debris.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
debris.setParticlesPerSec(0);
|
||||
debris.setGravity(0, 12f, 0);
|
||||
debris.setLowLife(1.4f);
|
||||
debris.setHighLife(1.5f);
|
||||
debris.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 15, 0));
|
||||
debris.getParticleInfluencer().setVelocityVariation(.60f);
|
||||
debris.setImagesX(3);
|
||||
debris.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/Debris.png"));
|
||||
debris.setMaterial(mat);
|
||||
|
||||
return debris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expanding circular shockwave
|
||||
* @return shockwave texture
|
||||
*/
|
||||
private ParticleEmitter createShockwave(){
|
||||
shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
|
||||
// shockwave.setRandomAngle(true);
|
||||
shockwave.setFaceNormal(Vector3f.UNIT_Y);
|
||||
shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, .8f / COUNT_FACTOR_F));
|
||||
shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));
|
||||
|
||||
shockwave.setStartSize(0f);
|
||||
shockwave.setEndSize(3f);
|
||||
|
||||
shockwave.setParticlesPerSec(0);
|
||||
shockwave.setGravity(0, 0, 0);
|
||||
shockwave.setLowLife(0.5f);
|
||||
shockwave.setHighLife(0.5f);
|
||||
shockwave.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
shockwave.getParticleInfluencer().setVelocityVariation(0f);
|
||||
shockwave.setImagesX(1);
|
||||
shockwave.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/shockwave.png"));
|
||||
shockwave.setMaterial(mat);
|
||||
|
||||
return shockwave;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an animated smoke column.
|
||||
* @return moving smoke texture
|
||||
*/
|
||||
private ParticleEmitter createMovingSmokeEmitter() {
|
||||
ParticleEmitter smokeEmitter = new ParticleEmitter("SmokeEmitter", Type.Triangle, 300);
|
||||
smokeEmitter.setGravity(0, 0, 0);
|
||||
smokeEmitter.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeEmitter.setLowLife(1);
|
||||
smokeEmitter.setHighLife(1);
|
||||
smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
|
||||
smokeEmitter.setImagesX(15); // Assuming the smoke texture is a sprite sheet with 15 frames
|
||||
|
||||
// Set the material for the emitter
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Smoke/Smoke.png"));
|
||||
smokeEmitter.setMaterial(mat);
|
||||
|
||||
return smokeEmitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a small burst of bubbles.
|
||||
*
|
||||
* @return bubbling water texture.
|
||||
*/
|
||||
public ParticleEmitter createWaterSplash() {
|
||||
ParticleEmitter waterSplash = new ParticleEmitter("WaterSplash", Type.Triangle, 30);
|
||||
|
||||
waterSplash.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.2f));
|
||||
|
||||
waterSplash.setStartColor(new ColorRGBA(0.4f, 0.4f, 1f, 1f)); // Light blue at start
|
||||
waterSplash.setEndColor(new ColorRGBA(0.4f, 0.4f, 1f, 0f)); // Transparent at the end
|
||||
|
||||
waterSplash.setStartSize(0.05f);
|
||||
waterSplash.setEndSize(0.1f);
|
||||
|
||||
waterSplash.setLowLife(0.5f);
|
||||
waterSplash.setHighLife(1f);
|
||||
|
||||
|
||||
waterSplash.setGravity(0, 0, 0); // No gravity to simulate a horizontal water splash
|
||||
|
||||
waterSplash.getParticleInfluencer().setInitialVelocity(new Vector3f(1f, 0f, 1f)); // Horizontal spread
|
||||
waterSplash.getParticleInfluencer().setVelocityVariation(1f); // Add randomness to splash
|
||||
waterSplash.setParticlesPerSec(0);
|
||||
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Splash/splash.png"));
|
||||
waterSplash.setMaterial(mat);
|
||||
|
||||
return waterSplash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||
@@ -63,7 +333,6 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
super(app.getGameLogic().getOwnMap(), root);
|
||||
this.app = app;
|
||||
this.map = map;
|
||||
this.particleFactory = new ParticleEffectFactory(app);
|
||||
addExisting();
|
||||
}
|
||||
|
||||
@@ -80,49 +349,13 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
return shot.isHit() ? handleHit(shot) : handleMiss(shot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a miss by representing it with a blue cylinder
|
||||
* and attaching a water splash effect to it.
|
||||
* @param shot the shot to be processed
|
||||
* @return a Spatial simulating a miss with water splash effect
|
||||
*/
|
||||
private Spatial handleMiss(Shot shot) {
|
||||
Node shotNode = new Node("ShotNode");
|
||||
Geometry shotCylinder = createCylinder(shot);
|
||||
shotNode.attachChild(shotCylinder);
|
||||
ParticleEmitter waterSplash = particleFactory.createWaterSplash();
|
||||
waterSplash.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||
shotNode.attachChild(waterSplash);
|
||||
waterSplash.emitAllParticles();
|
||||
|
||||
return shotNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the sinking animation and removal of ship if destroyed
|
||||
* @param ship the ship to be sunk
|
||||
*/
|
||||
private void sinkAndRemoveShip(Battleship ship) {
|
||||
Battleship wilkeningklaunichtmeinencode = ship;
|
||||
final Node shipNode = (Node) getSpatial(wilkeningklaunichtmeinencode);
|
||||
if (shipNode == null) return;
|
||||
|
||||
// Add sinking control to animate the sinking
|
||||
shipNode.addControl(new SinkingControl(shipNode));
|
||||
|
||||
// Add particle effects
|
||||
ParticleEmitter bubbles = particleFactory.createWaterSplash();
|
||||
bubbles.setLocalTranslation(shipNode.getLocalTranslation());
|
||||
shipNode.attachChild(bubbles);
|
||||
bubbles.emitAllParticles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a hit by attaching its representation to the node that
|
||||
* contains the ship model as a child so that it moves with the ship.
|
||||
*
|
||||
* @param shot a hit
|
||||
* @return always null to prevent the representation from being attached to the items node as well
|
||||
* @return always null to prevent the representation from being attached
|
||||
* to the items node as well
|
||||
*/
|
||||
private Spatial handleHit(Shot shot) {
|
||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||
@@ -134,14 +367,14 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
Node hitEffectNode = new Node("HitEffectNode");
|
||||
|
||||
// Create particle effects
|
||||
ParticleEmitter flame = particleFactory.createFlame();
|
||||
ParticleEmitter flash = particleFactory.createFlash();
|
||||
ParticleEmitter spark = particleFactory.createSpark();
|
||||
ParticleEmitter roundSpark = particleFactory.createRoundSpark();
|
||||
ParticleEmitter smokeTrail = particleFactory.createSmokeTrail();
|
||||
ParticleEmitter debris = particleFactory.createDebris();
|
||||
ParticleEmitter shockwave = particleFactory.createShockwave();
|
||||
ParticleEmitter movingSmoke = particleFactory.createMovingSmokeEmitter();
|
||||
ParticleEmitter flame = createFlame();
|
||||
ParticleEmitter flash = createFlash();
|
||||
ParticleEmitter spark = createSpark();
|
||||
ParticleEmitter roundSpark = createRoundSpark();
|
||||
ParticleEmitter smokeTrail = createSmokeTrail();
|
||||
ParticleEmitter debris = createDebris();
|
||||
ParticleEmitter shockwave = createShockwave();
|
||||
ParticleEmitter movingSmoke = createMovingSmokeEmitter(); // New moving smoke emitter
|
||||
|
||||
// Attach all effects to the hitEffectNode
|
||||
hitEffectNode.attachChild(flame);
|
||||
@@ -170,14 +403,36 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
flame.emitAllParticles();
|
||||
roundSpark.emitAllParticles();
|
||||
|
||||
//Checks if ship is destroyed and triggers animation accordingly
|
||||
if (ship.isDestroyed()) {
|
||||
sinkAndRemoveShip(ship);
|
||||
// Add ShipSinkingControl to the shipNode
|
||||
ShipSinkingControl sinkingControl = new ShipSinkingControl(2f, 5f, -5f, 60f);
|
||||
shipNode.addControl(sinkingControl);
|
||||
sinkingControl.startSinking(); // Start the sinking process
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a miss by representing it with a blue cylinder
|
||||
* and attaching a water splash effect to it.
|
||||
* @param shot the shot to be processed
|
||||
* @return a Spatial simulating a miss with water splash effect
|
||||
*/
|
||||
private Spatial handleMiss(Shot shot) {
|
||||
Node shotNode = new Node("ShotNode");
|
||||
Geometry shotCylinder = createCylinder(shot);
|
||||
shotNode.attachChild(shotCylinder);
|
||||
ParticleEmitter waterSplash = createWaterSplash();
|
||||
waterSplash.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||
shotNode.attachChild(waterSplash);
|
||||
waterSplash.emitAllParticles();
|
||||
|
||||
return shotNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a cylinder geometry representing the specified shot.
|
||||
* The appearance of the cylinder depends on whether the shot is a hit or a miss.
|
||||
@@ -229,11 +484,17 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
*/
|
||||
private Spatial createShip(Battleship ship) {
|
||||
switch (ship.getLength()) {
|
||||
case 4: return createBattleship(ship);
|
||||
case 3: return createCV(ship);
|
||||
case 2: return createBattle(ship);
|
||||
case 1: return createSmallship(ship);
|
||||
default: return createBox(ship);
|
||||
case 4:
|
||||
return createBattleship(ship);
|
||||
case 3:
|
||||
return createCV(ship);
|
||||
case 2:
|
||||
return createBattle(ship);
|
||||
case 1:
|
||||
return createSmallShip(ship);
|
||||
|
||||
default:
|
||||
return createBox(ship);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,27 +538,26 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
* Creates a detailed 3D model to represent a "King George V" battleship.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the "King George V" battleship
|
||||
* @return the spatial representing the "King George V" battleship.
|
||||
*/
|
||||
private Spatial createBattleship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(KING_GEORGE_V_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(1.48f);
|
||||
// model.scale(0.0007f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a small tug boat.
|
||||
* Creates a detailed 3D model to represent a small tugboat.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing a small tug boat
|
||||
* @return the spatial representing the small tugboat.
|
||||
*/
|
||||
private Spatial createSmallship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL);
|
||||
private Spatial createSmallShip(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(SMALL_BOAT_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.0005f);
|
||||
@@ -307,10 +567,27 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a "German WWII UBoat".
|
||||
* Creates a detailed 3D model to represent a U-Boat .
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the "German WWII UBoat"
|
||||
* @return the spatial representing the U-Boat.
|
||||
*/
|
||||
private Spatial createBattle(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
// model.move(0f, -0.05f, 0f);
|
||||
model.scale(0.27f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent an aircraft carrier
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the aircraft carrier.
|
||||
*/
|
||||
private Spatial createCV(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(CV_MODEL);
|
||||
@@ -323,23 +600,6 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a battleship.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing a battleship
|
||||
*/
|
||||
private Spatial createBattle(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.move(0f, -0.06f, 0f);
|
||||
model.scale(0.27f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation angle for the specified rotation.
|
||||
*
|
||||
@@ -375,4 +635,5 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
model.addControl(new ShellControl(shell));
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,16 +42,9 @@ public class Shell2DControl extends AbstractControl {
|
||||
spatial.setLocalTranslation(viewPos.getX() + MapView.FIELD_SIZE / 2, viewPos.getY() + MapView.FIELD_SIZE / 2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-specific behavior required for this control
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,16 +43,9 @@ public class ShellControl extends AbstractControl {
|
||||
spatial.rotate(PI/2,0,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-specific behavior required for this control
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
|
||||
/**
|
||||
* Controls the burning, tilting, and sinking behavior of a battleship.
|
||||
* The ship will burn and tilt for a specified duration, then sink below the water surface.
|
||||
*/
|
||||
public class ShipSinkingControl extends AbstractControl {
|
||||
|
||||
private float elapsedTime = 0f;
|
||||
private final float burnTiltDuration;
|
||||
private final float sinkDuration;
|
||||
private final float sinkDepth;
|
||||
private final float tiltAngle;
|
||||
private final Vector3f initialPosition;
|
||||
private boolean sinkingStarted = false;
|
||||
|
||||
/**
|
||||
* Constructs a new ShipSinkingControl instance.
|
||||
*
|
||||
* @param burnTiltDuration Time in seconds for the ship to burn and tilt on the surface
|
||||
* @param sinkDuration Time in seconds for the ship to fully sink
|
||||
* @param sinkDepth Depth below the water to sink the ship
|
||||
* @param tiltAngle Final tilt angle in degrees
|
||||
*/
|
||||
public ShipSinkingControl(float burnTiltDuration, float sinkDuration, float sinkDepth, float tiltAngle) {
|
||||
this.burnTiltDuration = burnTiltDuration;
|
||||
this.sinkDuration = sinkDuration;
|
||||
this.sinkDepth = sinkDepth;
|
||||
this.tiltAngle = tiltAngle;
|
||||
this.initialPosition = new Vector3f(); // Placeholder; will be set in controlUpdate
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides controlUpdate in AbstractControl
|
||||
* regulates the burn and tilt timeframe
|
||||
* @param tpf time per frame (in seconds)
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if (spatial == null) return;
|
||||
|
||||
elapsedTime += tpf;
|
||||
|
||||
if (elapsedTime < burnTiltDuration) {
|
||||
float progress = elapsedTime / burnTiltDuration;
|
||||
|
||||
float angleInRadians = FastMath.DEG_TO_RAD * FastMath.interpolateLinear(progress, 0f, -tiltAngle);
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(angleInRadians, 0, 0);
|
||||
spatial.setLocalRotation(tiltRotation);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start sinking if it hasn't started yet
|
||||
if (!sinkingStarted) {
|
||||
sinkingStarted = true;
|
||||
// Save the initial position when sinking starts
|
||||
initialPosition.set(spatial.getLocalTranslation());
|
||||
|
||||
// Remove the hitEffectNode
|
||||
Node parentNode = (Node) spatial;
|
||||
Spatial hitEffects = parentNode.getChild("HitEffectNode");
|
||||
if (hitEffects != null) {
|
||||
parentNode.detachChild(hitEffects);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the progress of the sinking (0 to 1)
|
||||
float progress = Math.min((elapsedTime - burnTiltDuration) / sinkDuration, 1f);
|
||||
|
||||
// Apply the tilt angle (remains constant during sinking)
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(-FastMath.DEG_TO_RAD * tiltAngle, 0, 0);
|
||||
spatial.setLocalRotation(tiltRotation);
|
||||
|
||||
// Sink the ship by interpolating the Y position
|
||||
float currentY = FastMath.interpolateLinear(progress, initialPosition.y, sinkDepth);
|
||||
spatial.setLocalTranslation(initialPosition.x, currentY, initialPosition.z);
|
||||
|
||||
if (currentY <= sinkDepth) {
|
||||
Node parentNode = (Node) spatial.getParent();
|
||||
if (parentNode != null) {
|
||||
parentNode.detachChild(spatial);
|
||||
}
|
||||
spatial.removeControl(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering logic is needed for this control
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the sinking process for the ship.
|
||||
*/
|
||||
public void startSinking() {
|
||||
// Nothing to do here as the control update handles the timing and sequence
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
|
||||
/**
|
||||
* Control that handles the sinking effect for destroyed ships.
|
||||
* It will gradually move the ship downwards and then remove it from the scene.
|
||||
*/
|
||||
class SinkingControl extends AbstractControl {
|
||||
private static final float SINK_DURATION = 5f; // Duration of the sinking animation
|
||||
private static final float SINK_SPEED = 0.1f; // Speed at which the ship sinks
|
||||
private float elapsedTime = 0;
|
||||
|
||||
private final Node shipNode;
|
||||
|
||||
/**
|
||||
* Constructs a {@code SinkingControl} object with the shipNode to be to be sunk
|
||||
* @param shipNode the node to handeld
|
||||
*/
|
||||
public SinkingControl(Node shipNode) {
|
||||
this.shipNode = shipNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated the Map to sink the ship
|
||||
*
|
||||
* @param tpf time per frame
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
// Update the sinking effect
|
||||
elapsedTime += tpf;
|
||||
|
||||
// Move the ship down over time
|
||||
Vector3f currentPos = shipNode.getLocalTranslation();
|
||||
shipNode.setLocalTranslation(currentPos.x, currentPos.y - SINK_SPEED * tpf, currentPos.z);
|
||||
|
||||
// Check if sinking duration has passed
|
||||
if (elapsedTime >= SINK_DURATION) {
|
||||
// Remove the ship from the scene
|
||||
shipNode.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-related code needed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
import pp.battleship.client.GameMusic;
|
||||
|
||||
|
||||
public class VolumeControl extends Slider {
|
||||
|
||||
private final GameMusic menuMusicModern;
|
||||
|
||||
private double vol;
|
||||
|
||||
public VolumeControl(GameMusic music) {
|
||||
super();
|
||||
this.menuMusicModern = music;
|
||||
vol = GameMusic.volumePreference();
|
||||
getModel().setPercent(vol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the volume of the music to the appropriate level set by the User through the Volume control Slider
|
||||
*
|
||||
*/
|
||||
public void update() {
|
||||
if (vol != getModel().getPercent()) {
|
||||
vol = getModel().getPercent();
|
||||
menuMusicModern.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
/**
|
||||
* The VolumeSlider class represents the Volume Slider in the Menu.
|
||||
* It extends the Slider class and provides functionalities for setting the music volume,
|
||||
* with the help of the Slider in the GUI
|
||||
*/
|
||||
public class VolumeSlider extends Slider {
|
||||
|
||||
private final GameMusic music;
|
||||
private double vol;
|
||||
|
||||
/**
|
||||
* Constructs the Volume Slider for the Menu dialog
|
||||
* @param music the music instance
|
||||
*/
|
||||
public VolumeSlider(GameMusic music) {
|
||||
super();
|
||||
this.music = music;
|
||||
vol = GameMusic.volumeInPreferences();
|
||||
getModel().setPercent(vol);
|
||||
}
|
||||
|
||||
/**
|
||||
* when triggered it updates the volume to the value set with the slider
|
||||
*/
|
||||
public void update() {
|
||||
if (vol != getModel().getPercent()) {
|
||||
vol = getModel().getPercent();
|
||||
music.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.server;
|
||||
package pp.battleship.client.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
@@ -42,14 +42,14 @@ import java.util.logging.LogManager;
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
*/
|
||||
public class BattleshipServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(BattleshipServer.class.getName());
|
||||
public class BattleshipSelfhostServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(BattleshipSelfhostServer.class.getName());
|
||||
private static final File CONFIG_FILE = new File("server.properties");
|
||||
|
||||
private final BattleshipConfig config = new BattleshipConfig();
|
||||
private Server myServer;
|
||||
private final ServerGameLogic logic;
|
||||
private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<ReceivedMessageSelfhost> pendingMessages = new LinkedBlockingQueue<>();
|
||||
|
||||
static {
|
||||
// Configure logging
|
||||
@@ -64,16 +64,16 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Battleships server.
|
||||
* Starts the server.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new BattleshipServer().run();
|
||||
new BattleshipSelfhostServer().run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the server.
|
||||
*/
|
||||
BattleshipServer() {
|
||||
BattleshipSelfhostServer() {
|
||||
config.readFromIfExists(CONFIG_FILE);
|
||||
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
|
||||
logic = new ServerGameLogic(this, config);
|
||||
@@ -133,7 +133,7 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
public void messageReceived(HostedConnection source, Message message) {
|
||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||
if (message instanceof ClientMessage clientMessage)
|
||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||
pendingMessages.add(new ReceivedMessageSelfhost(clientMessage, source.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,12 +5,12 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.server;
|
||||
package pp.battleship.client.server;
|
||||
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
|
||||
record ReceivedMessage(ClientMessage message, int from) {
|
||||
record ReceivedMessageSelfhost(ClientMessage message, int from) {
|
||||
void process(ClientInterpreter interpreter) {
|
||||
message.accept(interpreter, from);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 29.03.2012 14:25:39
|
||||
|
||||
newmtl default
|
||||
Ns 35.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.5400 0.5400 0.5400
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
||||
map_Kd 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
||||
@@ -0,0 +1,104 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 16.12.2011 14:18:52
|
||||
|
||||
newmtl white
|
||||
Ns 53.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.6667 0.6667 0.6667
|
||||
Kd 0.6667 0.6667 0.6667
|
||||
Ks 0.1800 0.1800 0.1800
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_elements_black
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.0000 0.0000 0.0000
|
||||
Kd 0.0000 0.0000 0.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_glass
|
||||
Ns 60.0000
|
||||
Ni 7.0000
|
||||
d 0.4000
|
||||
Tr 0.6000
|
||||
Tf 0.4000 0.4000 0.4000
|
||||
illum 2
|
||||
Ka 0.1059 0.1569 0.1451
|
||||
Kd 0.1059 0.1569 0.1451
|
||||
Ks 0.6750 0.6750 0.6750
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_screw_hooks_bronze
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2941 0.2157 0.0510
|
||||
Kd 0.2941 0.2157 0.0510
|
||||
Ks 0.7200 0.7200 0.7200
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_silver
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.3333 0.3333 0.3333
|
||||
Kd 0.3333 0.3333 0.3333
|
||||
Ks 0.7200 0.7200 0.7200
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_buffer
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.2700 0.2700 0.2700
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_buffer_diffuse.jpg
|
||||
map_Kd boat_buffer_diffuse.jpg
|
||||
|
||||
newmtl boat_roof_accessory
|
||||
Ns 15.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_roof_accessory_diffuse.jpg
|
||||
map_Kd boat_roof_accessory_diffuse.jpg
|
||||
|
||||
newmtl boat_body
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_body_diffuse.jpg
|
||||
map_Kd boat_body_diffuse.jpg
|
||||
|
After Width: | Height: | Size: 78 B |
@@ -0,0 +1,180 @@
|
||||
newmtl Model001_Material001
|
||||
map_Kd Yorktown_paint6.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material002
|
||||
map_Kd diff_null_7.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material003
|
||||
map_Kd diff_null_14.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material004
|
||||
map_Kd diff_null_Color005.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material005
|
||||
map_Kd diff_null_8.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material006
|
||||
map_Kd diff_null_Color007.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material007
|
||||
map_Kd diff_null_17.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material008
|
||||
map_Kd diff_null_FrontColor.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material009
|
||||
map_Kd diff_null_BackColor.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material010
|
||||
map_Kd diff_null_4.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material011
|
||||
map_Kd Color_004.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material012
|
||||
map_Kd diff_null_Gray1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material013
|
||||
map_Kd diff_null_3.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material014
|
||||
map_Kd Metal_Rough.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material015
|
||||
map_Kd diff_null_12.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material016
|
||||
map_Kd diff_null_19.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material017
|
||||
map_Kd diff_null_Color003.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material018
|
||||
map_Kd diff_null_mat1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material019
|
||||
map_Kd diff_null_1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material020
|
||||
map_Kd diff_null_2.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material021
|
||||
map_Kd diff_null_Black1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material022
|
||||
map_Kd diff_null_Model001Materia.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material023
|
||||
map_Kd diff_null_Model001Mate1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material024
|
||||
map_Kd diff_null_13.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material025
|
||||
map_Kd _6.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material026
|
||||
map_Kd Metal_Aluminum_Anodized.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material027
|
||||
map_Kd diff_null_Color006.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material028
|
||||
map_Kd Blinds_Vertical_Stripe_Gray.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material029
|
||||
map_Kd diff_null_15.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material030
|
||||
map_Kd diff_null_Color002.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material031
|
||||
map_Kd Cladding_Siding_Tan.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material032
|
||||
map_Kd diff_null_Color008.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material033
|
||||
map_Kd diff_null_16.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material034
|
||||
map_Kd _2.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material035
|
||||
map_Kd Blinds_Roman_Hobbled_Blue.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material036
|
||||
map_Kd Blinds_Wood_White.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material037
|
||||
map_Kd Metal_Seamed.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material038
|
||||
map_Kd image_16.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material039
|
||||
map_Kd diff_null_9.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material040
|
||||
map_Kd image_15.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material041
|
||||
map_Kd _Blinds_Roman_Hobbled_Blue_1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material042
|
||||
map_Kd diff_null_10.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material043
|
||||
map_Kd diff_null_Material5.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material044
|
||||
map_Kd diff_null_Material1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material045
|
||||
map_Kd diff_null_11.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
BIN
Projekte/battleship/converter/12219_boat_v2_L2.j3o
Normal file
BIN
Projekte/battleship/converter/Battle.j3o
Normal file
BIN
Projekte/battleship/converter/CV.j3o
Normal file
BIN
Projekte/battleship/converter/KingGeorgeV.j3o
Normal file
@@ -41,16 +41,14 @@ public class ModelExporter extends SimpleApplication {
|
||||
*/
|
||||
@Override
|
||||
public void simpleInitApp() {
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o"); //NON-NLS
|
||||
export("Models/BoatSmall/12219_boat_v2_L2.obj", "BoatSmall.j3o"); //NON-NLS
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o");//NON-NLS
|
||||
export("Models/BoatSmall/12219_boat_v2_L2.obj", "12219_boat_v2_L2.j3o");
|
||||
export("Models/Battle/14084_WWII_Ship_German_Type_II_U-boat_v2_L1.obj", "Battle.j3o"); //NON-NLS
|
||||
export("Models/CV/essex_scb-125_generic.obj", "CV.j3o"); //NON-NLS
|
||||
export("Models/Figures/Würfel_blau.obj", "Würfel_blau.j30");
|
||||
export("Models/Figures/Würfel_gelb.obj", "Würfel_gelb.j30");
|
||||
export("Models/Figures/Würfel_grün.obj", "Würfel_grün.j30");
|
||||
export("Models/Figures/Würfel_rosa.obj", "Würfel_rosa.j30");
|
||||
export("Models/Figures/Würfel_rot.obj", "Würfel_rot.j30");
|
||||
export("Models/Figures/Würfel_schwarz.obj", "Würfel_schwarz.j30");
|
||||
export("Models/Shell/Shell/45.obj", "Shell.j3o");
|
||||
|
||||
|
||||
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 78 B |
387991
Projekte/battleship/converter/src/main/resources/Models/Shell/Shell/45.obj
Normal file
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 3.0 MiB |
|
After Width: | Height: | Size: 246 KiB |
|
After Width: | Height: | Size: 330 KiB |
@@ -10,8 +10,8 @@ package pp.battleship.game.client;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.notification.Sound;
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
@@ -54,13 +54,13 @@ class BattleState extends ClientState {
|
||||
@Override
|
||||
public void receivedEffect(EffectMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
|
||||
|
||||
myTurn = msg.isMyTurn();
|
||||
logic.setInfoText(msg.getInfoTextKey());
|
||||
Shell shell = new Shell(msg.getShot());
|
||||
affectedMap(msg).add(shell);
|
||||
logic.playSound(Sound.SHELL_FLYING);
|
||||
logic.setState(new ShootingState(logic, shell, myTurn, msg));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
package pp.battleship.game.server;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
@@ -36,10 +36,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
private final BattleshipConfig config;
|
||||
private final List<Player> players = new ArrayList<>(2);
|
||||
private final Set<Player> readyPlayers = new HashSet<>();
|
||||
private Set<Player> waitPlayers = new HashSet<>();
|
||||
private final ServerSender serverSender;
|
||||
private Player activePlayer;
|
||||
private ServerState state = ServerState.WAIT;
|
||||
private Set<Player> waitPlayers = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Constructs a ServerGameLogic with the specified sender and configuration.
|
||||
@@ -136,6 +136,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
/**
|
||||
* Handles the reception of a MapMessage.
|
||||
* Also tests valid ship placement on the Map.
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
@@ -153,8 +154,85 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
send(players.get(from), new GameDetails(config));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the reception of a ShootMessage.
|
||||
*
|
||||
* @param msg the received ShootMessage
|
||||
* @param from the ID of the sender client
|
||||
*/
|
||||
@Override
|
||||
public void received(ShootMessage msg, int from) {
|
||||
if (state != ServerState.BATTLE)
|
||||
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
|
||||
else{
|
||||
setState(ServerState.ANIMATION);
|
||||
shoot(getPlayerById(from), msg.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the player as ready and sets their ships.
|
||||
* Transitions the state to PLAY if both players are ready.
|
||||
*
|
||||
* @param player the player who is ready
|
||||
* @param ships the list of ships placed by the player
|
||||
*/
|
||||
void playerReady(Player player, List<Battleship> ships) {
|
||||
if (!readyPlayers.add(player)) {
|
||||
LOGGER.log(Level.ERROR, "{0} was already ready", player); //NON-NLS
|
||||
return;
|
||||
}
|
||||
ships.forEach(player.getMap()::add);
|
||||
if (readyPlayers.size() == 2) {
|
||||
for (Player p : players)
|
||||
send(p, new StartBattleMessage(p == activePlayer));
|
||||
setState(ServerState.BATTLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the shooting action by the player.
|
||||
*
|
||||
* @param p the player who shot
|
||||
* @param pos the position of the shot
|
||||
*/
|
||||
void shoot(Player p, IntPoint pos) {
|
||||
if (p != activePlayer) return;
|
||||
|
||||
final Player otherPlayer = getOpponent(activePlayer);
|
||||
final Battleship selectedShip = otherPlayer.getMap().findShipAt(pos);
|
||||
if (selectedShip == null) {
|
||||
// shot missed
|
||||
send(activePlayer, EffectMessage.miss(true, pos));
|
||||
send(otherPlayer, EffectMessage.miss(false, pos));
|
||||
activePlayer = otherPlayer;
|
||||
}
|
||||
else {
|
||||
// shot hit a ship
|
||||
selectedShip.hit(pos);
|
||||
if (otherPlayer.getMap().getRemainingShips().isEmpty()) {
|
||||
// game is over
|
||||
send(activePlayer, EffectMessage.won(pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.lost(pos, selectedShip, activePlayer.getMap().getRemainingShips()));
|
||||
setState(ServerState.GAME_OVER);
|
||||
}
|
||||
else if (selectedShip.isDestroyed()) {
|
||||
// ship has been destroyed, but game is not yet over
|
||||
send(activePlayer, EffectMessage.shipDestroyed(true, pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.shipDestroyed(false, pos, selectedShip));
|
||||
}
|
||||
else {
|
||||
// ship has been hit, but it hasn't been destroyed
|
||||
send(activePlayer, EffectMessage.hit(true, pos));
|
||||
send(otherPlayer, EffectMessage.hit(false, pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handles the reception of a AnimationFinishedMessage.
|
||||
*
|
||||
@@ -212,79 +290,4 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a ShootMessage.
|
||||
*
|
||||
* @param msg the received ShootMessage
|
||||
* @param from the ID of the sender client
|
||||
*/
|
||||
@Override
|
||||
public void received(ShootMessage msg, int from) {
|
||||
if (state != ServerState.BATTLE)
|
||||
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
|
||||
else{
|
||||
setState(ServerState.ANIMATION);
|
||||
shoot(getPlayerById(from), msg.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the player as ready and sets their ships.
|
||||
* Transitions the state to PLAY if both players are ready.
|
||||
*
|
||||
* @param player the player who is ready
|
||||
* @param ships the list of ships placed by the player
|
||||
*/
|
||||
void playerReady(Player player, List<Battleship> ships) {
|
||||
if (!readyPlayers.add(player)) {
|
||||
LOGGER.log(Level.ERROR, "{0} was already ready", player); //NON-NLS
|
||||
return;
|
||||
}
|
||||
ships.forEach(player.getMap()::add);
|
||||
if (readyPlayers.size() == 2) {
|
||||
for (Player p : players)
|
||||
send(p, new StartBattleMessage(p == activePlayer));
|
||||
setState(ServerState.BATTLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the shooting action by the player.
|
||||
*
|
||||
* @param p the player who shot
|
||||
* @param pos the position of the shot
|
||||
*/
|
||||
void shoot(Player p, IntPoint pos) {
|
||||
if (p != activePlayer) return;
|
||||
final Player otherPlayer = getOpponent(activePlayer);
|
||||
final Battleship selectedShip = otherPlayer.getMap().findShipAt(pos);
|
||||
if (selectedShip == null) {
|
||||
// shot missed
|
||||
send(activePlayer, EffectMessage.miss(true, pos));
|
||||
send(otherPlayer, EffectMessage.miss(false, pos));
|
||||
activePlayer = otherPlayer;
|
||||
}
|
||||
else {
|
||||
// shot hit a ship
|
||||
selectedShip.hit(pos);
|
||||
if (otherPlayer.getMap().getRemainingShips().isEmpty()) {
|
||||
// game is over
|
||||
send(activePlayer, EffectMessage.won(pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.lost(pos, selectedShip, activePlayer.getMap().getRemainingShips()));
|
||||
setState(ServerState.GAME_OVER);
|
||||
}
|
||||
else if (selectedShip.isDestroyed()) {
|
||||
// ship has been destroyed, but game is not yet over
|
||||
send(activePlayer, EffectMessage.shipDestroyed(true, pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.shipDestroyed(false, pos, selectedShip));
|
||||
}
|
||||
else {
|
||||
// ship has been hit, but it hasn't been destroyed
|
||||
send(activePlayer, EffectMessage.hit(true, pos));
|
||||
send(otherPlayer, EffectMessage.hit(false, pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,9 @@ enum ServerState {
|
||||
*/
|
||||
ANIMATION,
|
||||
|
||||
|
||||
/**
|
||||
* The game has ended because all the ships of one player have been destroyed.
|
||||
*/
|
||||
GAME_OVER
|
||||
GAME_OVER,
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package pp.battleship.game.singlemode;
|
||||
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
|
||||
/**
|
||||
@@ -69,6 +69,7 @@ class Copycat implements ClientInterpreter {
|
||||
copiedMessage = msg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a copy of the provided {@link Battleship}.
|
||||
*
|
||||
@@ -78,4 +79,5 @@ class Copycat implements ClientInterpreter {
|
||||
private static Battleship copy(Battleship ship) {
|
||||
return new Battleship(ship.getLength(), ship.getX(), ship.getY(), ship.getRot());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package pp.battleship.game.singlemode;
|
||||
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerInterpreter;
|
||||
@@ -72,7 +72,6 @@ class RobotClient implements ServerInterpreter {
|
||||
* Makes the RobotClient take a shot by sending a ShootMessage with the target position.
|
||||
*/
|
||||
private void robotShot() {
|
||||
|
||||
connection.sendRobotMessage(new ShootMessage(getShotPosition()));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ public interface ClientInterpreter {
|
||||
/**
|
||||
* Processes a received AnimationFinishedMessage.
|
||||
*
|
||||
* @param msg the MapMessage to be processed
|
||||
* @param animationFinishedMessage the MapMessage to be processed
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
void received(AnimationFinishedMessage msg, int from);
|
||||
void received(AnimationFinishedMessage animationFinishedMessage, int from);
|
||||
}
|
||||
|
||||
@@ -123,3 +123,4 @@ public class Shell implements Item {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,15 +78,6 @@ public class ShipMap {
|
||||
addItem(ship);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shot on the map and triggers an item addition event.
|
||||
*
|
||||
* @param shell the shell to be registered on the map
|
||||
*/
|
||||
public void add(Shell shell) {
|
||||
addItem(shell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shot on the map, updates the state of the affected ship (if any),
|
||||
* and triggers an item addition event.
|
||||
@@ -100,6 +91,16 @@ public class ShipMap {
|
||||
addItem(shot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shot on the map and triggers an item addition event.
|
||||
*
|
||||
* @param shell the shell to be registered on the map
|
||||
*/
|
||||
public void add(Shell shell) {
|
||||
addItem(shell);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an item from the map and triggers an item removal event.
|
||||
*
|
||||
|
||||
@@ -28,12 +28,14 @@ public interface Visitor<T> {
|
||||
* @return the result of visiting the Battleship element
|
||||
*/
|
||||
T visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* Visits a Shell element
|
||||
*
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
* @return the result of visitung the Battleship element
|
||||
*/
|
||||
|
||||
T visit(Shell shell);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ public interface VoidVisitor {
|
||||
void visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* Visits a Shell element
|
||||
* * Visits a Shell element
|
||||
* @param shell the Shell element to visit
|
||||
*/
|
||||
void visit(Shell shell);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,4 +27,5 @@ public enum Sound {
|
||||
* Sound of a shell flying
|
||||
*/
|
||||
SHELL_FLYING
|
||||
|
||||
}
|
||||
|
||||
@@ -25,11 +25,12 @@ button.cancel=Cancel
|
||||
server.dialog=Server
|
||||
host.name=Host
|
||||
port.number=Port
|
||||
server.host= Self-Host Game
|
||||
wait.its.not.your.turn=Wait, it's not your turn!!
|
||||
menu.quit=Quit game
|
||||
menu.return-to-game=Return to game
|
||||
menu.sound-enabled=Sound switched on
|
||||
menu.background-sound-enabled=Background music switched on
|
||||
menu.background-sound-enabled=Music switched on
|
||||
menu.map.load=Load map from file...
|
||||
menu.map.save=Save map in file...
|
||||
label.file=File:
|
||||
@@ -38,4 +39,3 @@ dialog.error=Error
|
||||
dialog.question=Question
|
||||
port.must.be.integer=Port must be an integer number
|
||||
map.doesnt.fit=The map doesn't fit to this game
|
||||
client.server-start=Start server
|
||||
|
||||
@@ -25,11 +25,12 @@ button.cancel=Abbruch
|
||||
server.dialog=Server
|
||||
host.name=Host
|
||||
port.number=Port
|
||||
server.host= Spiel selbst hosten
|
||||
wait.its.not.your.turn=Warte, Du bist nicht dran!!
|
||||
menu.quit=Spiel beenden
|
||||
menu.return-to-game=Zurück zum Spiel
|
||||
menu.sound-enabled=Sound eingeschaltet
|
||||
menu.background-sound-enabled=Hintergrundmusik eingeschaltet
|
||||
menu.background-sound-enabled=Musik eingeschaltet
|
||||
menu.map.load=Karte von Datei laden...
|
||||
menu.map.save=Karte in Datei speichern...
|
||||
label.file=Datei:
|
||||
@@ -38,4 +39,3 @@ dialog.error=Fehler
|
||||
dialog.question=Frage
|
||||
port.must.be.integer=Der Port muss eine ganze Zahl sein
|
||||
map.doesnt.fit=Diese Karte passt nicht zu diesem Spiel
|
||||
client.server-start=Server starten
|
||||
|
||||
@@ -18,10 +18,10 @@ import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.game.server.Player;
|
||||
import pp.battleship.game.server.ServerGameLogic;
|
||||
import pp.battleship.game.server.ServerSender;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
@@ -81,8 +81,9 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
|
||||
public void run() {
|
||||
startServer();
|
||||
while (true)
|
||||
while (true) {
|
||||
processNextMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
@@ -120,6 +121,7 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
||||
@@ -111,7 +111,7 @@ public class DialogManager {
|
||||
*
|
||||
* @param dialog the dialog to open
|
||||
*/
|
||||
public void open(Dialog dialog) {
|
||||
void open(Dialog dialog) {
|
||||
dialogStack.push(dialog);
|
||||
dialog.update();
|
||||
app.getGuiNode().attachChild(dialog);
|
||||
@@ -133,7 +133,7 @@ public class DialogManager {
|
||||
* @param dialog the dialog to close
|
||||
* @throws IllegalArgumentException if the specified dialog is not the top dialog
|
||||
*/
|
||||
public void close(Dialog dialog) {
|
||||
void close(Dialog dialog) {
|
||||
if (!isTop(dialog))
|
||||
throw new IllegalArgumentException(dialog + " is not the top dialog");
|
||||
dialogStack.pop();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Styling of Lemur components
|
||||
// For documentation, see:
|
||||
// For documentation, see
|
||||
// https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
|
||||
import com.simsilica.lemur.*
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent
|
||||
|
||||
import com.simsilica.lemur.Button
|
||||
import com.simsilica.lemur.Button.ButtonAction
|
||||
import com.simsilica.lemur.Command
|
||||
@@ -11,19 +10,14 @@ import com.simsilica.lemur.Insets3f
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent
|
||||
import com.simsilica.lemur.component.TbtQuadBackgroundComponent
|
||||
|
||||
def bgColor = color(1, 1, 1, 1)
|
||||
def buttonEnabledColor = color(0, 0, 0, 1)
|
||||
def bgColor = color(0.25, 0.5, 0.5, 1)
|
||||
def buttonEnabledColor = color(0.8, 0.9, 1, 1)
|
||||
def buttonDisabledColor = color(0.8, 0.9, 1, 0.2)
|
||||
def buttonBgColor = color(1, 1, 1, 1)
|
||||
def buttonBgColor = color(0, 0.75, 0.75, 1)
|
||||
def sliderColor = color(0.6, 0.8, 0.8, 1)
|
||||
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
|
||||
|
||||
|
||||
|
||||
def gradient = TbtQuadBackgroundComponent.create(
|
||||
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png",
|
||||
@@ -33,14 +27,7 @@ def gradient = TbtQuadBackgroundComponent.create(
|
||||
|
||||
def doubleGradient = new QuadBackgroundComponent(gradientColor)
|
||||
doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
|
||||
generateMips: false)
|
||||
|
||||
def orangeBorder = TbtQuadBackgroundComponent.create(
|
||||
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", // Replace with an appropriate texture if needed
|
||||
generateMips: false),
|
||||
1, 1, 1, 126, 126,
|
||||
1f, false)
|
||||
orangeBorder.color = color(1, 0.5, 0, 1) // Orange color
|
||||
generateMips: false)
|
||||
|
||||
selector("pp") {
|
||||
font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt")
|
||||
@@ -59,26 +46,10 @@ selector("header", "pp") {
|
||||
}
|
||||
|
||||
selector("container", "pp") {
|
||||
background = solidWhiteBackground.clone()
|
||||
background = gradient.clone()
|
||||
background.setColor(bgColor)
|
||||
}
|
||||
|
||||
selector("toolbar") {
|
||||
// Set the grey background
|
||||
background = new QuadBackgroundComponent(greyBackground)
|
||||
|
||||
// Add a red border using a TbtQuadBackgroundComponent
|
||||
def redBorder = TbtQuadBackgroundComponent.create(
|
||||
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png",
|
||||
generateMips: false),
|
||||
1, 1, 1, 1, 1,
|
||||
1f, false)
|
||||
redBorder.color = redBorderColor
|
||||
background = greyBackground
|
||||
|
||||
// Optional: Set padding inside the toolbar
|
||||
insets = new Insets3f(10, 10, 10, 10)
|
||||
}
|
||||
selector("slider", "pp") {
|
||||
background = gradient.clone()
|
||||
background.setColor(bgColor)
|
||||
@@ -144,7 +115,7 @@ selector("title", "pp") {
|
||||
shadowOffset = vec3(2, -2, -1)
|
||||
background = new QuadBackgroundComponent(color(0.5, 0.75, 0.85, 1))
|
||||
background.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
|
||||
generateMips: false)
|
||||
generateMips: false)
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
|
||||
buttonCommands = stdButtonCommands
|
||||
@@ -152,14 +123,11 @@ selector("title", "pp") {
|
||||
|
||||
|
||||
selector("button", "pp") {
|
||||
def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Orange border
|
||||
def innerBackground = new QuadBackgroundComponent(buttonBgColor) // Inner button background
|
||||
background = gradient.clone()
|
||||
color = buttonEnabledColor
|
||||
background.setColor(buttonBgColor)
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
|
||||
// Apply the outer border as the main background
|
||||
background = outerBackground
|
||||
|
||||
// Use insets to create a margin/padding effect for the inner background
|
||||
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
|
||||
buttonCommands = stdButtonCommands
|
||||
}
|
||||
|
||||
@@ -208,7 +176,6 @@ selector("slider.down.button", "pp") {
|
||||
|
||||
selector("checkbox", "pp") {
|
||||
color = buttonEnabledColor
|
||||
fontSize = 20
|
||||
}
|
||||
|
||||
selector("rollup", "pp") {
|
||||
@@ -225,14 +192,10 @@ selector("tabbedPanel.container", "pp") {
|
||||
}
|
||||
|
||||
selector("tab.button", "pp") {
|
||||
background = solidWhiteBackground.clone()
|
||||
background = gradient.clone()
|
||||
background.setColor(bgColor)
|
||||
color = tabbuttonEnabledColor
|
||||
insets = new Insets3f(4, 2, 0, 2)
|
||||
|
||||
buttonCommands = stdButtonCommands
|
||||
}
|
||||
selector("settings-title", "pp") {
|
||||
fontSize = 48 // Set font size
|
||||
background = new QuadBackgroundComponent(color(0.4157f, 0.4235f, 0.4392f, 1.0f)) // Grey background
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
plugins {
|
||||
id 'buildlogic.jme-application-conventions'
|
||||
}
|
||||
|
||||
description = 'Monopoly Client'
|
||||
|
||||
dependencies {
|
||||
implementation project(":jme-common")
|
||||
implementation project(":monopoly:model")
|
||||
implementation project(":monopoly:server")
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
runtimeOnly libs.jme3.jogg
|
||||
runtimeOnly libs.jme3.testdata
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = 'pp.monopoly.client.MonopolyApp'
|
||||
applicationName = 'monopoly'
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
########################################
|
||||
## Programming project code
|
||||
## UniBw M, 2022, 2023, 2024
|
||||
## www.unibw.de/inf2
|
||||
## (c) Mark Minas (mark.minas@unibw.de)
|
||||
########################################
|
||||
#
|
||||
# Battleship client configuration
|
||||
#
|
||||
# Specifies the map used by the opponent in single mode.
|
||||
# Single mode is activated if this property is set.
|
||||
#map.opponent=maps/map2.json
|
||||
#
|
||||
# Specifies the map used by the player in single mode.
|
||||
# The player must define their own map if this property is not set.
|
||||
map.own=maps/map1.json
|
||||
#
|
||||
# Coordinates of the shots fired by the RobotClient in the order listed.
|
||||
# Example:
|
||||
# 2, 0,\
|
||||
# 2, 1,\
|
||||
# 2, 2,\
|
||||
# 2, 3
|
||||
# defines four shots, namely at the coordinates
|
||||
# (x=2, y=0), (x=2, y=1), (x=2, y=2), and (x=2, y=3)
|
||||
robot.targets=2, 0,\
|
||||
2, 1,\
|
||||
2, 2,\
|
||||
2, 3
|
||||
#
|
||||
# Delay in milliseconds between each shot fired by the RobotClient.
|
||||
robot.delay=500
|
||||
#
|
||||
# The dimensions of the game map used in single mode.
|
||||
# 'map.width' defines the number of columns, and 'map.height' defines the number of rows.
|
||||
map.width=10
|
||||
map.height=10
|
||||
#
|
||||
# The number of ships of each length available in single mode.
|
||||
# The value is a comma-separated list where each element corresponds to the number of ships
|
||||
# with a specific length. For example:
|
||||
# ship.nums=4, 3, 2, 1
|
||||
# This configuration means:
|
||||
# - 4 ships of length 1
|
||||
# - 3 ships of length 2
|
||||
# - 2 ships of length 3
|
||||
# - 1 ship of length 4
|
||||
ship.nums=4, 3, 2, 1
|
||||
#
|
||||
# Screen settings
|
||||
#
|
||||
# Color of the text displayed at the top of the overlay.
|
||||
# The format is (red, green, blue, alpha) where each value ranges from 0 to 1.
|
||||
overlay.top.color=1, 1, 1, 1
|
||||
#
|
||||
# Application settings configuration
|
||||
# Determines whether the settings window is shown at startup.
|
||||
settings.show=false
|
||||
#
|
||||
# Specifies the width of the application window in pixels.
|
||||
settings.resolution.width=1200
|
||||
#
|
||||
# Specifies the height of the application window in pixels.
|
||||
settings.resolution.height=800
|
||||
#
|
||||
# Determines whether the application runs in full-screen mode.
|
||||
settings.full-screen=false
|
||||
#
|
||||
# Enables or disables gamma correction to improve color accuracy.
|
||||
settings.use-gamma-correction=true
|
||||
#
|
||||
# Indicates whether the statistics window is displayed during gameplay.
|
||||
statistics.show=false
|
||||
@@ -1,8 +0,0 @@
|
||||
handlers=java.util.logging.ConsoleHandler
|
||||
.level=INFO
|
||||
pp.level=FINE
|
||||
com.jme3.network.level=INFO
|
||||
;com.jme3.util.TangentBinormalGenerator.level=SEVERE
|
||||
java.util.logging.ConsoleHandler.level=FINER
|
||||
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
|
||||
;java.util.logging.SimpleFormatter.format=[%4$s %2$s] %5$s%n
|
||||
@@ -1,129 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
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;
|
||||
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.SoundEvent;
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
* An application state that plays sounds.
|
||||
*/
|
||||
public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
private static final Logger LOGGER = System.getLogger(GameSound.class.getName());
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the splash sound effect.
|
||||
*/
|
||||
public void splash() {
|
||||
if (isEnabled() && splashSound != null)
|
||||
splashSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the explosion sound effect.
|
||||
*/
|
||||
public void explosion() {
|
||||
if (isEnabled() && explosionSound != null)
|
||||
explosionSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays sound effect when a ship has been destroyed.
|
||||
*/
|
||||
public void shipDestroyed() {
|
||||
if (isEnabled() && shipDestroyedSound != null)
|
||||
shipDestroyedSound.playInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(SoundEvent event) {
|
||||
switch (event.sound()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
* The Menu class represents the main menu in the Battleship game application.
|
||||
* It extends the Dialog class and provides functionalities for loading, saving,
|
||||
* returning to the game, and quitting the application.
|
||||
*/
|
||||
class Menu extends Dialog {
|
||||
private static final Preferences PREFERENCES = getPreferences(Menu.class);
|
||||
private static final String LAST_PATH = "last.file.path";
|
||||
private final MonopolyApp app;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the Menu dialog for the Battleship application.
|
||||
*
|
||||
* @param app the BattleshipApp instance
|
||||
*/
|
||||
public Menu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of the load and save buttons based on the game logic.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* As an escape action, this method closes the menu if it is the top dialog.
|
||||
*/
|
||||
@Override
|
||||
public void escape() {
|
||||
close();
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.font.BitmapFont;
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.input.KeyInput;
|
||||
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;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
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;
|
||||
private final MonopolyAppConfig config;
|
||||
private final ActionListener escapeListener = (name, isPressed, tpf) -> handleEscape(isPressed);
|
||||
private final DialogManager dialogManager = new DialogManager(this);
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
private final Draw draw;
|
||||
private SettingsMenu settingsMenu;
|
||||
private TestWorld testWorld;
|
||||
private boolean isSettingsMenuOpen = false;
|
||||
private boolean inputBlocked = false;
|
||||
private MonopolyServer monopolyServer;
|
||||
|
||||
/**
|
||||
* Path to the styles script for GUI elements.
|
||||
*/
|
||||
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
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new MonopolyApp().start();
|
||||
}
|
||||
|
||||
public MonopolyApp() {
|
||||
this.draw = new Draw(assetManager);
|
||||
config = new MonopolyAppConfig();
|
||||
serverConnection = new NetworkSupport(this);
|
||||
logic = new ClientGameLogic(serverConnection);
|
||||
logic.addListener(this);
|
||||
setShowSettings(config.getShowSettings());
|
||||
setSettings(makeSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MonopolyAppConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientGameLogic getGameLogic() {
|
||||
return logic;
|
||||
}
|
||||
|
||||
private AppSettings makeSettings() {
|
||||
final AppSettings settings = new AppSettings(true);
|
||||
settings.setTitle("Monopoly Game");
|
||||
settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight());
|
||||
settings.setFullscreen(config.fullScreen());
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
setupInput();
|
||||
setupGui();
|
||||
|
||||
// Zeige das Startmenü
|
||||
StartMenu.createStartMenu(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void setupGui() {
|
||||
BitmapFont normalFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
||||
topText = new BitmapText(normalFont);
|
||||
topText.setLocalTranslation(10, settings.getHeight() - 10, 0);
|
||||
guiNode.attachChild(topText);
|
||||
}
|
||||
|
||||
private void setupInput() {
|
||||
inputManager.deleteMapping(INPUT_MAPPING_EXIT);
|
||||
inputManager.setCursorVisible(true);
|
||||
inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
||||
inputManager.addListener(escapeListener, "ESC");
|
||||
}
|
||||
|
||||
void handleEscape(boolean isPressed) {
|
||||
if (isPressed) {
|
||||
if (settingsMenu != null && isSettingsMenuOpen) {
|
||||
// Schließe das SettingsMenu
|
||||
System.out.println("Schließe SettingsMenu...");
|
||||
settingsMenu.close();
|
||||
settingsMenu = null;
|
||||
setSettingsMenuOpen(false);
|
||||
} else {
|
||||
// Öffne das SettingsMenu
|
||||
System.out.println("Öffne SettingsMenu...");
|
||||
settingsMenu = new SettingsMenu(this);
|
||||
settingsMenu.open();
|
||||
setSettingsMenuOpen(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void blockInputs() {
|
||||
if (!inputBlocked) {
|
||||
System.out.println("Blockiere Eingaben...");
|
||||
inputManager.setCursorVisible(true); // Cursor sichtbar machen
|
||||
inputManager.clearMappings(); // Alle Mappings entfernen
|
||||
inputBlocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void unblockInputs() {
|
||||
if (inputBlocked) {
|
||||
System.out.println("Aktiviere Eingaben...");
|
||||
setupInput(); // Standard-Eingaben neu registrieren
|
||||
inputBlocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setInfoText(String text) {
|
||||
topText.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(InfoTextEvent event) {
|
||||
setInfoText(event.key());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(boolean waitFor) {
|
||||
if (executor != null) executor.shutdownNow();
|
||||
serverConnection.disconnect();
|
||||
super.stop(waitFor);
|
||||
}
|
||||
|
||||
public DialogManager getDialogManager() {
|
||||
return dialogManager;
|
||||
}
|
||||
|
||||
public Draw getDraw() {
|
||||
return draw;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void closeApp() {
|
||||
stop();
|
||||
}
|
||||
|
||||
public void errorDialog(String errorMessage) {
|
||||
DialogBuilder.simple(dialogManager)
|
||||
.setTitle("Fehler")
|
||||
.setText(errorMessage)
|
||||
.setOkButton("OK")
|
||||
.build()
|
||||
.open();
|
||||
}
|
||||
|
||||
public void setSettingsMenuOpen(boolean isOpen) {
|
||||
this.isSettingsMenuOpen = isOpen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simpleUpdate(float tpf) {
|
||||
if (testWorld != null) {
|
||||
testWorld.update(tpf); // Aktualisiere die Kamera in der TestWorld
|
||||
}
|
||||
}
|
||||
|
||||
public void startTestWorld() {
|
||||
guiNode.detachAllChildren(); // Entferne GUI
|
||||
testWorld = new TestWorld(this); // Erstelle eine Instanz von TestWorld
|
||||
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 = new MonopolyServer(); // Erstelle Serverinstanz
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public MonopolyServer getMonopolyServer() {
|
||||
return monopolyServer;
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
|
||||
import pp.monopoly.game.client.MonopolyClientConfig;
|
||||
|
||||
/**
|
||||
* Provides access to the Monopoly application configuration.
|
||||
* Extends {@link MonopolyClientConfig} to include additional properties specific to the client,
|
||||
* particularly those related to screen settings and visual customization.
|
||||
* <p>
|
||||
* <b>Note:</b> Attributes of this class should not be marked as {@code final}
|
||||
* to ensure proper functionality when reading from a properties file.
|
||||
* </p>
|
||||
*/
|
||||
public class MonopolyAppConfig extends MonopolyClientConfig {
|
||||
|
||||
/**
|
||||
* Converts a string value found in the properties file into an object of the specified type.
|
||||
* Extends the superclass method to support conversion to {@link ColorRGBA}.
|
||||
*
|
||||
* @param value the string value to be converted
|
||||
* @param targetType the target type into which the value string is converted
|
||||
* @return the converted object of the specified type
|
||||
*/
|
||||
@Override
|
||||
protected Object convertToType(String value, Class<?> targetType) {
|
||||
if (targetType == ColorRGBA.class)
|
||||
return makeColorRGBA(value);
|
||||
return super.convertToType(value, targetType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified string value to a corresponding {@link ColorRGBA} object.
|
||||
*
|
||||
* @param value the color in the format "red, green, blue, alpha" with all values in the range [0..1]
|
||||
* @return a {@link ColorRGBA} object representing the color
|
||||
* @throws IllegalArgumentException if the input string is not in the expected format
|
||||
*/
|
||||
private static ColorRGBA makeColorRGBA(String value) {
|
||||
String[] split = value.split(",", -1);
|
||||
try {
|
||||
if (split.length == 4)
|
||||
return new ColorRGBA(Float.parseFloat(split[0]),
|
||||
Float.parseFloat(split[1]),
|
||||
Float.parseFloat(split[2]),
|
||||
Float.parseFloat(split[3]));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// deliberately left empty
|
||||
}
|
||||
throw new IllegalArgumentException(value + " should consist of exactly 4 numbers");
|
||||
}
|
||||
|
||||
/**
|
||||
* The width of the game view resolution in pixels.
|
||||
*/
|
||||
@Property("settings.resolution.width") //NON-NLS
|
||||
private int resolutionWidth = 1200;
|
||||
|
||||
/**
|
||||
* The height of the game view resolution in pixels.
|
||||
*/
|
||||
@Property("settings.resolution.height") //NON-NLS
|
||||
private int resolutionHeight = 800;
|
||||
|
||||
/**
|
||||
* Specifies whether the game should start in full-screen mode.
|
||||
*/
|
||||
@Property("settings.full-screen") //NON-NLS
|
||||
private boolean fullScreen = false;
|
||||
|
||||
/**
|
||||
* Specifies whether gamma correction should be enabled.
|
||||
* If enabled, the main framebuffer is configured for sRGB colors,
|
||||
* and sRGB images are linearized.
|
||||
* <p>
|
||||
* Requires a GPU that supports GL_ARB_framebuffer_sRGB; otherwise, this setting will be ignored.
|
||||
* </p>
|
||||
*/
|
||||
@Property("settings.use-gamma-correction") //NON-NLS
|
||||
private boolean useGammaCorrection = true;
|
||||
|
||||
/**
|
||||
* Specifies whether full resolution framebuffers should be used on Retina displays.
|
||||
* This setting is ignored on non-Retina platforms.
|
||||
*/
|
||||
@Property("settings.use-retina-framebuffer") //NON-NLS
|
||||
private boolean useRetinaFrameBuffer = false;
|
||||
|
||||
/**
|
||||
* Specifies whether the settings window should be shown for configuring the game.
|
||||
*/
|
||||
@Property("settings.show") //NON-NLS
|
||||
private boolean showSettings = false;
|
||||
|
||||
/**
|
||||
* Specifies whether the JME statistics window should be shown in the lower left corner of the screen.
|
||||
*/
|
||||
@Property("statistics.show") //NON-NLS
|
||||
private boolean showStatistics = false;
|
||||
|
||||
/**
|
||||
* The color of the top text during gameplay, represented as a {@link ColorRGBA} object.
|
||||
*/
|
||||
@Property("overlay.top.color") //NON-NLS
|
||||
private ColorRGBA topColor = ColorRGBA.White;
|
||||
|
||||
/**
|
||||
* Creates a default {@code MonopolyAppConfig} with predefined values.
|
||||
*/
|
||||
public MonopolyAppConfig() {
|
||||
// Default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the game view resolution in pixels.
|
||||
*
|
||||
* @return the width of the game view resolution in pixels
|
||||
*/
|
||||
public int getResolutionWidth() {
|
||||
return resolutionWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the game view resolution in pixels.
|
||||
*
|
||||
* @return the height of the game view resolution in pixels
|
||||
*/
|
||||
public int getResolutionHeight() {
|
||||
return resolutionHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the game should start in full-screen mode.
|
||||
*
|
||||
* @return {@code true} if the game should start in full-screen mode; {@code false} otherwise
|
||||
*/
|
||||
public boolean fullScreen() {
|
||||
return fullScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether gamma correction is enabled.
|
||||
* If enabled, the main framebuffer is configured for sRGB colors,
|
||||
* and sRGB images are linearized.
|
||||
*
|
||||
* @return {@code true} if gamma correction is enabled; {@code false} otherwise
|
||||
*/
|
||||
public boolean useGammaCorrection() {
|
||||
return useGammaCorrection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether full resolution framebuffers should be used on Retina displays.
|
||||
* This setting is ignored on non-Retina platforms.
|
||||
*
|
||||
* @return {@code true} if full resolution framebuffers should be used on Retina displays; {@code false} otherwise
|
||||
*/
|
||||
public boolean useRetinaFrameBuffer() {
|
||||
return useRetinaFrameBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the settings window should be shown for configuring the game.
|
||||
*
|
||||
* @return {@code true} if the settings window should be shown; {@code false} otherwise
|
||||
*/
|
||||
public boolean getShowSettings() {
|
||||
return showSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the JME statistics window should be shown in the lower left corner of the screen.
|
||||
*
|
||||
* @return {@code true} if the statistics window should be shown; {@code false} otherwise
|
||||
*/
|
||||
public boolean getShowStatistics() {
|
||||
return showStatistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color of the top text during gameplay as a {@link ColorRGBA} object.
|
||||
*
|
||||
* @return the color of the top text during gameplay
|
||||
*/
|
||||
public ColorRGBA getTopColor() {
|
||||
return topColor;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
|
||||
/**
|
||||
* Abstract class representing a state in the Monopoly game.
|
||||
* Extends the AbstractAppState from jMonkeyEngine to manage state behavior.
|
||||
*/
|
||||
public abstract class MonopolyAppState extends AbstractAppState {
|
||||
private MonopolyApp app;
|
||||
|
||||
/**
|
||||
* Creates a new MonopolyAppState that is initially disabled.
|
||||
*/
|
||||
protected MonopolyAppState() {
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the state manager and application.
|
||||
*
|
||||
* @param stateManager The state manager
|
||||
* @param application The application instance
|
||||
*/
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application application) {
|
||||
super.initialize(stateManager, application);
|
||||
this.app = (MonopolyApp) application;
|
||||
if (isEnabled()) {
|
||||
enableState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MonopolyApp instance associated with this MonopolyAppState.
|
||||
*
|
||||
* @return The MonopolyApp instance.
|
||||
*/
|
||||
public MonopolyApp getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client game logic handler.
|
||||
*
|
||||
* @return the client game logic handler
|
||||
*/
|
||||
public ClientGameLogic getGameLogic() {
|
||||
return app.getGameLogic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of the MonopolyAppState.
|
||||
* If the new state is the same as the current state, the method returns.
|
||||
*
|
||||
* @param enabled The new enabled state.
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
super.setEnabled(enabled);
|
||||
if (app != null) {
|
||||
if (enabled) {
|
||||
enableState();
|
||||
} else {
|
||||
disableState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the state is enabled. Override to define specific behavior.
|
||||
*/
|
||||
protected abstract void enableState();
|
||||
|
||||
/**
|
||||
* Called when the state is disabled. Override to define specific behavior.
|
||||
*/
|
||||
protected abstract void disableState();
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
package pp.monopoly.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 pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
|
||||
/**
|
||||
* Represents a dialog for setting up a network connection in the Monopoly game.
|
||||
* Allows users to specify the host and port for connecting to a game server.
|
||||
*/
|
||||
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 final NetworkSupport network;
|
||||
private final TextField host = new TextField(LOCALHOST);
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
private String hostname;
|
||||
private int portNumber;
|
||||
private Future<Object> connectionFuture;
|
||||
private Dialog progressDialog;
|
||||
|
||||
/**
|
||||
* Constructs a new NetworkDialog.
|
||||
*
|
||||
* @param network The NetworkSupport instance to be used for network operations.
|
||||
*/
|
||||
NetworkDialog(NetworkSupport network) {
|
||||
super(network.getApp().getDialogManager());
|
||||
this.network = network;
|
||||
initializeDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the dialog with input fields and connection buttons.
|
||||
*/
|
||||
private void initializeDialog() {
|
||||
final MonopolyApp app = network.getApp();
|
||||
Container inputContainer = new Container();
|
||||
|
||||
// Titel und Eingabefelder für Host und Port
|
||||
inputContainer.addChild(new Label("Server-Adresse"));
|
||||
inputContainer.addChild(host);
|
||||
|
||||
inputContainer.addChild(new Label("Port"));
|
||||
inputContainer.addChild(port);
|
||||
|
||||
Button connectButton = inputContainer.addChild(new Button("Verbinden"));
|
||||
connectButton.addClickCommands(source -> connect());
|
||||
|
||||
Button cancelButton = inputContainer.addChild(new Button("Abbrechen"));
|
||||
cancelButton.addClickCommands(source -> app.closeApp());
|
||||
|
||||
app.getGuiNode().attachChild(inputContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the connection attempt based on the entered host and port.
|
||||
*/
|
||||
private void connect() {
|
||||
LOGGER.log(Level.INFO, "Connecting to host={0}, port={1}", host, port);
|
||||
try {
|
||||
hostname = host.getText().trim().isEmpty() ? LOCALHOST : host.getText();
|
||||
portNumber = Integer.parseInt(port.getText());
|
||||
openProgressDialog();
|
||||
connectionFuture = network.getApp().getExecutor().submit(this::initNetwork);
|
||||
} catch (NumberFormatException e) {
|
||||
network.getApp().errorDialog("Port muss eine Zahl sein.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a progress dialog while connecting.
|
||||
*/
|
||||
private void openProgressDialog() {
|
||||
progressDialog = DialogBuilder.simple(network.getApp().getDialogManager())
|
||||
.setText("Verbinde zum Server...")
|
||||
.build();
|
||||
progressDialog.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to initialize the network connection.
|
||||
*
|
||||
* @throws RuntimeException If an error occurs when creating the client.
|
||||
*/
|
||||
private Object initNetwork() {
|
||||
try {
|
||||
network.initNetwork(hostname, portNumber);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the connection status and handles completion or failure.
|
||||
*/
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
if (connectionFuture != null && connectionFuture.isDone()) {
|
||||
try {
|
||||
connectionFuture.get();
|
||||
onSuccess();
|
||||
} catch (ExecutionException e) {
|
||||
onFailure(e.getCause());
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Connection interrupted.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a successful connection to the game server.
|
||||
*/
|
||||
private void onSuccess() {
|
||||
connectionFuture = null;
|
||||
progressDialog.close();
|
||||
this.close();
|
||||
network.getApp().setInfoText("Warte auf einen Gegner...");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a failed connection attempt.
|
||||
*
|
||||
* @param e The cause of the failure.
|
||||
*/
|
||||
private void onFailure(Throwable e) {
|
||||
connectionFuture = null;
|
||||
progressDialog.close();
|
||||
network.getApp().errorDialog("Verbindung zum Server fehlgeschlagen.");
|
||||
network.getApp().setInfoText(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import com.jme3.network.Client;
|
||||
import com.jme3.network.ClientStateListener;
|
||||
import com.jme3.network.Message;
|
||||
import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
|
||||
import pp.monopoly.game.client.ServerConnection;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
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 {
|
||||
private static final Logger LOGGER = System.getLogger(NetworkSupport.class.getName());
|
||||
private final MonopolyApp app;
|
||||
private Client client;
|
||||
|
||||
/**
|
||||
* Constructs a NetworkSupport instance for the Monopoly application.
|
||||
*
|
||||
* @param app The Monopoly application instance.
|
||||
*/
|
||||
public NetworkSupport(MonopolyApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Monopoly application instance.
|
||||
*
|
||||
* @return Monopoly application instance
|
||||
*/
|
||||
MonopolyApp getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a connection to the game server.
|
||||
*
|
||||
* @return true if there is a connection to the game server, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return client != null && client.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to join the game if there is no connection yet.
|
||||
* Opens a dialog for the user to enter the host and port information.
|
||||
*/
|
||||
@Override
|
||||
public void connect() {
|
||||
if (client == null) {
|
||||
new NetworkDialog(this).open();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the client connection.
|
||||
*/
|
||||
@Override
|
||||
public void disconnect() {
|
||||
if (client == null) return;
|
||||
client.close();
|
||||
client = null;
|
||||
LOGGER.log(Level.INFO, "Client connection closed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the network connection.
|
||||
*
|
||||
* @param host The server's address.
|
||||
* @param port The server's port.
|
||||
* @throws IOException If an I/O error occurs when creating the client.
|
||||
*/
|
||||
void initNetwork(String host, int port) throws IOException {
|
||||
if (client != null) {
|
||||
throw new IllegalStateException("Already connected to the game server.");
|
||||
}
|
||||
client = Network.connectToServer(host, port);
|
||||
client.start();
|
||||
client.addMessageListener(this);
|
||||
client.addClientStateListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a message is received from the server.
|
||||
*
|
||||
* @param client The client instance that received the message.
|
||||
* @param message The message received from the server.
|
||||
*/
|
||||
@Override
|
||||
public void messageReceived(Client client, Message message) {
|
||||
LOGGER.log(Level.INFO, "Message received from server: {0}", message);
|
||||
if (message instanceof ServerMessage serverMessage) {
|
||||
app.enqueue(() -> serverMessage.accept(app.getGameLogic()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the client has successfully connected to the server.
|
||||
*
|
||||
* @param client The client that connected to the server.
|
||||
*/
|
||||
@Override
|
||||
public void clientConnected(Client client) {
|
||||
LOGGER.log(Level.INFO, "Successfully connected to server: {0}", client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the client is disconnected from the server.
|
||||
*
|
||||
* @param client The client that was disconnected.
|
||||
* @param disconnectInfo Information about the disconnection.
|
||||
*/
|
||||
@Override
|
||||
public void clientDisconnected(Client client, DisconnectInfo disconnectInfo) {
|
||||
LOGGER.log(Level.INFO, "Disconnected from server: {0}", disconnectInfo);
|
||||
this.client = null;
|
||||
app.enqueue(() -> app.setInfoText("Verbindung zum Server verloren."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the specified message to the server.
|
||||
*
|
||||
* @param message The message to be sent to the server.
|
||||
*/
|
||||
@Override
|
||||
public void send(ClientMessage message) {
|
||||
LOGGER.log(Level.INFO, "Sending message to server: {0}", message);
|
||||
if (client == null) {
|
||||
app.errorDialog("Verbindung zum Server verloren.");
|
||||
} else {
|
||||
client.send(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
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.HAlignment;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.gui.CreateGameMenu;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
|
||||
/**
|
||||
* Constructs the startup menu dialog for the Monopoly application.
|
||||
import pp.monopoly.client.gui.GameMenu;
|
||||
*/
|
||||
public class StartMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private Container logoContainer;
|
||||
private Container unibwLogoContainer;
|
||||
|
||||
/**
|
||||
* Constructs the Startup Menu dialog for the Monopoly application.
|
||||
*
|
||||
* @param app the MonopolyApp instance
|
||||
*/
|
||||
public StartMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and displays the Start Menu with buttons for starting the game,
|
||||
* opening settings, and quitting the application.
|
||||
*/
|
||||
public static void createStartMenu(MonopolyApp app) {
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenHeight = app.getContext().getSettings().getHeight();
|
||||
|
||||
// Set up the background image
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(screenWidth, screenHeight);
|
||||
Geometry 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); // Ensure it is behind other GUI elements
|
||||
app.getGuiNode().attachChild(background);
|
||||
|
||||
createMonopolyLogo(app);
|
||||
createUnibwLogo(app);
|
||||
|
||||
// Center container for title and play button
|
||||
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
|
||||
Button startButton = new Button("Spielen");
|
||||
startButton.setPreferredSize(new Vector3f(190, 60, 0)); // Increase button size (width, height)
|
||||
startButton.setFontSize(40); // Set the font size for the button text
|
||||
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
|
||||
|
||||
startButton.addClickCommands(source -> startGame(app));
|
||||
centerMenu.addChild(startButton);
|
||||
|
||||
// Position the center container in the middle of the screen
|
||||
centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f,
|
||||
screenHeight / 2f - 280 + centerMenu.getPreferredSize().y / 2f,
|
||||
0));
|
||||
app.getGuiNode().attachChild(centerMenu);
|
||||
|
||||
// Lower-left container for "Spiel beenden" button
|
||||
Container lowerLeftMenu = new Container();
|
||||
lowerLeftMenu.setLocalTranslation(new Vector3f(100, 90, 0));
|
||||
Button quitButton = new Button("Spiel beenden");
|
||||
quitButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
|
||||
quitButton.setFontSize(18);
|
||||
quitButton.addClickCommands(source -> quitGame());
|
||||
lowerLeftMenu.addChild(quitButton);
|
||||
app.getGuiNode().attachChild(lowerLeftMenu);
|
||||
|
||||
// Lower-right container for "Einstellungen" button
|
||||
Container lowerRightMenu = new Container();
|
||||
lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 200, 90, 0));
|
||||
Button settingsButton = new Button("Einstellungen");
|
||||
settingsButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
|
||||
settingsButton.setFontSize(18); // Increase the font size for the text
|
||||
settingsButton.addClickCommands(source -> openSettings(app));
|
||||
lowerRightMenu.addChild(settingsButton);
|
||||
app.getGuiNode().attachChild(lowerRightMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and positions the Monopoly logo container in the center of the screen.
|
||||
*/
|
||||
private static void createMonopolyLogo(MonopolyApp app) {
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenHeight = app.getContext().getSettings().getHeight();
|
||||
|
||||
// Load the Monopoly logo as a texture
|
||||
Texture logoTexture = app.getAssetManager().loadTexture("Pictures/logo-monopoly.png");
|
||||
|
||||
// Create a container for the logo
|
||||
Container logoContainer = new Container();
|
||||
QuadBackgroundComponent logoBackground = new QuadBackgroundComponent(logoTexture);
|
||||
logoContainer.setBackground(logoBackground);
|
||||
|
||||
// Set the size of the container to fit the logo
|
||||
float logoWidth = 512; // Adjust these values based on the logo dimensions
|
||||
float logoHeight = 128; // Adjust these values based on the logo dimensions
|
||||
logoContainer.setPreferredSize(new Vector3f(logoWidth, logoHeight, 0));
|
||||
|
||||
// Position the container at the center of the screen
|
||||
logoContainer.setLocalTranslation(new Vector3f(
|
||||
screenWidth / 2f - logoWidth / 2f,
|
||||
screenHeight / 2f + 200, // Adjust this value for vertical position
|
||||
0
|
||||
));
|
||||
|
||||
// Attach the container to the GUI node
|
||||
app.getGuiNode().attachChild(logoContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and positions the Unibw logo container in the center of the screen.
|
||||
*/
|
||||
private static void createUnibwLogo(MonopolyApp app) {
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenHeight = app.getContext().getSettings().getHeight();
|
||||
|
||||
// Load the Unibw logo as a texture
|
||||
Texture unibwTexture = app.getAssetManager().loadTexture("Pictures/logo-unibw.png");
|
||||
|
||||
// Create a container for the Unibw logo
|
||||
Container unibwContainer = new Container();
|
||||
QuadBackgroundComponent unibwBackground = new QuadBackgroundComponent(unibwTexture);
|
||||
unibwContainer.setBackground(unibwBackground);
|
||||
|
||||
// Set the size of the container to fit the Unibw logo
|
||||
float unibwWidth = 512; // Adjust these values based on the logo dimensions
|
||||
float unibwHeight = 128; // Adjust these values based on the logo dimensions
|
||||
unibwContainer.setPreferredSize(new Vector3f(unibwWidth, unibwHeight, 0));
|
||||
|
||||
// Position the container slightly below the Monopoly logo
|
||||
unibwContainer.setLocalTranslation(new Vector3f(
|
||||
screenWidth / 2f - unibwWidth / 2f,
|
||||
screenHeight / 2f + 100, // Adjust this value for vertical position
|
||||
0
|
||||
));
|
||||
|
||||
// Attach the container to the GUI node
|
||||
app.getGuiNode().attachChild(unibwContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game by transitioning to the CreateGameMenu.
|
||||
*/
|
||||
private static void startGame(MonopolyApp app) {
|
||||
app.getGuiNode().detachAllChildren();
|
||||
new CreateGameMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the settings menu.
|
||||
*/
|
||||
private static void openSettings(MonopolyApp app) {
|
||||
app.getGuiNode().detachAllChildren();
|
||||
new SettingsMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the game application.
|
||||
*/
|
||||
private static void quitGame() {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Visitor;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.ItemAddedEvent;
|
||||
import pp.monopoly.notification.ItemRemovedEvent;
|
||||
import pp.view.ModelViewSynchronizer;
|
||||
|
||||
/**
|
||||
* Abstract base class for synchronizing the visual representation of a {@link Board} with its model state.
|
||||
* This class handles the addition and removal of items from the map, ensuring that changes in the model
|
||||
* are accurately reflected in the view.
|
||||
*/
|
||||
abstract class BoardSynchronizer extends ModelViewSynchronizer<Item> implements Visitor<Spatial>, GameEventListener {
|
||||
protected final Board board;
|
||||
|
||||
/**
|
||||
* Constructs a new BoardSynchronizer.
|
||||
*
|
||||
* @param board the game board to synchronize
|
||||
* @param root the root node to which the view representations of the board items are attached
|
||||
*/
|
||||
protected BoardSynchronizer(Board board, Node root) {
|
||||
super(root);
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a model item into its corresponding visual representation.
|
||||
*
|
||||
* @param item the item from the model to be translated
|
||||
* @return the visual representation of the item as a {@link Spatial}
|
||||
*/
|
||||
@Override
|
||||
protected Spatial translate(Item item) {
|
||||
return item.accept(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the existing items from the board to the view during initialization.
|
||||
*/
|
||||
protected void addExisting() {
|
||||
board.getItems().forEach(this::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when an item is removed from the board.
|
||||
*
|
||||
* @param event the event indicating that an item has been removed from the board
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(ItemRemovedEvent event) {
|
||||
if (board == event.getBoard()) {
|
||||
delete(event.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when an item is added to the board.
|
||||
*
|
||||
* @param event the event indicating that an item has been added to the board
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(ItemAddedEvent event) {
|
||||
if (board == event.getBoard()) {
|
||||
add(event.getItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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ü
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial.CullHint;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.model.Board;
|
||||
|
||||
/**
|
||||
* Represents the visual view of a {@link Board}, used to display the map structure and elements.
|
||||
* This class handles the graphical representation of the board, including background setup and grid lines.
|
||||
*/
|
||||
class MapView {
|
||||
private static final float FIELD_SIZE = 40f;
|
||||
private static final float BACKGROUND_DEPTH = -4f;
|
||||
private static final ColorRGBA BACKGROUND_COLOR = new ColorRGBA(0, 0.05f, 0.05f, 0.5f);
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Node mapNode = new Node("map");
|
||||
private final Board board;
|
||||
private final MapViewSynchronizer synchronizer;
|
||||
|
||||
/**
|
||||
* Constructs a new MapView for a given {@link Board} and {@link MonopolyApp}.
|
||||
*
|
||||
* @param board the board to visualize
|
||||
* @param app the main application instance
|
||||
*/
|
||||
MapView(Board board, MonopolyApp app) {
|
||||
this.board = board;
|
||||
this.app = app;
|
||||
this.synchronizer = new MapViewSynchronizer(this);
|
||||
setupBackground();
|
||||
app.getGameLogic().addListener(synchronizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the {@link MapViewSynchronizer} from listening to board changes.
|
||||
*/
|
||||
void unregister() {
|
||||
app.getGameLogic().removeListener(synchronizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the background of the map view using a quad geometry.
|
||||
*/
|
||||
private void setupBackground() {
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat.setColor("Color", BACKGROUND_COLOR);
|
||||
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
Geometry background = new Geometry("MapBackground", new Quad(board.getWidth() * FIELD_SIZE, board.getHeight() * FIELD_SIZE));
|
||||
background.setMaterial(mat);
|
||||
background.setLocalTranslation(0f, 1f, BACKGROUND_DEPTH);
|
||||
background.setCullHint(CullHint.Never);
|
||||
mapNode.attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the root node containing all visual elements in this map view.
|
||||
*
|
||||
* @return the root node for the map view
|
||||
*/
|
||||
public Node getNode() {
|
||||
return mapNode;
|
||||
}
|
||||
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.scene.Spatial;
|
||||
|
||||
import pp.monopoly.model.Figure;
|
||||
|
||||
/**
|
||||
* Synchronizes the visual representation of the board with the game model.
|
||||
* Handles updates for items on the board.
|
||||
*/
|
||||
class MapViewSynchronizer extends BoardSynchronizer {
|
||||
private final MapView view;
|
||||
|
||||
/**
|
||||
* Constructs a new MapViewSynchronizer for the given MapView.
|
||||
*
|
||||
* @param view the MapView to synchronize with the game model
|
||||
*/
|
||||
public MapViewSynchronizer(MapView view) {
|
||||
super(view.getBoard(), view.getNode());
|
||||
this.view = view;
|
||||
addExisting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the state by performing initial setup, such as adding any items to the view.
|
||||
*/
|
||||
|
||||
protected void enableState() {
|
||||
// Platz für zusätzliche Initialisierungen
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the state by clearing the view.
|
||||
*/
|
||||
|
||||
protected void disableState() {
|
||||
view.getNode().detachAllChildren(); // Entfernt alle visuellen Elemente vom Knoten
|
||||
}
|
||||
|
||||
|
||||
public Spatial visit(Figure figure) {
|
||||
return figure.accept(this);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 484 KiB |
|
Before Width: | Height: | Size: 144 KiB |
@@ -1,15 +0,0 @@
|
||||
plugins {
|
||||
id 'buildlogic.java-library-conventions'
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
/**
|
||||
* Provides access to the configuration settings for the Monopoly game.
|
||||
* <p>
|
||||
* This class allows for loading configuration settings from a properties file,
|
||||
* including the server port, map dimensions
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>Note:</b> Attributes of this class are not marked as {@code final} to allow
|
||||
* for proper initialization when reading from a properties file.
|
||||
* </p>
|
||||
*/
|
||||
public class MonopolyConfig extends Config {
|
||||
|
||||
/**
|
||||
* The default port number for the Monopoly server.
|
||||
*/
|
||||
@Property("port")
|
||||
private int port = 42069;
|
||||
|
||||
/**
|
||||
* The width of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.width")
|
||||
private int mapWidth = 10;
|
||||
|
||||
/**
|
||||
* The height of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.height")
|
||||
private int mapHeight = 10;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code MonopolyConfig} with default settings.
|
||||
*/
|
||||
public MonopolyConfig() {
|
||||
// Default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number configured for the Monopoly server.
|
||||
*
|
||||
* @return the port number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the game map. The width is guaranteed to be at least 2 units.
|
||||
*
|
||||
* @return the width of the game map
|
||||
*/
|
||||
public int getMapWidth() {
|
||||
return max(mapWidth, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the game map. The height is guaranteed to be at least 2 units.
|
||||
*
|
||||
* @return the height of the game map
|
||||
*/
|
||||
public int getMapHeight() {
|
||||
return max(mapHeight, 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Provides access to the resource bundle of the game.
|
||||
*
|
||||
* @see #BUNDLE
|
||||
*/
|
||||
public class Resources {
|
||||
/**
|
||||
* The resource bundle for the Monopoly game.
|
||||
*/
|
||||
public static final ResourceBundle BUNDLE = ResourceBundle.getBundle("monopoly"); //NON-NLS
|
||||
|
||||
/**
|
||||
* Gets a string for the given key from the resource bundle in {@linkplain #BUNDLE}.
|
||||
*
|
||||
* @param key the key for the desired string
|
||||
* @return the string for the given key
|
||||
* @throws NullPointerException if {@code key} is {@code null}
|
||||
* @throws java.util.MissingResourceException if no object for the given key can be found
|
||||
* @throws ClassCastException if the object found for the given key is not a string
|
||||
*/
|
||||
public static String lookup(String key) {
|
||||
return BUNDLE.getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation.
|
||||
*/
|
||||
private Resources() { /* do not instantiate */ }
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.BuyPropertyResponse;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
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.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.message.server.TimeOutWarning;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
import pp.monopoly.message.server.TradeRequest;
|
||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.SoundEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls the client-side game logic for Monopoly.
|
||||
* Manages the player's placement, interactions with the map, and response to server messages.
|
||||
*/
|
||||
public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||
private final ClientSender clientSender;
|
||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||
private Board board;
|
||||
|
||||
private ClientState state = new ClientState(this) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
*
|
||||
* @param clientSender the object used to send messages to the server
|
||||
*/
|
||||
public ClientGameLogic(ClientSender clientSender) {
|
||||
this.clientSender = clientSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current state of the game logic.
|
||||
*/
|
||||
ClientState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current state of the game logic.
|
||||
*
|
||||
* @param newState the new state to be set
|
||||
*/
|
||||
void setState(ClientState newState) {
|
||||
LOGGER.log(Level.DEBUG, "state transition {0} --> {1}", state.getName(), newState.getName()); //NON-NLS
|
||||
state = newState;
|
||||
notifyListeners(new ClientStateEvent());
|
||||
state.entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player's own map.
|
||||
*
|
||||
* @return the player's own map
|
||||
*/
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the preview figure to the specified position.
|
||||
*
|
||||
* @param pos the new position for the preview figure
|
||||
*/
|
||||
public void movePreview(IntPoint pos) {
|
||||
state.movePreview(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the informational text to be displayed to the player.
|
||||
*
|
||||
* @param key the key for the info text
|
||||
*/
|
||||
void setInfoText(String key) {
|
||||
notifyListeners(new InfoTextEvent(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an event to play the specified sound.
|
||||
*
|
||||
* @param sound the sound to be played.
|
||||
*/
|
||||
public void playSound(Sound sound) {
|
||||
notifyListeners(new SoundEvent(sound));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a map from the specified file.
|
||||
*
|
||||
* @param file the file to load the map from
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public void loadMap(File file) throws IOException {
|
||||
state.loadMap(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the server.
|
||||
*
|
||||
* @param msg the message to be sent
|
||||
*/
|
||||
void send(ClientMessage msg) {
|
||||
if (clientSender == null)
|
||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||
else
|
||||
clientSender.send(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener to receive game events.
|
||||
*
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public synchronized void addListener(GameEventListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listener from receiving game events.
|
||||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public synchronized void removeListener(GameEventListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all listeners of a game event.
|
||||
*
|
||||
* @param event the game event to notify listeners of
|
||||
*/
|
||||
@Override
|
||||
public void notifyListeners(GameEvent event) {
|
||||
final List<GameEventListener> copy;
|
||||
synchronized (this) {
|
||||
copy = new ArrayList<>(listeners);
|
||||
}
|
||||
for (GameEventListener listener : copy)
|
||||
event.notifyListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once per frame by the update loop.
|
||||
*
|
||||
* @param delta time in seconds since the last update call
|
||||
*/
|
||||
public void update(float delta) {
|
||||
state.update(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyResponse msg) {
|
||||
if (msg.isSuccessful()) {
|
||||
setInfoText("You successfully bought " + msg.getPropertyName() + "!");
|
||||
playSound(Sound.MONEY_LOST);
|
||||
} else {
|
||||
setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DiceResult msg) {
|
||||
setInfoText("You rolled a " + msg.calcTotal() + "!");
|
||||
playSound(Sound.DICE_ROLL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(EventDrawCard msg) {
|
||||
setInfoText("Event card drawn: " + msg.getCardDescription());
|
||||
playSound(Sound.EVENT_CARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(GameOver msg) {
|
||||
if (msg.isWinner()) {
|
||||
setInfoText("Congratulations! You have won the game!");
|
||||
playSound(Sound.WINNER);
|
||||
} else {
|
||||
setInfoText("Game over. Better luck next time!");
|
||||
playSound(Sound.LOSER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(GameStart msg) {
|
||||
setInfoText("The game has started! Good luck!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(JailEvent msg) {
|
||||
if (msg.isGoingToJail()) {
|
||||
setInfoText("You are sent to jail!");
|
||||
playSound(Sound.GULAG);
|
||||
} else {
|
||||
setInfoText("You are out of jail!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(PlayerStatusUpdate msg) {
|
||||
setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(TimeOutWarning msg) {
|
||||
setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ViewAssetsResponse msg) {
|
||||
setInfoText("Your current assets are being displayed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(TradeReply msg) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
|
||||
/**
|
||||
* Interface for sending messages to the server.
|
||||
*/
|
||||
public interface ClientSender {
|
||||
/**
|
||||
* Send the specified message to the server.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
void send(ClientMessage message);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* Defines the behavior and state transitions for the client-side game logic.
|
||||
* Different states of the game logic implement this interface to handle various game events and actions.
|
||||
*/
|
||||
abstract class ClientState {
|
||||
/**
|
||||
* The game logic object.
|
||||
*/
|
||||
final ClientGameLogic logic;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param logic the game logic
|
||||
*/
|
||||
ClientState(ClientGameLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be overridden by subclasses for post-transition initialization.
|
||||
* By default, it does nothing, but it can be overridden in derived states.
|
||||
*/
|
||||
void entry() {
|
||||
// Default implementation does nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current state.
|
||||
*
|
||||
* @return the name of the current state
|
||||
*/
|
||||
String getName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the battle state should be shown.
|
||||
*
|
||||
* @return true if the battle state should be shown, false otherwise
|
||||
*/
|
||||
boolean showTurn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the preview figure to the specified position.
|
||||
*
|
||||
* @param pos the new position for the preview figure
|
||||
*/
|
||||
void movePreview(IntPoint pos) {
|
||||
ClientGameLogic.LOGGER.log(Level.DEBUG, "movePreview has no effect in {0}", getName()); //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a map from the specified file.
|
||||
*
|
||||
* @param file the file to load the map from
|
||||
* @throws IOException if the map cannot be loaded in the current state
|
||||
*/
|
||||
void loadMap(File file) throws IOException {
|
||||
throw new IOException("You are not allowed to load a map in this state of the game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once per frame by the update loop if this state is active.
|
||||
*
|
||||
* @param delta time in seconds since the last update call
|
||||
*/
|
||||
void update(float delta) { /* do nothing by default */ }
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
/**
|
||||
* Interface representing a Monopoly client.
|
||||
* Provides methods to access game logic, configuration, and to enqueue tasks.
|
||||
*/
|
||||
public interface MonopolyClient {
|
||||
|
||||
/**
|
||||
* Returns the game logic associated with this client.
|
||||
*
|
||||
* @return the ClientGameLogic instance
|
||||
*/
|
||||
ClientGameLogic getGameLogic();
|
||||
|
||||
/**
|
||||
* Returns the configuration associated with this client.
|
||||
*
|
||||
* @return the MonopolyConfig instance
|
||||
*/
|
||||
MonopolyClientConfig getConfig();
|
||||
|
||||
/**
|
||||
* Enqueues a task to be executed by the client.
|
||||
*
|
||||
* @param runnable the task to be executed
|
||||
*/
|
||||
void enqueue(Runnable runnable);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
|
||||
/**
|
||||
* Class providing access to the Monopoly client configuration.
|
||||
* Extends {@link MonopolyConfig} to include additional properties specific to the client.
|
||||
* This class manages configuration settings related to the RobotClient's behavior
|
||||
* and the game maps used in single mode.
|
||||
* <p>
|
||||
* <b>Note:</b> Attributes of this class should not be marked as {@code final}
|
||||
* to ensure proper functionality when reading from a properties file.
|
||||
* </p>
|
||||
*/
|
||||
public class MonopolyClientConfig extends MonopolyConfig {
|
||||
|
||||
/**
|
||||
* Path to the file representing the map.
|
||||
*/
|
||||
@Property("map")
|
||||
private String map;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a default {@code MonopolyClientConfig} with predefined values.
|
||||
*/
|
||||
public MonopolyClientConfig() {
|
||||
// Default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file representing the opponent's map.
|
||||
*
|
||||
* @return the opponent's map file, or {@code null} if not set.
|
||||
*/
|
||||
public File getMap() {
|
||||
return map == null ? null : new File(map);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
/**
|
||||
* Interface representing a connection to the server.
|
||||
* Extends ClientSender to allow sending messages to the server.
|
||||
*/
|
||||
public interface ServerConnection extends ClientSender {
|
||||
|
||||
/**
|
||||
* Checks if the client is currently connected to the server.
|
||||
*
|
||||
* @return true if connected, false otherwise.
|
||||
*/
|
||||
boolean isConnected();
|
||||
|
||||
/**
|
||||
* Establishes a connection to the server.
|
||||
*/
|
||||
void connect();
|
||||
|
||||
/**
|
||||
* Disconnects from the server.
|
||||
*/
|
||||
void disconnect();
|
||||
}
|
||||
@@ -1,487 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.EventField;
|
||||
import pp.monopoly.model.fields.FineField;
|
||||
import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.model.fields.GoField;
|
||||
import pp.monopoly.model.fields.GulagField;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
import pp.monopoly.model.fields.TestStreckeField;
|
||||
import pp.monopoly.model.fields.WacheField;
|
||||
|
||||
/**
|
||||
* Class representing a player
|
||||
*/
|
||||
public class Player implements FieldVisitor<Void>{
|
||||
private final int id;
|
||||
private String name;
|
||||
private PlayerColor color;
|
||||
private int accountBalance = 0;
|
||||
private Figure figure;
|
||||
private List<PropertyField> properties;
|
||||
private int getOutOfJailCard;
|
||||
private int fieldID;
|
||||
private DiceResult rollResult;
|
||||
private final PlayerHandler handler;
|
||||
private PlayerState state = new LobbyState();
|
||||
|
||||
/**
|
||||
* Constructs a player with the speciefied params
|
||||
* @param id the id of the player
|
||||
* @param name the name of the player
|
||||
* @param handler the PlayerHandler thispalyer is a part of
|
||||
*/
|
||||
public Player(int id, String name, PlayerHandler handler) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a player with the specified id
|
||||
* @param id the id of the player
|
||||
* @param handler the PlayerHandler this player is a part of
|
||||
*/
|
||||
public Player(int id, PlayerHandler handler) {
|
||||
this.id = id;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Player
|
||||
* @param name the new name
|
||||
*/
|
||||
void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PlayerColor
|
||||
* @param color the color to be set to
|
||||
*/
|
||||
void setColor(PlayerColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this players id
|
||||
* @return th eid of this player
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current position of the player
|
||||
* @return the current position of this player
|
||||
*/
|
||||
public int getFieldID() {
|
||||
return fieldID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves by the specified amount of steps
|
||||
* @param steps the number of steps to move
|
||||
* @return the new position
|
||||
*/
|
||||
public int move(int steps){
|
||||
return movePos(fieldID+steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the player to the specified Position on the board
|
||||
* @param position the position to move to
|
||||
* @return the new position
|
||||
*/
|
||||
public int movePos(int position){
|
||||
fieldID = fieldID+position;
|
||||
if(fieldID >= 40) {
|
||||
fieldID = fieldID%40;
|
||||
earnMoney(2000);
|
||||
}
|
||||
return fieldID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the properties owned by this player
|
||||
* @return List of all properties owned by this player
|
||||
*/
|
||||
public List<PropertyField> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy the speciefied property.
|
||||
* Properties can olny be bought when they are not sold yet and you have enough money left to buy
|
||||
* @param property to property to be bought
|
||||
*/
|
||||
public void buyProperty(PropertyField property) {
|
||||
if (property.getOwner() == null && accountBalance >= property.getPrice()) {
|
||||
properties.add(property);
|
||||
pay(property.getPrice());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell the property
|
||||
* @param property the property to be sold
|
||||
*/
|
||||
public void sellProperty(PropertyField property) {
|
||||
if (property.getOwner() == this) {
|
||||
properties.remove(property);
|
||||
property.setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this players current accountBalanece
|
||||
* @return the amount of money currently owned by this player
|
||||
*/
|
||||
public int getAccountBalance() {
|
||||
return accountBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed the speciefied amount of money to this players accountabalance
|
||||
* @param amount the amount to be removed
|
||||
*/
|
||||
public void pay(int amount) {
|
||||
accountBalance -= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the speciefied amount of money to this players accountabalance
|
||||
* @param amount the amount to be added
|
||||
*/
|
||||
public void earnMoney(int amount) {
|
||||
accountBalance += amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the players name
|
||||
* @return the name of this player
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of GEtOutOfJailCards owned by this player
|
||||
* @return
|
||||
*/
|
||||
public int getNumJailCard() {
|
||||
return getOutOfJailCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a GetOutOfJailCard
|
||||
*/
|
||||
public void addJailCard() {
|
||||
getOutOfJailCard++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a GetOutOfJailCard.
|
||||
* Removes one single card per call, to a minimum of 0 cards
|
||||
*/
|
||||
public void removeJailCard() {
|
||||
if (getOutOfJailCard ==0) {
|
||||
throw new IllegalStateException("Has no JailCard to remove");
|
||||
}
|
||||
getOutOfJailCard--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the logic of paying the jail bail
|
||||
*/
|
||||
public void payBail() {
|
||||
state.payBail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the logic of using a GetOutOfJailCard
|
||||
*/
|
||||
public void useJailCard() {
|
||||
state.useJailCard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
int rent = field.calcRent();
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GateField field) {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GulagField field) {
|
||||
state = new JailState();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(TestStreckeField field) {
|
||||
earnMoney(field.collectMoney());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(EventField field) {
|
||||
DeckHelper.drawCard();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(WacheField field) {
|
||||
movePos(10);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GoField field) {
|
||||
earnMoney(2000);
|
||||
GulagField res = (GulagField) handler.getLogic().getBoardManager().getFieldAtIndex(10);
|
||||
res.accept(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(FineField field) {
|
||||
int amount = field.getFine();
|
||||
pay(amount);
|
||||
TestStreckeField res =(TestStreckeField) handler.getLogic().getBoardManager().getFieldAtIndex(20);
|
||||
res.addMoney(amount);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of Properties of the speciefied fild type
|
||||
* @param field the type of field to search for
|
||||
* @return the number of the fields owned with the specified type
|
||||
*/
|
||||
public int getNumProp(PropertyField field) {
|
||||
int count = 0;
|
||||
for (PropertyField propertyField : properties) {
|
||||
if (propertyField.getClass() == field.getClass()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
*/
|
||||
private class Dice {
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* Rolls a single die and returns a random value from 1 to 6.
|
||||
*
|
||||
* @return the result of a dice roll (1 to 6)
|
||||
*/
|
||||
private static int rollDice() {
|
||||
return random.nextInt(6) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls two dice and returns a list with the results.
|
||||
*
|
||||
* @return a List of two integers representing the dice roll results
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
return state.rollDice();
|
||||
}
|
||||
|
||||
/**
|
||||
* A interface representing the PlayerStates
|
||||
*/
|
||||
private interface PlayerState {
|
||||
/**
|
||||
* Handles the logic for rolling Dice
|
||||
* @return the {@link DiceResult} of this the DiceRoll
|
||||
*/
|
||||
DiceResult rollDice();
|
||||
|
||||
/**
|
||||
* Handles the logic for paying the Jail Bail
|
||||
*/
|
||||
void payBail();
|
||||
|
||||
/**
|
||||
* Handles the action of using a GetOutOfJail Card
|
||||
*/
|
||||
void useJailCard();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class to represent the Active PlayerState
|
||||
* This class is set when it is the Players turn to do actions
|
||||
*/
|
||||
private class ActiveState implements PlayerState {
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// do nothings
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A class to represent the Lobby PlayerState
|
||||
* Set when in Lobby
|
||||
*/
|
||||
private class LobbyState implements PlayerState{
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
//do nothing
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A class to represent the Jailed PlayerState
|
||||
* Set when in Gulag
|
||||
*/
|
||||
private class JailState implements PlayerState {
|
||||
|
||||
private int DoubletsCounter = 3;
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
if (rollResult.isDoublets()) {
|
||||
state = new ActiveState();
|
||||
} else if (DoubletsCounter == 0) {
|
||||
|
||||
} else {
|
||||
DoubletsCounter--;
|
||||
}
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
pay(500);
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
getOutOfJailCard--;
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class BankruptState implements PlayerState {
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
|
||||
/**
|
||||
* Enum representing six distinct colors for players in the game.
|
||||
*/
|
||||
public enum PlayerColor {
|
||||
GREEN_LIGHT(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), // Hex: 00cc00
|
||||
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), // Hex: ff0000
|
||||
BLUE(new ColorRGBA(0 / 255f, 0 / 255f, 204 / 255f, 1)), // Hex: 0000cc
|
||||
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), // Hex: ff4da6
|
||||
GREEN_DARK(new ColorRGBA(0 / 255f, 102 / 255f, 0 / 255f, 1)), // Hex: 006600
|
||||
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)); // Hex: ffff00
|
||||
|
||||
private final ColorRGBA color;
|
||||
|
||||
/**
|
||||
* Constructs a PlayerColor with the specified ColorRGBA value.
|
||||
*
|
||||
* @param color the ColorRGBA value associated with the player color
|
||||
*/
|
||||
PlayerColor(ColorRGBA color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ColorRGBA value of the player color.
|
||||
*
|
||||
* @return the ColorRGBA value
|
||||
*/
|
||||
public ColorRGBA getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* A class for helping with player actions and managing thier turns
|
||||
*/
|
||||
public class PlayerHandler {
|
||||
private List<Player> players = new LinkedList<>();
|
||||
private Set<Player> readyPlayers = new HashSet<>();
|
||||
private ServerGameLogic logic;
|
||||
|
||||
/**
|
||||
* Contructs a PlayerHandler
|
||||
* @param logic the {@link ServerGameLogic} this PlayerHandler is a part of
|
||||
*/
|
||||
PlayerHandler(ServerGameLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contructs a PlayerHandler
|
||||
* @param logic the {@link ServerGameLogic} this PlayerHandler is a part of
|
||||
* @param p1 a Player to be added
|
||||
*/
|
||||
PlayerHandler(ServerGameLogic logic, Player p1) {
|
||||
this(logic);
|
||||
players.add(p1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Contructs a PlayerHandler
|
||||
* @param logic the {@link ServerGameLogic} this PlayerHandler is a part of
|
||||
* @param players a Collection of Players to be added
|
||||
*/
|
||||
PlayerHandler(ServerGameLogic logic, Collection<Player> players) {
|
||||
this(logic);
|
||||
players.addAll(players);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of players
|
||||
* @return number of players in the game
|
||||
*/
|
||||
public int getPlayerCount() {
|
||||
return players.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Chechs if all players are ready to start the game
|
||||
* @return {@code true} if all players are ready, otherwise {@code false}
|
||||
*/
|
||||
public boolean allPlayersReady() {
|
||||
if (readyPlayers.size() == players.size()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a players Ready status
|
||||
* @param player the player to alter
|
||||
* @param ready the new Status
|
||||
*/
|
||||
void setPlayerReady(Player player, boolean ready) {
|
||||
if (!players.contains(player)) {
|
||||
throw new IllegalArgumentException("Player does not belong to this PlayerHandler");
|
||||
} else {
|
||||
if (ready) {
|
||||
readyPlayers.add(player);
|
||||
} else {
|
||||
readyPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the Queue
|
||||
* @param player the player to be added to the queue
|
||||
*/
|
||||
void addPlayer(Player player) {
|
||||
if (players.contains(player)) {
|
||||
throw new IllegalArgumentException("Player already registered");
|
||||
}
|
||||
players.add(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified Player from the Queue
|
||||
* @param player the player to be removed
|
||||
*/
|
||||
void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Player based on their id in the Queue
|
||||
* @param index the index of the queue
|
||||
* @return the Player at the required index
|
||||
*/
|
||||
Player getPlayerAtIndex(int index) {
|
||||
return players.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes a player turn and return the next player
|
||||
* @return the next players who is active
|
||||
*/
|
||||
Player nextPlayer() {
|
||||
Player tmp = players.get(0);
|
||||
players.remove(0);
|
||||
players.add(tmp);
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ServerGameLogic} of this PlayerHandler
|
||||
* @return the {@link ServerGameLogic} of this PlayerHandler
|
||||
*/
|
||||
ServerGameLogic getLogic() {
|
||||
return logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player based on their id
|
||||
* @param id the id to be searched for
|
||||
* @return the player with the required id
|
||||
*/
|
||||
Player getPlayerById(int id) {
|
||||
for (Player player : players) {
|
||||
if (player.getId() == id) return player;
|
||||
}
|
||||
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
||||
}
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.*;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
import pp.monopoly.message.server.TradeRequest;
|
||||
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.
|
||||
*/
|
||||
public class ServerGameLogic implements ClientInterpreter {
|
||||
private static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName());
|
||||
|
||||
private final MonopolyConfig config;
|
||||
private final PlayerHandler playerHandler = new PlayerHandler(this);
|
||||
private final ServerSender serverSender;
|
||||
private ServerState state = ServerState.CREATEGAME;
|
||||
private static final int MAX_PLAYERS = 6;
|
||||
private BoardManager boardManager = new BoardManager();
|
||||
|
||||
/**
|
||||
* Constructs a ServerGameLogic instance with the specified sender and configuration.
|
||||
*
|
||||
* @param serverSender the sender used to send messages to clients
|
||||
* @param config the game configuration
|
||||
*/
|
||||
public ServerGameLogic(ServerSender serverSender, MonopolyConfig config) {
|
||||
this.serverSender = serverSender;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current state of the game.
|
||||
*
|
||||
* @return the current ServerState
|
||||
*/
|
||||
ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new state for the game and logs the state transition.
|
||||
*
|
||||
* @param newState the new ServerState to transition to
|
||||
*/
|
||||
void setState(ServerState newState) {
|
||||
LOGGER.log(Level.DEBUG, "State transition {0} --> {1}", state, newState);
|
||||
state = newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to a specified player.
|
||||
*
|
||||
* @param player the Player to whom the message is sent
|
||||
* @param msg the ServerMessage to send
|
||||
*/
|
||||
void send(Player player, ServerMessage msg) {
|
||||
if (player != null && msg != null) {
|
||||
serverSender.send(player.getId(), msg);
|
||||
LOGGER.log(Level.DEBUG, "Message sent to player {0}: {1}", player.getName(), msg.getClass().getSimpleName());
|
||||
} else {
|
||||
LOGGER.log(Level.WARNING, "Attempted to send a null message or to a null player");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new player to the game if the game is in the LOBBY state and the maximum
|
||||
* player limit has not been reached.
|
||||
*
|
||||
* @param player the Player to add to the game
|
||||
* @return the added Player, or null if the player could not be added
|
||||
*/
|
||||
public Player addPlayer(Player player) {
|
||||
if (state != ServerState.LOBBY) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; game is not in LOBBY state.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (playerHandler.getPlayerCount() >= MAX_PLAYERS) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; maximum player limit reached.");
|
||||
return null;
|
||||
}
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new player to the game if the game is in the LOBBY state and the maximum
|
||||
* player limit has not been reached.
|
||||
*
|
||||
* @param id the id of the player to add to the game
|
||||
* @return the added Player, or null if the player could not be added
|
||||
*/
|
||||
public Player addPlayer(int id) {
|
||||
Player player = new Player(id, playerHandler);
|
||||
if (state != ServerState.LOBBY) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; game is not in LOBBY state.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (playerHandler.getPlayerCount() >= MAX_PLAYERS) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; maximum player limit reached.");
|
||||
return null;
|
||||
}
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a BuyPropertyRequest from a player, allowing the player to purchase a property
|
||||
* if it is unowned and they have sufficient funds.
|
||||
*
|
||||
* @param msg the BuyPropertyRequest received from the player
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property
|
||||
|
||||
if (property.getOwner() == null && player.getAccountBalance() >= property.getPrice()) {
|
||||
player.buyProperty(property);
|
||||
property.setOwner(player);
|
||||
player.earnMoney(-property.getPrice());
|
||||
LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
|
||||
} else {
|
||||
LOGGER.log(Level.WARNING, "Player {0} cannot buy property {1}", player.getName(), property.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an EndTurn request, ending the player's turn and advancing to the next player.
|
||||
*
|
||||
* @param msg the EndTurn message received from the player
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(EndTurn msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||
playerHandler.nextPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a PlayerReady message, marking the player as ready.
|
||||
*
|
||||
* @param msg the PlayerReady message received from the player
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayerReady msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
player.setName(msg.getName());
|
||||
player.setColor(msg.getColor());
|
||||
player.setName(msg.getName());
|
||||
LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a RollDice message, rolling dice for the player and moving them on the board.
|
||||
*
|
||||
* @param msg the RollDice message received from the player
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
send(player, player.rollDice());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a TradeOffer message by forwarding the trade offer to the receiving player.
|
||||
*
|
||||
* @param msg the TradeOffer message received from the initiating player
|
||||
* @param from the connection ID of the player who sent the offer
|
||||
*/
|
||||
@Override
|
||||
public void received(TradeOffer msg, int from) {
|
||||
Player sender = playerHandler.getPlayerById(from);
|
||||
Player receiver = playerHandler.getPlayerById(msg.getReceiverId());
|
||||
|
||||
if (sender != null && receiver != null) {
|
||||
LOGGER.log(Level.INFO, "Player {0} offers a trade to player {1}", sender.getName(), receiver.getName());
|
||||
send(playerHandler.getPlayerById(msg.getReceiverId()), new TradeRequest(msg.getReceiverId(), msg.getTradeHandler()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a TradeResponse message by forwarding the response back to the initiating player.
|
||||
*
|
||||
* @param msg the TradeResponse message received from the receiving player
|
||||
* @param from the connection ID of the player who sent the response
|
||||
*/
|
||||
@Override
|
||||
public void received(TradeResponse msg, int from) {
|
||||
Player responder = playerHandler.getPlayerById(from);
|
||||
Player initiator = playerHandler.getPlayerById(msg.getInitiatorId());
|
||||
|
||||
if (responder != null && initiator != null) {
|
||||
LOGGER.log(Level.INFO, "Player {0} responded to trade with player {1}", responder.getName(), initiator.getName());
|
||||
send(initiator, new TradeReply(msg.getInitiatorId(), msg.getTradeHandler()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a ViewAssetsRequest message, sending the player a response containing their assets.
|
||||
*
|
||||
* @param msg the ViewAssetsRequest message received from the player
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@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());
|
||||
|
||||
send(player, new ViewAssetsResponse(player.getProperties(), player.getAccountBalance(), player.getNumJailCard()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the board manager, which manages the game board.
|
||||
*
|
||||
* @return the BoardManager instance managing the game board
|
||||
*/
|
||||
public BoardManager getBoardManager() {
|
||||
return boardManager;
|
||||
}
|
||||
|
||||
public Player getPlayerById(int id) {
|
||||
return playerHandler.getPlayerById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
/**
|
||||
* Interface for sending messages to a client.
|
||||
*/
|
||||
public interface ServerSender {
|
||||
/**
|
||||
* Send the specified message to the client.
|
||||
*
|
||||
* @param id the id of the client that shall receive the message
|
||||
* @param message the message
|
||||
*/
|
||||
void send(int id, ServerMessage message);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
/**
|
||||
* Represents the different states of the Monopoly server during the game lifecycle.
|
||||
*/
|
||||
enum ServerState {
|
||||
/**
|
||||
* The server is waiting for clients to connect.
|
||||
*/
|
||||
CREATEGAME,
|
||||
|
||||
/**
|
||||
* The server is waiting for clients to set up their status to ready
|
||||
*/
|
||||
LOBBY,
|
||||
|
||||
/**
|
||||
* The battle of the game where players take turns
|
||||
*/
|
||||
INGAME,
|
||||
|
||||
/**
|
||||
* The game has ended because all the players went bankrupt
|
||||
*/
|
||||
GAMEOVER
|
||||
}
|
||||