22 Commits

Author SHA1 Message Date
Simon Wilkening
1f4ebdb630 fixed incorrect splash effect 2024-10-18 17:15:57 +02:00
Simon Wilkening
1f5c8ba4a6 fixed bug of chrashing servers when shell hits a target 2024-10-18 17:09:50 +02:00
Simon Wilkening
0cdd345ab5 corrected minor error 2024-10-18 13:54:04 +02:00
Simon Wilkening
ba837d4016 shell sound 2024-10-18 13:21:29 +02:00
Simon Wilkening
28d9cb10e5 shell animation 2024-10-18 13:20:23 +02:00
Simon Wilkening
21553ec52e ships are finally sinking 2024-10-14 04:40:37 +02:00
Simon Wilkening
5f79e8e00c Added effect for not hitting ships 2024-10-14 04:25:55 +02:00
Simon Wilkening
03adf45167 Adjusted effects 2024-10-14 04:06:27 +02:00
Simon Wilkening
17c4fca078 Added effects for hits 2024-10-13 18:54:36 +02:00
Simon Wilkening
16620a0a3b Added map 7 and map 8 to compare 3D ship models 2024-10-13 14:18:25 +02:00
Simon Wilkening
2028d936e3 Server can now be started from client menu 2024-10-13 14:16:28 +02:00
Simon Wilkening
21fc46f9c5 Added background music for everything 2024-10-13 04:32:33 +02:00
Simon Wilkening
dc52cf4f32 Added boat model for 3x1 boats 2024-10-12 21:35:55 +02:00
Simon Wilkening
c339f3fc9d Added boat model for 2x1 boats 2024-10-12 21:16:13 +02:00
Simon Wilkening
de0b2a4054 Added boat model for 1x1 boats 2024-10-12 20:41:35 +02:00
Simon Wilkening
67e4c1e805 Added map6 with missing ship 2024-10-12 16:54:39 +02:00
Simon Wilkening
0a66d3cbfd Added map5 ignoring zoc 2024-10-12 16:50:25 +02:00
Simon Wilkening
30d129735c Added map3 with ship out of map
Added map4 with ship colliding each other
2024-10-12 16:31:15 +02:00
Simon Wilkening
5f91ce0947 Server site map loading validation 2024-10-12 16:27:38 +02:00
Simon Wilkening
fae747e504 Server site map loading validation 2024-10-12 15:55:30 +02:00
Simon Wilkening
64834e8bf1 Map generation fixed 2024-10-07 12:26:14 +02:00
Simon Wilkening
8f08e83358 Map generation fixed 2024-10-07 12:25:17 +02:00
372 changed files with 763 additions and 581033 deletions

1
.gitignore vendored
View File

@@ -4,7 +4,6 @@ build
# VSC
bin
.vscode
# IntelliJ
*.iml

View File

@@ -1,18 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MonopolyApp (Mac)" type="Application" factoryName="Application"
singleton="false">
<option name="MAIN_CLASS_NAME" value="pp.monopoly.client.MonopolyApp"/>
<module name="Projekte.monopoly.client.main"/>
<option name="VM_PARAMETERS" value="-XstartOnFirstThread"/>
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pp.monopoly.client.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>

View File

@@ -1,18 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MonopolyApp" type="Application" factoryName="Application" singleton="false"
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="pp.monopoly.client.MonopolyApp"/>
<module name="Projekte.monopoly.client.main"/>
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/>
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pp.monopoly.client.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>

View File

@@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MonopolyServer" type="Application" factoryName="Application"
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="pp.monopoly.server.MonopolyServer"/>
<module name="Projekte.monopoly.server.main"/>
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pp.monopoly.server.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>

View File

@@ -9,7 +9,6 @@ dependencies {
implementation project(":battleship:model")
implementation libs.jme3.desktop
implementation libs.jme3.effects
runtimeOnly libs.jme3.awt.dialogs
runtimeOnly libs.jme3.plugins

View File

@@ -9,7 +9,7 @@
#
# Specifies the map used by the opponent in single mode.
# Single mode is activated if this property is set.
#map.opponent=maps/map2.json
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.

View File

@@ -0,0 +1,66 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 4,
"x": 15,
"y": 5,
"rot": "DOWN"
},
{
"length": 3,
"x": 0,
"y": 9,
"rot": "DOWN"
},
{
"length": 3,
"x": 2,
"y": 6,
"rot": "RIGHT"
},
{
"length": 2,
"x": 4,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 2,
"y": 4,
"rot": "DOWN"
},
{
"length": 2,
"x": 2,
"y": 1,
"rot": "DOWN"
},
{
"length": 1,
"x": 6,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 6,
"y": 0,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 0,
"rot": "RIGHT"
}
]
}

View File

@@ -0,0 +1,66 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 4,
"x": 0,
"y": 5,
"rot": "DOWN"
},
{
"length": 3,
"x": 0,
"y": 9,
"rot": "DOWN"
},
{
"length": 3,
"x": 2,
"y": 6,
"rot": "RIGHT"
},
{
"length": 2,
"x": 0,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 2,
"y": 4,
"rot": "DOWN"
},
{
"length": 2,
"x": 2,
"y": 1,
"rot": "DOWN"
},
{
"length": 1,
"x": 6,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 6,
"y": 0,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 0,
"rot": "RIGHT"
}
]
}

View File

@@ -0,0 +1,66 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 4,
"x": 0,
"y": 5,
"rot": "DOWN"
},
{
"length": 3,
"x": 0,
"y": 9,
"rot": "DOWN"
},
{
"length": 3,
"x": 0,
"y": 6,
"rot": "RIGHT"
},
{
"length": 2,
"x": 4,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 2,
"y": 4,
"rot": "DOWN"
},
{
"length": 2,
"x": 2,
"y": 1,
"rot": "DOWN"
},
{
"length": 1,
"x": 6,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 6,
"y": 0,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 0,
"rot": "RIGHT"
}
]
}

View File

@@ -0,0 +1,60 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 3,
"x": 0,
"y": 9,
"rot": "DOWN"
},
{
"length": 3,
"x": 2,
"y": 6,
"rot": "RIGHT"
},
{
"length": 2,
"x": 4,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 2,
"y": 4,
"rot": "DOWN"
},
{
"length": 2,
"x": 2,
"y": 1,
"rot": "DOWN"
},
{
"length": 1,
"x": 6,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 6,
"y": 0,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 0,
"rot": "RIGHT"
}
]
}

View File

@@ -0,0 +1,66 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 4,
"x": 0,
"y": 9,
"rot": "RIGHT"
},
{
"length": 3,
"x": 4,
"y": 9,
"rot": "RIGHT"
},
{
"length": 3,
"x": 7,
"y": 9,
"rot": "RIGHT"
},
{
"length": 2,
"x": 0,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 2,
"y": 8,
"rot": "RIGHT"
},
{
"length": 2,
"x": 4,
"y": 8,
"rot": "RIGHT"
},
{
"length": 1,
"x": 6,
"y": 8,
"rot": "RIGHT"
},
{
"length": 1,
"x": 7,
"y": 8,
"rot": "RIGHT"
},
{
"length": 1,
"x": 8,
"y": 8,
"rot": "RIGHT"
},
{
"length": 1,
"x": 9,
"y": 8,
"rot": "RIGHT"
}
]
}

View File

@@ -0,0 +1,66 @@
{
"width": 10,
"height": 10,
"ships": [
{
"length": 4,
"x": 0,
"y": 9,
"rot": "RIGHT"
},
{
"length": 3,
"x": 0,
"y": 8,
"rot": "RIGHT"
},
{
"length": 3,
"x": 0,
"y": 7,
"rot": "RIGHT"
},
{
"length": 2,
"x": 0,
"y": 6,
"rot": "RIGHT"
},
{
"length": 2,
"x": 0,
"y": 5,
"rot": "RIGHT"
},
{
"length": 2,
"x": 0,
"y": 4,
"rot": "RIGHT"
},
{
"length": 1,
"x": 0,
"y": 3,
"rot": "RIGHT"
},
{
"length": 1,
"x": 0,
"y": 2,
"rot": "RIGHT"
},
{
"length": 1,
"x": 0,
"y": 1,
"rot": "RIGHT"
},
{
"length": 1,
"x": 0,
"y": 0,
"rot": "RIGHT"
}
]
}

View File

@@ -22,7 +22,6 @@ 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.game.client.BattleshipClient;
import pp.battleship.game.client.ClientGameLogic;
@@ -283,14 +282,15 @@ 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);
}
/**
* Updates the application state every frame.
* This method is called once per frame during the game loop.

View File

@@ -1,4 +1,4 @@
package pp.monopoly.client;
package pp.battleship.client;
import static pp.util.PreferencesUtils.getPreferences;
@@ -14,9 +14,6 @@ import com.jme3.asset.AssetNotFoundException;
import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode;
/**
* Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio.
*/
public class GameMusic extends AbstractAppState{
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
@@ -37,7 +34,7 @@ public class GameMusic extends AbstractAppState{
/**
* Checks if sound is enabled in the preferences.
*
* @return float to which the volume is set
*
*/
public static float volumeInPreferences() {
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
@@ -53,7 +50,7 @@ public class GameMusic extends AbstractAppState{
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
music = loadSound(app, "Sound/background.ogg");
music = loadSound(app, "Sound/DasBootMenu.ogg");
setVolume(volumeInPreferences());
music.setLooping(true);
if (isEnabled() && music != null) {
@@ -90,15 +87,11 @@ public class GameMusic extends AbstractAppState{
@Override
public void setEnabled(boolean enabled) {
if (isEnabled() == enabled) return;
if (music != null) {
if (enabled) {
music.play();
} else {
music.stop();
}
else if(!isEnabled() && enabled) {
if (music != null) music.play();
} else if (isEnabled() && !enabled) {
if (music != null) music.stop();
}
super.setEnabled(enabled);
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
@@ -111,12 +104,8 @@ public class GameMusic extends AbstractAppState{
setEnabled(!isEnabled());
}
/**
* Sets the volume of music
* @param vol the volume to which the music should be set
*/
public void setVolume(float vol){
music.setVolume(vol);
PREFERENCES.putFloat(VOLUME_PREF, vol);
}
}
}

View File

@@ -80,6 +80,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
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");
}
/**
@@ -137,7 +138,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
/**
* Handles a recieved {@code SoundEvent} and plays the according sound.
*
*
* @param event the Sound event to be processed
*/
@Override
@@ -147,6 +148,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
case SPLASH -> splash();
case DESTROYED_SHIP -> shipDestroyed();
case SHELL_FLYING -> shellFly();
}
}
}

View File

@@ -7,22 +7,22 @@
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.dialog.Dialog;
import pp.dialog.StateCheckboxModel;
import pp.dialog.TextInputDialog;
import pp.battleship.client.gui.VolumeSlider;
import pp.battleship.client.GameMusic;
import pp.battleship.client.VolumeSlider;
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;
/**
@@ -39,7 +39,7 @@ class Menu extends Dialog {
private final VolumeSlider slider;
/**
* Constructs the Menu dialog for the Battleship application.+
* Constructs the Menu dialog for the Battleship application.
*
* @param app the BattleshipApp instance
*/
@@ -51,14 +51,17 @@ class Menu extends Dialog {
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));
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();
}
@@ -71,11 +74,6 @@ class Menu extends Dialog {
saveButton.setEnabled(app.getGameLogic().maySaveMap());
}
@Override
public void update(float delta) {
slider.update();
}
/**
* As an escape action, this method closes the menu if it is the top dialog.
*/
@@ -151,4 +149,13 @@ class Menu extends Dialog {
private void saveDialog() {
fileDialog(app.getGameLogic()::saveMap, lookup("menu.map.save"));
}
/**
* Updates the position of the volume control slider.
*/
@Override
public void update(float delta) {
slider.update();
}
}

View File

@@ -7,23 +7,23 @@
package pp.battleship.client;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.SpringGridLayout;
import static pp.battleship.Resources.lookup;
import pp.battleship.server.BattleshipServer;
import pp.dialog.Dialog;
import pp.dialog.DialogBuilder;
import pp.dialog.SimpleDialog;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static pp.battleship.Resources.lookup;
/**
* Represents a dialog for setting up a network connection in the Battleship game.
* Allows users to specify the host and port for connecting to a game server.
@@ -31,7 +31,7 @@ import pp.dialog.SimpleDialog;
class NetworkDialog extends SimpleDialog {
private static final Logger LOGGER = System.getLogger(NetworkDialog.class.getName());
private static final String LOCALHOST = "localhost"; //NON-NLS
private static final String DEFAULT_PORT = "42069"; //NON-NLS
private static final String DEFAULT_PORT = "1234"; //NON-NLS
private final NetworkSupport network;
private final TextField host = new TextField(LOCALHOST);
private final TextField port = new TextField(DEFAULT_PORT);
@@ -69,7 +69,7 @@ class NetworkDialog extends SimpleDialog {
.setOkClose(false)
.setNoClose(false)
.build(this);
//Add the button to start the sever
addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread));
}

View File

@@ -1,21 +1,13 @@
package pp.battleship.client.gui;
package pp.battleship.client;
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;
@@ -23,14 +15,10 @@ public class VolumeSlider extends Slider {
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);
}
}
}
}

View File

@@ -1,122 +0,0 @@
package pp.battleship.client.gui;
import static pp.util.PreferencesUtils.getPreferences;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.prefs.Preferences;
import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetLoadException;
import com.jme3.asset.AssetNotFoundException;
import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode;
/**
* Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio.
*/
public class GameMusic extends AbstractAppState{
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
private static final String ENABLED_PREF = "enabled"; //NON-NLS
private static final String VOLUME_PREF = "volume"; //NON-NLS
private AudioNode music;
/**
* Checks if sound is enabled in the preferences.
*
* @return {@code true} if sound is enabled, {@code false} otherwise.
*/
public static boolean enabledInPreferences() {
return PREFERENCES.getBoolean(ENABLED_PREF, true);
}
/**
* Checks if sound is enabled in the preferences.
*
* @return float to which the volume is set
*/
public static float volumeInPreferences() {
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
}
/**
* Initializes the sound effects for the game.
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
*
* @param stateManager The state manager
* @param app The application
*/
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
music = loadSound(app, "Sound/background.ogg");
setVolume(volumeInPreferences());
music.setLooping(true);
if (isEnabled() && music != null) {
music.play();
}
}
/**
* Loads a sound from the specified file.
*
* @param app The application
* @param name The name of the sound file.
* @return The loaded AudioNode.
*/
private AudioNode loadSound(Application app, String name) {
try {
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
sound.setLooping(false);
sound.setPositional(false);
return sound;
}
catch (AssetLoadException | AssetNotFoundException ex) {
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
}
return null;
}
/**
* Sets the enabled state of this AppState.
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
*
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
*/
@Override
public void setEnabled(boolean enabled) {
if (isEnabled() == enabled) return;
if (music != null) {
if (enabled) {
music.play();
} else {
music.stop();
}
}
super.setEnabled(enabled);
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
}
/**
* Toggles the game sound on or off.
*/
public void toggleSound() {
setEnabled(!isEnabled());
}
/**
* Sets the volume of music
* @param vol the volume to which the music should be set
*/
public void setVolume(float vol){
music.setVolume(vol);
PREFERENCES.putFloat(VOLUME_PREF, vol);
}
}

View File

@@ -15,12 +15,10 @@ 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;
import pp.util.Position;
import static com.jme3.material.Materials.UNSHADED;
@@ -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;
}
}
}

View File

@@ -7,30 +7,28 @@ 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 {
public class ParticleCreator {
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) {
ParticleCreator(BattleshipApp app) {
this.app = app;
}
/**
* Creates a flame particle emitter.
*
*
* @return a configured flame particle emitter
*/
ParticleEmitter createFlame() {
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)));
@@ -56,7 +54,7 @@ public class ParticleEffectFactory {
/**
* Creates a flash particle emitter.
*
*
* @return a configured flash particle emitter
*/
ParticleEmitter createFlash() {
@@ -85,7 +83,7 @@ public class ParticleEffectFactory {
/**
* Creates a round spark particle emitter.
*
*
* @return a configured round spark particle emitter
*/
ParticleEmitter createRoundSpark() {
@@ -113,7 +111,7 @@ public class ParticleEffectFactory {
/**
* Creates a spark particle emitter.
*
*
* @return a configured spark particle emitter
*/
ParticleEmitter createSpark() {
@@ -125,9 +123,9 @@ public class ParticleEffectFactory {
spark.setFacingVelocity(true);
spark.setParticlesPerSec(0);
spark.setGravity(0, 5, 0);
spark.setLowLife(1.1f);
spark.setLowLife(0.5f);
spark.setHighLife(1.5f);
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 8, 0)); // y20
spark.getParticleInfluencer().setVelocityVariation(1);
spark.setImagesX(1);
spark.setImagesY(1);
@@ -140,7 +138,7 @@ public class ParticleEffectFactory {
/**
* Creates a smoke trail particle emitter.
*
*
* @return a configured smoke trail particle emitter
*/
ParticleEmitter createSmokeTrail() {
@@ -167,7 +165,7 @@ public class ParticleEffectFactory {
/**
* Creates a debris particle emitter.
*
*
* @return a configured debris particle emitter
*/
ParticleEmitter createDebris() {
@@ -196,7 +194,7 @@ public class ParticleEffectFactory {
/**
* Creates a shockwave particle emitter.
*
*
* @return a configured shockwave particle emitter
*/
ParticleEmitter createShockwave() {
@@ -223,7 +221,7 @@ public class ParticleEffectFactory {
/**
* Creates a moving smoke emitter.
*
*
* @return a configured smoke emitter
*/
ParticleEmitter createMovingSmokeEmitter() {
@@ -243,20 +241,20 @@ public class ParticleEffectFactory {
/**
* 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);
@@ -267,14 +265,14 @@ public class ParticleEffectFactory {
// 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"));
@@ -282,4 +280,5 @@ public class ParticleEffectFactory {
return waterSplash;
}
}

View File

@@ -37,9 +37,9 @@ import static pp.util.FloatMath.PI;
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 BATTLE_MODEL = "Models/Battle/Battle.j3o"; //NON-NLS
private static final String SMALL_SHIP_MODEL = "Models/SmallShip/SmallShip.j3o"; //NON-NLS
private static final String U_BOAT_MODEL = "Models/WWII_ship_German_Type_II_U-boat_v2/WW2Uboat.j3o"; //NON-NLS
private static final String TUG_BOAT_MODEL = "Models/TugBoat/TugBoat.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 +50,8 @@ class SeaSynchronizer extends ShipMapSynchronizer {
private final ShipMap map;
private final BattleshipApp app;
private final ParticleEffectFactory particleFactory;
private final ParticleCreator particlecreator;
/**
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
@@ -63,7 +64,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
super(app.getGameLogic().getOwnMap(), root);
this.app = app;
this.map = map;
this.particleFactory = new ParticleEffectFactory(app);
this.particlecreator = new ParticleCreator(app);
addExisting();
}
@@ -90,7 +91,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
Node shotNode = new Node("ShotNode");
Geometry shotCylinder = createCylinder(shot);
shotNode.attachChild(shotCylinder);
ParticleEmitter waterSplash = particleFactory.createWaterSplash();
ParticleEmitter waterSplash = particlecreator.createWaterSplash();
waterSplash.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
shotNode.attachChild(waterSplash);
waterSplash.emitAllParticles();
@@ -103,45 +104,46 @@ class SeaSynchronizer extends ShipMapSynchronizer {
* @param ship the ship to be sunk
*/
private void sinkAndRemoveShip(Battleship ship) {
Battleship wilkeningklaunichtmeinencode = ship;
final Node shipNode = (Node) getSpatial(wilkeningklaunichtmeinencode);
Battleship dasIstGelebteTeamarbeit = ship;
final Node shipNode = (Node) getSpatial(dasIstGelebteTeamarbeit);
if (shipNode == null) return;
// Add sinking control to animate the sinking
shipNode.addControl(new SinkingControl(shipNode));
shipNode.addControl(new SinkControl(shipNode));
// Add particle effects
ParticleEmitter bubbles = particleFactory.createWaterSplash();
ParticleEmitter bubbles = particlecreator.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");
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
// Create a new node specifically for the hit effects
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 = particlecreator.createFlame();
ParticleEmitter flash = particlecreator.createFlash();
ParticleEmitter spark = particlecreator.createSpark();
ParticleEmitter roundSpark = particlecreator.createRoundSpark();
ParticleEmitter smokeTrail = particlecreator.createSmokeTrail();
ParticleEmitter debris = particlecreator.createDebris();
ParticleEmitter shockwave = particlecreator.createShockwave();
ParticleEmitter movingSmoke = particlecreator.createMovingSmokeEmitter();
// Attach all effects to the hitEffectNode
hitEffectNode.attachChild(flame);
@@ -155,8 +157,8 @@ class SeaSynchronizer extends ShipMapSynchronizer {
// Set the local translation for the hit effect to the point of impact
hitEffectNode.setLocalTranslation(shot.getY() + 0.5f - shipNode.getLocalTranslation().x,
0.5f, // Adjust as needed for height above the ship
shot.getX() + 0.5f - shipNode.getLocalTranslation().z);
0.5f, // Adjust as needed for height above the ship
shot.getX() + 0.5f - shipNode.getLocalTranslation().z);
// Attach the hitEffectNode to the shipNode so it moves with the ship
shipNode.attachChild(hitEffectNode);
@@ -229,12 +231,18 @@ 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 createLargeship(ship);
case 2:
return createMediumship(ship);
case 1:
return createSmallship(ship);
default:
return createBox(ship);
}
}
/**
@@ -284,20 +292,13 @@ class SeaSynchronizer extends ShipMapSynchronizer {
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.
*
* @param ship the battleship to be represented
* @return the spatial representing a small tug boat
*/
private Spatial createSmallship(Battleship ship) {
final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL);
final Spatial model = app.getAssetManager().loadModel(SMALL_SHIP_MODEL);
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
model.scale(0.0005f);
@@ -306,35 +307,21 @@ class SeaSynchronizer extends ShipMapSynchronizer {
return model;
}
/**
* Creates a detailed 3D model to represent a "German WWII UBoat".
*
* @param ship the battleship to be represented
* @return the spatial representing the "German WWII UBoat"
*/
private Spatial createCV(Battleship ship) {
final Spatial model = app.getAssetManager().loadModel(CV_MODEL);
private Spatial createMediumship(Battleship ship) {
final Spatial model = app.getAssetManager().loadModel(U_BOAT_MODEL);
model.rotate(0f, calculateRotationAngle(ship.getRot()), 0f);
model.move(0f, 0.25f, 0f);
model.scale(0.85f);
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
model.scale(0.27f);
model.setShadowMode(ShadowMode.CastAndReceive);
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);
private Spatial createLargeship(Battleship ship) {
final Spatial model = app.getAssetManager().loadModel(TUG_BOAT_MODEL);
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
model.move(0f, -0.06f, 0f);
model.scale(0.27f);
model.scale(0.0004f);
model.setShadowMode(ShadowMode.CastAndReceive);
return model;
@@ -375,4 +362,4 @@ class SeaSynchronizer extends ShipMapSynchronizer {
model.addControl(new ShellControl(shell));
return model;
}
}
}

View File

@@ -42,14 +42,6 @@ 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

View File

@@ -43,14 +43,6 @@ 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

View File

@@ -10,7 +10,7 @@ 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 {
class SinkControl 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;
@@ -21,13 +21,13 @@ class SinkingControl extends AbstractControl {
* Constructs a {@code SinkingControl} object with the shipNode to be to be sunk
* @param shipNode the node to handeld
*/
public SinkingControl(Node shipNode) {
public SinkControl(Node shipNode) {
this.shipNode = shipNode;
}
/**
* Updated the Map to sink the ship
*
*
* @param tpf time per frame
*/
@Override
@@ -46,16 +46,9 @@ class SinkingControl extends AbstractControl {
}
}
/**
* 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
}
}

View File

@@ -18,8 +18,8 @@ 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.AnimationFinishedMessage;
import pp.battleship.message.client.MapMessage;
import pp.battleship.message.client.ShootMessage;
import pp.battleship.message.server.EffectMessage;
@@ -179,4 +179,5 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
else
LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS
}
}
}

View File

@@ -15,3 +15,4 @@ record ReceivedMessage(ClientMessage message, int from) {
message.accept(interpreter, from);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 670 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@@ -42,15 +42,9 @@ 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/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/SmallShip/12219_boat_v2_L2.obj", "SmallShip.j3o"); //NON-NLS
export("Models/WWII_ship_German_Type_II_U-boat_v2/14084_WWII_Ship_German_Type_II_U-boat_v2_L1.obj", "WW2Uboat.j3o"); //NON-NLS
export("Models/TugBoat/12218_tugboat_v1_L2.obj", "TugBoat.j3o"); //NON-NLS
stop();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

Some files were not shown because too many files have changed in this diff Show More