Compare commits
22 Commits
b_wilkenin
...
b_puderbac
Author | SHA1 | Date | |
---|---|---|---|
|
fe41a67341 | ||
|
842eabd32e | ||
|
e4a24c3070 | ||
|
04d16a2882 | ||
|
a798edf07f | ||
|
5dff2c271f | ||
|
b6642a4815 | ||
|
33dba7f3b6 | ||
|
96992c5b03 | ||
|
c525a8994c | ||
|
86a3d90bf8 | ||
|
a6fec62fa0 | ||
|
b8cd71120f | ||
|
fc22ae1819 | ||
|
f27ec36d2b | ||
|
68e252e174 | ||
|
b33ddcb2c2 | ||
|
3386d395fe | ||
|
91b24db6ca | ||
|
0ff5fceae7 | ||
|
f6699c2a0a | ||
|
9ca08c3d0c |
2
.gitignore
vendored
@@ -24,3 +24,5 @@ out
|
||||
.DS_Store
|
||||
!Projekte/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
45.j3o
|
||||
KingGeorge.j3o
|
||||
|
@@ -73,8 +73,7 @@ Betriebssystem:
|
||||
die Zeile:
|
||||
|
||||
`export JAVA_HOME="<Pfad zum entpackten Archiv>"`
|
||||
|
||||
Ersetzen Sie dabei `<Pfad zum entpackten Archiv>` mit dem entsprechenden Pfad.
|
||||
cd Ersetzen Sie dabei `<Pfad zum entpackten Archiv>` mit dem entsprechenden Pfad.
|
||||
Zum Beispiel:
|
||||
|
||||
`export JAVA_HOME="/home/user/jdk-20.0.2"`
|
||||
|
@@ -7,8 +7,15 @@ 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 project(path: ':battleship:server')
|
||||
implementation project(path: ':battleship:server')
|
||||
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
|
@@ -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.
|
||||
|
@@ -23,7 +23,7 @@
|
||||
{
|
||||
"length": 2,
|
||||
"x": 4,
|
||||
"y": 8,
|
||||
"y": 12,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"ships": [
|
||||
{
|
||||
"length": 4,
|
||||
"x": 15,
|
||||
"x": 0,
|
||||
"y": 5,
|
||||
"rot": "DOWN"
|
||||
},
|
||||
|
@@ -11,7 +11,7 @@
|
||||
{
|
||||
"length": 3,
|
||||
"x": 0,
|
||||
"y": 9,
|
||||
"y": 4,
|
||||
"rot": "DOWN"
|
||||
},
|
||||
{
|
||||
@@ -22,7 +22,7 @@
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 0,
|
||||
"x": 4,
|
||||
"y": 8,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
|
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
@@ -7,6 +7,15 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.app.DebugKeysAppState;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.app.StatsAppState;
|
||||
@@ -20,7 +29,10 @@ import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import pp.battleship.client.gui.BattleAppState;
|
||||
import pp.battleship.client.gui.BgMusic;
|
||||
import pp.battleship.client.gui.EditorAppState;
|
||||
import pp.battleship.client.gui.SeaAppState;
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
@@ -35,17 +47,6 @@ import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
|
||||
/**
|
||||
* The main class for the Battleship client application.
|
||||
* It manages the initialization, input setup, GUI setup, and game states for the client.
|
||||
@@ -267,8 +268,8 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
stateManager.detach(stateManager.getState(DebugKeysAppState.class));
|
||||
|
||||
attachGameSound();
|
||||
attachGameMusic();
|
||||
stateManager.attachAll(new EditorAppState(), new BattleAppState(), new SeaAppState());
|
||||
attachBgMusic();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,14 +281,10 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
gameSound.setEnabled(GameSound.enabledInPreferences());
|
||||
stateManager.attach(gameSound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches the music state and sets its initial enabled state.
|
||||
*/
|
||||
private void attachGameMusic() {
|
||||
final GameMusic gameMusic = new GameMusic();
|
||||
gameMusic.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameMusic);
|
||||
private void attachBgMusic() {
|
||||
final BgMusic gameSound = new BgMusic();
|
||||
gameSound.setEnabled(BgMusic.enabledInPreferences());
|
||||
stateManager.attach(gameSound);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,6 +7,10 @@
|
||||
|
||||
package pp.battleship.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;
|
||||
@@ -14,13 +18,9 @@ import com.jme3.asset.AssetLoadException;
|
||||
import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
import pp.battleship.notification.GameEventListener;
|
||||
import pp.battleship.notification.SoundEvent;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
@@ -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,8 +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");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,28 +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,24 +7,25 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.dialog.TextInputDialog;
|
||||
|
||||
import pp.battleship.client.GameMusic;
|
||||
import pp.battleship.client.VolumeSlider;
|
||||
|
||||
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.BgMusic;
|
||||
import pp.battleship.client.gui.VolumeSlider;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.dialog.TextInputDialog;
|
||||
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,
|
||||
@@ -46,12 +47,14 @@ class Menu extends Dialog {
|
||||
public Menu(BattleshipApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
slider = new VolumeSlider(app.getStateManager().getState(BgMusic.class));
|
||||
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.sound-enabled"), new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||
|
||||
addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, BgMusic.class)));
|
||||
|
||||
addChild(slider);
|
||||
|
||||
addChild(loadButton)
|
||||
@@ -73,6 +76,10 @@ class Menu extends Dialog {
|
||||
loadButton.setEnabled(app.getGameLogic().mayLoadMap());
|
||||
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.
|
||||
@@ -149,13 +156,4 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@@ -7,22 +7,22 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
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 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 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 static pp.battleship.Resources.lookup;
|
||||
import pp.battleship.client.server.BattleshipSelfhostServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
|
||||
/**
|
||||
* Represents a dialog for setting up a network connection in the Battleship game.
|
||||
@@ -35,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;
|
||||
@@ -60,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"))
|
||||
@@ -69,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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,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());
|
||||
}
|
||||
|
@@ -1,6 +1,11 @@
|
||||
package pp.battleship.client;
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
@@ -14,9 +19,14 @@ import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
public class GameMusic extends AbstractAppState{
|
||||
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
* An application state that plays sounds.
|
||||
*/
|
||||
public class BgMusic extends AbstractAppState{
|
||||
private static final Logger LOGGER = System.getLogger(BgMusic.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(BgMusic.class);
|
||||
private static final String ENABLED_PREF = "enabled"; //NON-NLS
|
||||
private static final String VOLUME_PREF = "volume"; //NON-NLS
|
||||
|
||||
@@ -31,10 +41,10 @@ public class GameMusic extends AbstractAppState{
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
*
|
||||
* @return //TODO
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
@@ -50,7 +60,7 @@ public class GameMusic extends AbstractAppState{
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app) {
|
||||
super.initialize(stateManager, app);
|
||||
music = loadSound(app, "Sound/DasBootMenu.ogg");
|
||||
music = loadSound(app, "Sound/Music/bgMusic.ogg");
|
||||
setVolume(volumeInPreferences());
|
||||
music.setLooping(true);
|
||||
if (isEnabled() && music != null) {
|
||||
@@ -78,7 +88,7 @@ public class GameMusic extends AbstractAppState{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/** TODO
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
*
|
||||
@@ -108,4 +118,4 @@ public class GameMusic extends AbstractAppState{
|
||||
music.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,19 +7,19 @@
|
||||
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.math.Vector2f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import pp.battleship.client.BattleshipAppState;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import static pp.battleship.client.BattleshipApp.CLICK;
|
||||
import pp.battleship.client.BattleshipAppState;
|
||||
|
||||
/**
|
||||
* EditorState manages the editor mode in the Battleship game,
|
||||
|
@@ -16,6 +16,7 @@ import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial.CullHint;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.ShipMap;
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import static com.jme3.material.Materials.UNSHADED;
|
||||
import com.jme3.material.RenderState;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
@@ -15,12 +16,11 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
* Synchronizes the visual representation of the ship map with the game model.
|
||||
@@ -116,6 +116,8 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
return shipNode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a line geometry representing part of the ship's border.
|
||||
*
|
||||
@@ -129,8 +131,7 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
private Geometry shipLine(float x1, float y1, float x2, float y2, ColorRGBA color) {
|
||||
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.
|
||||
*
|
||||
|
@@ -10,25 +10,28 @@ import com.jme3.math.Vector3f;
|
||||
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
|
||||
public class ParticleCreator {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
ParticleCreator(BattleshipApp app) {
|
||||
ParticleEffectFactory(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)));
|
||||
@@ -54,7 +57,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a flash particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured flash particle emitter
|
||||
*/
|
||||
ParticleEmitter createFlash() {
|
||||
@@ -83,7 +86,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a round spark particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured round spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createRoundSpark() {
|
||||
@@ -111,7 +114,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a spark particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createSpark() {
|
||||
@@ -123,9 +126,9 @@ public class ParticleCreator {
|
||||
spark.setFacingVelocity(true);
|
||||
spark.setParticlesPerSec(0);
|
||||
spark.setGravity(0, 5, 0);
|
||||
spark.setLowLife(0.5f);
|
||||
spark.setLowLife(1.1f);
|
||||
spark.setHighLife(1.5f);
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 8, 0)); // y20
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
|
||||
spark.getParticleInfluencer().setVelocityVariation(1);
|
||||
spark.setImagesX(1);
|
||||
spark.setImagesY(1);
|
||||
@@ -138,7 +141,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a smoke trail particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured smoke trail particle emitter
|
||||
*/
|
||||
ParticleEmitter createSmokeTrail() {
|
||||
@@ -165,7 +168,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a debris particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured debris particle emitter
|
||||
*/
|
||||
ParticleEmitter createDebris() {
|
||||
@@ -181,6 +184,7 @@ public class ParticleCreator {
|
||||
debris.setGravity(0, 12f, 0);
|
||||
debris.setLowLife(1.4f);
|
||||
debris.setHighLife(1.5f);
|
||||
debris.setLocalTranslation(0, 2f, 0);
|
||||
debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 15, 0));
|
||||
debris.getParticleInfluencer().setVelocityVariation(.60f);
|
||||
debris.setImagesX(3);
|
||||
@@ -194,7 +198,7 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* Creates a shockwave particle emitter.
|
||||
*
|
||||
*
|
||||
* @return a configured shockwave particle emitter
|
||||
*/
|
||||
ParticleEmitter createShockwave() {
|
||||
@@ -221,40 +225,35 @@ public class ParticleCreator {
|
||||
|
||||
/**
|
||||
* 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.setLocalTranslation(0, 2f, 0); //___________________
|
||||
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
|
||||
smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
smokeEmitter.setImagesX(15);
|
||||
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() {
|
||||
public ParticleEmitter createWaterSplash() { //wird durch explosions animation ersetzt
|
||||
// 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);
|
||||
@@ -265,14 +264,14 @@ public class ParticleCreator {
|
||||
|
||||
// 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"));
|
@@ -7,24 +7,28 @@
|
||||
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
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;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Box;
|
||||
import com.jme3.scene.shape.Cylinder;
|
||||
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Rotation;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static pp.util.FloatMath.HALF_PI;
|
||||
import static pp.util.FloatMath.PI;
|
||||
|
||||
@@ -36,22 +40,24 @@ 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 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 KING_GEORGE_V_MODEL = "Models/Transporter/cr90.j3o"; //NON-NLS
|
||||
private static final String TIE_FIGHTER = "Models/TieFighter/TieFighter.j3o"; //NON-NLS
|
||||
private static final String TRANSPORTER = "Models/KingGeorgeV/KingGeorge.j3o"; //NON-NLS
|
||||
//private static final String VENATOR = "Models/Venator/Venator.j3o"; //NON-NLS
|
||||
private static final String WING = "Models/Wing/Wing.j3o"; //NON-NLS
|
||||
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
private static final ColorRGBA BOX_COLOR = ColorRGBA.Gray;
|
||||
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
|
||||
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
||||
private static final String LIGHTING = "Common/MatDefs/Light/Lighting.j3md";
|
||||
|
||||
private final ShipMap map;
|
||||
private final BattleshipApp app;
|
||||
private final ParticleCreator particlecreator;
|
||||
|
||||
private final ParticleEffectFactory particleFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||
@@ -64,7 +70,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
super(app.getGameLogic().getOwnMap(), root);
|
||||
this.app = app;
|
||||
this.map = map;
|
||||
this.particlecreator = new ParticleCreator(app);
|
||||
this.particleFactory = new ParticleEffectFactory(app);
|
||||
addExisting();
|
||||
}
|
||||
|
||||
@@ -80,39 +86,27 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
public Spatial visit(Shot shot) {
|
||||
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 = particlecreator.createWaterSplash();
|
||||
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 dasIstGelebteTeamarbeit = ship;
|
||||
final Node shipNode = (Node) getSpatial(dasIstGelebteTeamarbeit);
|
||||
Battleship wilkeningklaunichtmeinencode = ship;
|
||||
final Node shipNode = (Node) getSpatial(wilkeningklaunichtmeinencode);
|
||||
if (shipNode == null) return;
|
||||
|
||||
// Add sinking control to animate the sinking
|
||||
shipNode.addControl(new SinkControl(shipNode));
|
||||
shipNode.addControl(new SinkingControl(shipNode));
|
||||
|
||||
// Add particle effects
|
||||
ParticleEmitter bubbles = particlecreator.createWaterSplash();
|
||||
ParticleEmitter bubbles = particleFactory.createWaterSplash();
|
||||
bubbles.setLocalTranslation(shipNode.getLocalTranslation());
|
||||
shipNode.attachChild(bubbles);
|
||||
bubbles.emitAllParticles();
|
||||
@@ -132,18 +126,17 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
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 = 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();
|
||||
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();
|
||||
|
||||
// Attach all effects to the hitEffectNode
|
||||
hitEffectNode.attachChild(flame);
|
||||
@@ -157,8 +150,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);
|
||||
@@ -172,11 +165,12 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
flame.emitAllParticles();
|
||||
roundSpark.emitAllParticles();
|
||||
|
||||
//Checks if ship is destroyed and triggers animation accordingly
|
||||
if (ship.isDestroyed()) {
|
||||
sinkAndRemoveShip(ship);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -190,15 +184,16 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private Geometry createCylinder(Shot shot) {
|
||||
final ColorRGBA color = shot.isHit() ? HIT_COLOR : SPLASH_COLOR;
|
||||
final float height = shot.isHit() ? 1.2f : 0.1f;
|
||||
|
||||
|
||||
final Cylinder cylinder = new Cylinder(2, 20, 0.45f, height, true);
|
||||
final Geometry geometry = new Geometry(SHOT, cylinder);
|
||||
|
||||
|
||||
geometry.setMaterial(createColoredMaterial(color));
|
||||
geometry.rotate(HALF_PI, 0f, 0f);
|
||||
// compute the center of the shot in world coordinates
|
||||
geometry.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||
|
||||
|
||||
// compute the center of the shot in world coordinates, with an additional 2f height
|
||||
geometry.setLocalTranslation(shot.getY() + 0.5f, 2f + height / 2, shot.getX() + 0.5f);
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@@ -230,20 +225,20 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
* @return the spatial representing the battleship
|
||||
*/
|
||||
private Spatial createShip(Battleship ship) {
|
||||
switch (ship.getLength()) {
|
||||
case 4:
|
||||
return createBattleship(ship);
|
||||
case 3:
|
||||
return createLargeship(ship);
|
||||
case 2:
|
||||
return createMediumship(ship);
|
||||
case 1:
|
||||
return createSmallship(ship);
|
||||
default:
|
||||
return createBox(ship);
|
||||
if (ship.getLength() == 1) {
|
||||
return createTie_Fighter(ship);
|
||||
} else if (ship.getLength() == 2) {
|
||||
return createWing(ship);
|
||||
} else if (ship.getLength() == 3) {
|
||||
return createTransporter(ship);
|
||||
} else if (ship.getLength() == 4) {
|
||||
return createBattleship(ship);
|
||||
} else {
|
||||
return createBox(ship);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a simple box to represent a battleship that is not of the "King George V" type.
|
||||
@@ -282,50 +277,100 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a "King George V" battleship.
|
||||
* Creates a detailed 3D model to represent all battleships.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @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.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private Spatial createSmallship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(SMALL_SHIP_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.0005f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private Spatial createMediumship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(U_BOAT_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.27f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private Spatial createLargeship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(TUG_BOAT_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.0004f);
|
||||
// Berechne den Rotationswinkel
|
||||
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||
model.rotate(0f, rotationAngle, -HALF_PI);
|
||||
model.scale(1.2f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
// Bestimme die Verschiebung basierend auf der Rotation
|
||||
Vector3f translation = model.getLocalTranslation();
|
||||
|
||||
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||
translation = translation.subtract(0,0,1); // Nach hinten auf der Z-Achse, und um 2f nach oben
|
||||
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||
translation = translation.subtract(1,0,0); // Nach hinten auf der X-Achse, und um 2f nach oben
|
||||
}
|
||||
|
||||
model.setLocalTranslation(translation);
|
||||
|
||||
return model;
|
||||
}
|
||||
private Spatial createTransporter(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(TRANSPORTER);
|
||||
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot())+ PI, 0f);
|
||||
model.scale(0.008f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||
Vector3f translation = model.getLocalTranslation();
|
||||
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||
translation = translation.subtract(0,0,1);
|
||||
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||
translation = translation.add(1,0,0);
|
||||
}
|
||||
|
||||
model.setLocalTranslation(translation);
|
||||
|
||||
|
||||
return model;
|
||||
}
|
||||
private Spatial createWing(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(WING);
|
||||
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||
|
||||
// Berechne den Rotationswinkel
|
||||
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||
model.rotate(0f, rotationAngle, 0f);
|
||||
model.scale(0.0008f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
// Bestimme die Verschiebung basierend auf der Rotation
|
||||
Vector3f translation = model.getLocalTranslation();
|
||||
|
||||
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||
translation = translation.add(0,0,0); // Nach hinten auf der Z-Achse, und um 2f nach oben
|
||||
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||
translation = translation.add(0,0,0); // Nach hinten auf der X-Achse, und um 2f nach oben
|
||||
}
|
||||
|
||||
model.setLocalTranslation(translation);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
private Spatial createTie_Fighter(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(TIE_FIGHTER);
|
||||
|
||||
model.rotate(-0f, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.07f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the rotation angle for the specified rotation.
|
||||
@@ -341,7 +386,6 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
case UP -> PI;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a 3D model representation of the given {@code Shell} object
|
||||
* for visualization in the game.
|
||||
@@ -362,4 +406,5 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
model.addControl(new ShellControl(shell));
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@ import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.model.Shell;
|
||||
|
||||
import pp.battleship.model.Shell;
|
||||
import static pp.util.FloatMath.PI;
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ public class ShellControl extends AbstractControl {
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
Vector3f pos = shell.getPosition();
|
||||
Vector3f fixed = new Vector3f(pos.z + 0.5f, pos.y, pos.x + 0.5f);
|
||||
Vector3f fixed = new Vector3f(pos.z + 0.5f, pos.y + 2f, pos.x + 0.5f);
|
||||
fixed.setY(pos.y);
|
||||
spatial.setLocalTranslation(fixed);
|
||||
spatial.setLocalRotation(shell.getRotation());
|
||||
|
@@ -1,18 +1,20 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
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.control.AbstractControl;
|
||||
|
||||
/**
|
||||
* Control that handles the sinking effect for destroyed ships.
|
||||
* It will gradually move the ship downwards and then remove it from the scene.
|
||||
*/
|
||||
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
|
||||
class SinkingControl extends AbstractControl {
|
||||
private static final float SINK_DURATION = 2f; // Duration of the sinking animation
|
||||
private static final float SINK_SPEED = 0.6f; // Speed at which the ship sinks
|
||||
private float elapsedTime = 0;
|
||||
|
||||
private final Node shipNode;
|
||||
@@ -21,13 +23,13 @@ class SinkControl extends AbstractControl {
|
||||
* Constructs a {@code SinkingControl} object with the shipNode to be to be sunk
|
||||
* @param shipNode the node to handeld
|
||||
*/
|
||||
public SinkControl(Node shipNode) {
|
||||
public SinkingControl(Node shipNode) {
|
||||
this.shipNode = shipNode;
|
||||
}
|
||||
|
||||
float tiltAngle= 0;
|
||||
/**
|
||||
* Updated the Map to sink the ship
|
||||
*
|
||||
*
|
||||
* @param tpf time per frame
|
||||
*/
|
||||
@Override
|
||||
@@ -37,13 +39,18 @@ class SinkControl extends AbstractControl {
|
||||
|
||||
// Move the ship down over time
|
||||
Vector3f currentPos = shipNode.getLocalTranslation();
|
||||
shipNode.setLocalTranslation(currentPos.x, currentPos.y - SINK_SPEED * tpf, currentPos.z);
|
||||
|
||||
shipNode.setLocalTranslation(currentPos.x+SINK_SPEED*tpf, currentPos.y - SINK_SPEED * tpf*2, currentPos.z+SINK_SPEED*tpf*2);
|
||||
|
||||
// Check if sinking duration has passed
|
||||
if (elapsedTime >= SINK_DURATION) {
|
||||
// Remove the ship from the scene
|
||||
shipNode.removeFromParent();
|
||||
}
|
||||
// Apply the tilt angle and rotation during sinking
|
||||
float sinkingTiltAngle = FastMath.DEG_TO_RAD * tiltAngle * tpf;
|
||||
float sinkingRotationAngle = FastMath.DEG_TO_RAD * 45f * tpf; // Additional rotation during sinking
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(-sinkingTiltAngle, sinkingRotationAngle, 0);
|
||||
spatial.setLocalRotation(tiltRotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,4 +58,3 @@ class SinkControl extends AbstractControl {
|
||||
// No rendering-related code needed
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,140 @@
|
||||
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 SinkingShip extends AbstractControl {
|
||||
|
||||
private float elapsedTime = 0.2f;
|
||||
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 SinkingShip(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)
|
||||
float sinkingTiltAngle = FastMath.DEG_TO_RAD * tiltAngle * progress;
|
||||
float sinkingRotationAngle = FastMath.DEG_TO_RAD * 45f * progress; // Additional rotation during sinking (test)
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(-sinkingTiltAngle, sinkingRotationAngle, sinkingRotationAngle);
|
||||
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);
|
||||
}
|
||||
// public void checkAndTriggerExplosion() {
|
||||
// // Prüfen, ob das sinkende Schiff den Boden erreicht hat
|
||||
// if (spatial != null && spatial.getLocalTranslation().y <= sinkDepth) {
|
||||
// // Explosion ausführen, wenn der Boden erreicht ist
|
||||
// triggerExplosionAnimation();
|
||||
//
|
||||
// // Entfernen des Schiffs aus dem Elternknoten
|
||||
// Node parentNode = (Node) spatial.getParent();
|
||||
// if (parentNode != null) {
|
||||
// parentNode.detachChild(spatial);
|
||||
// }
|
||||
//
|
||||
// // Entfernen der Kontrolle vom Spatial
|
||||
// spatial.removeControl(this);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void triggerExplosionAnimation() {
|
||||
// // Code für die Explosion-Animation (alibi Methode)
|
||||
// System.out.println("Explosion wird ausgeführt: Das Schiff hat den Boden erreicht!");
|
||||
// // Hier könnte eine echte Animation eingefügt werden, z.B. Partikeleffekte
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
// --> sinkingControl
|
||||
}
|
||||
}
|
@@ -1,17 +1,17 @@
|
||||
package pp.battleship.client;
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
|
||||
public class VolumeSlider extends Slider {
|
||||
|
||||
private final GameMusic music;
|
||||
private final BgMusic music;
|
||||
|
||||
private double vol;
|
||||
|
||||
public VolumeSlider(GameMusic music) {
|
||||
public VolumeSlider(BgMusic music) {
|
||||
super();
|
||||
this.music = music;
|
||||
vol = GameMusic.volumeInPreferences();
|
||||
vol = BgMusic.volumeInPreferences();
|
||||
getModel().setPercent(vol);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ public class VolumeSlider extends Slider {
|
||||
music.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -5,30 +5,7 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
import com.jme3.network.Message;
|
||||
import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
import com.jme3.network.Server;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
import pp.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.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;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
import pp.battleship.message.server.StartBattleMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shot;
|
||||
package pp.battleship.client.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -39,17 +16,41 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
import com.jme3.network.Message;
|
||||
import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
import com.jme3.network.Server;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
|
||||
import pp.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.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
import pp.battleship.message.server.StartBattleMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -67,13 +68,13 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
* Starts the Battleships 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);
|
||||
@@ -116,24 +117,24 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
Serializer.registerClass(ShootMessage.class);
|
||||
Serializer.registerClass(EffectMessage.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -179,5 +180,4 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
else
|
||||
LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -5,14 +5,13 @@
|
||||
// (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);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 235 KiB |
Before Width: | Height: | Size: 94 KiB |
@@ -1,3 +0,0 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/wwii-ship-uk-king-george-v-class-battleship-v1--185381.html
|
||||
License: Free Personal Use Only
|
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 166 KiB |
Before Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 354 KiB |
After Width: | Height: | Size: 164 KiB |
After Width: | Height: | Size: 220 KiB |
Before Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 168 KiB |
@@ -1,6 +1,6 @@
|
||||
Material Water : Common/MatDefs/Light/Lighting.j3md {
|
||||
MaterialParameters {
|
||||
Shininess : 64
|
||||
Shininess : 6
|
||||
DiffuseMap : Repeat Textures/Terrain/Water/Water_002_COLOR.jpg
|
||||
NormalMap : Repeat Textures/Terrain/Water/Water_002_NORM.jpg
|
||||
SpecularMap : Repeat Textures/Terrain/Water/Water_002_ROUGH.jpg
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,2 @@
|
||||
[LocalizedFileNames]
|
||||
Water_002_NORM.jpg=@Water_002_NORM,0
|
@@ -1,12 +1,10 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.exporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.binary.BinaryExporter;
|
||||
@@ -14,11 +12,6 @@ import com.jme3.scene.Spatial;
|
||||
import com.jme3.system.JmeContext;
|
||||
import com.jme3.util.TangentBinormalGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* This class transforms models into j3o format.
|
||||
*/
|
||||
@@ -41,10 +34,14 @@ public class ModelExporter extends SimpleApplication {
|
||||
*/
|
||||
@Override
|
||||
public void simpleInitApp() {
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o"); //NON-NLS
|
||||
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
|
||||
export("Models/45.obj", "45.j3o");//NON-NLS passt
|
||||
//export("Models/.j3o");
|
||||
// export("Models/Transporter/Transporter.obj", "Transporter.j3o"); //NON-NLS passt
|
||||
// export("Models/TieFighter.obj", "TieFighter.j3o"); //NON-NLS
|
||||
// export("Models/Venator/Venator.obj", "Venator.j3o"); //NON-NLS kickt
|
||||
|
||||
|
||||
|
||||
stop();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,72 @@
|
||||
# Blender MTL File: 'SpaceShipDetailed.blend'
|
||||
# Material Count: 7
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.002
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.003
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.004
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.005
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.006
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.007
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
16605
Projekte/battleship/converter/src/main/resources/Models/KingGeorge.obj
Normal file
Before Width: | Height: | Size: 235 KiB |
@@ -1,18 +0,0 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 16.03.2012 14:15:53
|
||||
|
||||
newmtl _King_George_V
|
||||
Ns 60.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.4500 0.4500 0.4500
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka King_George_V.jpg
|
||||
map_Kd King_George_V.jpg
|
||||
map_bump King_George_V_bump.jpg
|
||||
bump King_George_V_bump.jpg
|
Before Width: | Height: | Size: 94 KiB |
@@ -1,3 +0,0 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/wwii-ship-uk-king-george-v-class-battleship-v1--185381.html
|
||||
License: Free Personal Use Only
|
@@ -1,104 +0,0 @@
|
||||
# 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
|
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 166 KiB |
Before Width: | Height: | Size: 98 KiB |
31138
Projekte/battleship/converter/src/main/resources/Models/TieFighter.obj
Normal file
Before Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 47 KiB |
@@ -1,154 +0,0 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 21.12.2011 10:51:13
|
||||
|
||||
newmtl 12218_tugboat_tube
|
||||
Ns 40.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.1800 0.1800 0.1800
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 12218_tugboat_tube_diffuse.jpg
|
||||
map_Kd 12218_tugboat_tube_diffuse.jpg
|
||||
|
||||
newmtl 12218_tugboat_cabine
|
||||
Ns 40.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.1800 0.1800 0.1800
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 12218_tugboat_cabine_diffuse.jpg
|
||||
map_Kd 12218_tugboat_cabine_diffuse.jpg
|
||||
|
||||
newmtl 12218_tugboat_boat
|
||||
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.5400 0.5400 0.5400
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 12218_tugboat_boat_diffuse.jpg
|
||||
map_Kd 12218_tugboat_boat_diffuse.jpg
|
||||
|
||||
newmtl 12218_tugboat_blackpaint
|
||||
Ns 40.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.1333 0.1333 0.1333
|
||||
Kd 0.1333 0.1333 0.1333
|
||||
Ks 0.1725 0.1725 0.1725
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_yellowpaint
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.8196 0.6588 0.1725
|
||||
Kd 0.8196 0.6588 0.1725
|
||||
Ks 0.6471 0.6471 0.6471
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_crane
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.6314 0.0588 0.0588
|
||||
Kd 0.6314 0.0588 0.0588
|
||||
Ks 0.6471 0.6471 0.6471
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_orangepaint
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.8627 0.2549 0.1137
|
||||
Kd 0.8627 0.2549 0.1137
|
||||
Ks 0.6471 0.6471 0.6471
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_whitepaint
|
||||
Ns 60.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.8667 0.8667 0.8667
|
||||
Kd 0.8667 0.8667 0.8667
|
||||
Ks 0.7765 0.7765 0.7765
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_greypaint
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.3373 0.3412 0.3490
|
||||
Kd 0.3373 0.3412 0.3490
|
||||
Ks 0.6471 0.6471 0.6471
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_bronze
|
||||
Ns 75.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.5529 0.4275 0.0000
|
||||
Kd 0.5529 0.4275 0.0000
|
||||
Ks 0.6471 0.6471 0.6471
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 12218_tugboat_saferound
|
||||
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 12218_tugboat_saferound_diffuse.jpg
|
||||
map_Kd 12218_tugboat_saferound_diffuse.jpg
|
||||
|
||||
newmtl 12218_tugboat_dirtdark
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.1216 0.1059 0.0863
|
||||
Kd 0.1216 0.1059 0.0863
|
||||
Ks 0.0000 0.0000 0.0000
|
||||
Ke 0.0000 0.0000 0.0000
|
@@ -1,16 +0,0 @@
|
||||
# 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
|
Before Width: | Height: | Size: 168 KiB |
BIN
Projekte/battleship/converter/src/main/resources/Models/Wing.j3o
Normal file
@@ -0,0 +1,48 @@
|
||||
# WaveFront *.mtl file (generated by CINEMA 4D)
|
||||
|
||||
newmtl small parts
|
||||
Kd 0.50599998235703 0.53606665134430 0.55000001192093
|
||||
Ks 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl body . blue
|
||||
Kd 0.08579999953508 0.18754999339581 0.33000001311302
|
||||
Ks 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl Mat
|
||||
Ka 1.44000005722046 1.11624002456665 0.41760000586510
|
||||
Kd 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
d 0
|
||||
Tf 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
illum 7
|
||||
|
||||
newmtl Body
|
||||
Kd 0.62400001287460 0.64219999313354 0.64999997615814
|
||||
Ks 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl body . Red .1
|
||||
Kd 0.70999997854233 0.16329999268055 0.16329999268055
|
||||
Ks 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl Mat.1
|
||||
Kd 0.00000000000000 0.00000000000000 0.00000000000000
|
||||
Ks 0.72000002861023 0.72000002861023 0.72000002861023
|
||||
Ns 100
|
||||
d 0
|
||||
Tf 0.60000002384186 0.60000002384186 0.60000002384186
|
||||
Ni 1.517
|
||||
illum 7
|
||||
|
||||
newmtl Body 2 Dark
|
||||
Kd 0.20460000634193 0.21537999808788 0.21999999880791
|
||||
Ks 1.00000000000000 1.00000000000000 1.00000000000000
|
||||
Ns 100
|
||||
illum 7
|
||||
|
38127
Projekte/battleship/converter/src/main/resources/Models/Wing.obj
Normal file
@@ -7,6 +7,8 @@
|
||||
|
||||
package pp.battleship.game.client;
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.IntPoint;
|
||||
@@ -14,8 +16,6 @@ import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.notification.Sound;
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* Represents the state of the client where players take turns to attack each other's ships.
|
||||
*/
|
||||
@@ -72,4 +72,11 @@ class BattleState extends ClientState {
|
||||
private ShipMap affectedMap(EffectMessage msg) {
|
||||
return msg.isOwnShot() ? logic.getOpponentMap() : logic.getOwnMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the opponent's ship was destroyed by the player's shot.
|
||||
*
|
||||
* @param msg the effect message received from the server
|
||||
* @return true if the shot destroyed an opponent's ship, false otherwise
|
||||
*/
|
||||
}
|
||||
|
@@ -7,6 +7,13 @@
|
||||
|
||||
package pp.battleship.game.server;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
@@ -19,12 +26,6 @@ import pp.battleship.message.server.StartBattleMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Controls the server-side game logic for Battleship.
|
||||
@@ -53,7 +54,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state of the game.
|
||||
* Returns the state of the game.
|
||||
*/
|
||||
ServerState getState() {
|
||||
return state;
|
||||
@@ -136,7 +137,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
/**
|
||||
* Handles the reception of a MapMessage.
|
||||
* Also tests if Map is in correct format
|
||||
* Also tests valid ship placement on the Map.
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
@@ -145,14 +146,17 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(MapMessage msg, int from) {
|
||||
if (state != ServerState.SET_UP)
|
||||
LOGGER.log(Level.ERROR, "playerReady not allowed in {0}", state); //NON-NLS
|
||||
else {
|
||||
if (checkMap(msg.getShips())) {
|
||||
playerReady(getPlayerById(from), msg.getShips());
|
||||
} else {
|
||||
LOGGER.log(Level.WARNING, "Invalid Map sent from player {0}", from); //NON-NLS
|
||||
send(players.get(from), new GameDetails(config));
|
||||
}
|
||||
|
||||
|
||||
List<Battleship> ships = msg.getShips();
|
||||
|
||||
if (! mapTest(ships)){
|
||||
LOGGER.log(Level.ERROR, "Geladene Karte von Spieler {0} enthält unzulässige Schiffe", from);
|
||||
send(getPlayerById(from),null);
|
||||
return;
|
||||
}
|
||||
|
||||
playerReady(getPlayerById(from), msg.getShips());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,11 +169,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
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);
|
||||
else
|
||||
shoot(getPlayerById(from), msg.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,17 +230,33 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
}
|
||||
}
|
||||
//Aufgabe 8
|
||||
|
||||
/* Tests if any ship in the list occupies the space of another ship and marks occupied points in the Map.
|
||||
* @param ships list of ships to validate
|
||||
* @return {@code true} if all ships positions are valid, {@code false} otherwise
|
||||
private boolean isInBounds(Battleship ship){
|
||||
return ship.getMinX() >= 0 && ship.getMaxX() < config.getMapWidth() &&
|
||||
ship.getMinY() >= 0 && ship.getMaxY() < config.getMapHeight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean mapTest(List<Battleship> ships) {
|
||||
Set<IntPoint> belegt = new HashSet<>();
|
||||
return ships.stream().allMatch(ship -> isInBounds(ship) &&
|
||||
ship.getPositions().stream().allMatch(belegt::add));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a AnimationFinishedMessage.
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void received(AnimationFinishedMessage msg, int from) {
|
||||
if (state != ServerState.ANIMATION) {
|
||||
LOGGER.log(Level.ERROR, "animation finished not allowed in {0}", state);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
LOGGER.log(Level.DEBUG, "anim received from {0}", getPlayerById(from));
|
||||
Player player = getPlayerById(from);
|
||||
if (!waitPlayers.add(player)) {
|
||||
@@ -252,31 +269,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Tests if a given ship is positioned inside of Map constrains
|
||||
* @param ship the ship to validate
|
||||
* @return {@code true} if a ship is not violating constrains, {@code false} otherwise
|
||||
*/
|
||||
|
||||
private boolean checkMap(List<Battleship> ships) {
|
||||
int numShips = config.getShipNums().values().stream().mapToInt(Integer::intValue).sum();
|
||||
if (numShips != ships.size()) return false;
|
||||
|
||||
List<IntPoint> occupied = new ArrayList<>();
|
||||
|
||||
for (Battleship battleship : ships) {
|
||||
int x = battleship.getX();
|
||||
int y = battleship.getY();
|
||||
for (int i = 0; i < battleship.getLength(); i++) {
|
||||
if (x >= 0 && x < config.getMapWidth() && y >= 0 && y < config.getMapHeight() && !occupied.contains(new IntPoint(x, y))) {
|
||||
occupied.add(new IntPoint(x, y));
|
||||
x += battleship.getRot().dx();
|
||||
y += battleship.getRot().dy();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -26,13 +26,13 @@ enum ServerState {
|
||||
*/
|
||||
BATTLE,
|
||||
|
||||
/**
|
||||
* The server is waiting for all clients to finish the shoot animation.
|
||||
*/
|
||||
ANIMATION,
|
||||
|
||||
/**
|
||||
* The game has ended because all the ships of one player have been destroyed.
|
||||
*/
|
||||
GAME_OVER
|
||||
GAME_OVER,
|
||||
|
||||
/**
|
||||
* The server is waiting for all clients to finish the shoot animation.
|
||||
*/
|
||||
ANIMATION
|
||||
}
|
||||
|
@@ -64,12 +64,6 @@ class Copycat implements ClientInterpreter {
|
||||
copiedMessage = new MapMessage(msg.getShips().stream().map(Copycat::copy).toList());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(AnimationFinishedMessage msg, int from) {
|
||||
copiedMessage = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of the provided {@link Battleship}.
|
||||
*
|
||||
@@ -79,4 +73,10 @@ class Copycat implements ClientInterpreter {
|
||||
private static Battleship copy(Battleship ship) {
|
||||
return new Battleship(ship.getLength(), ship.getX(), ship.getY(), ship.getRot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(AnimationFinishedMessage msg, int from) {
|
||||
copiedMessage = msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
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.server.EffectMessage;
|
||||
@@ -122,7 +121,6 @@ class RobotClient implements ServerInterpreter {
|
||||
@Override
|
||||
public void received(EffectMessage msg) {
|
||||
LOGGER.log(Level.INFO, "Received EffectMessage: {0}", msg); //NON-NLS
|
||||
connection.sendRobotMessage(new AnimationFinishedMessage());
|
||||
if (msg.isMyTurn())
|
||||
shoot();
|
||||
}
|
||||
|
@@ -22,3 +22,4 @@ public class AnimationFinishedMessage extends ClientMessage {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,14 +7,15 @@
|
||||
|
||||
package pp.battleship.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a battleship in the game. A battleship is characterized by its length, position,
|
||||
@@ -321,4 +322,14 @@ public class Battleship implements Item {
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
public List<IntPoint> getPositions() {
|
||||
List<IntPoint> positions = new ArrayList<>();
|
||||
for (int x = getMinX(); x <= getMaxX(); x++) {
|
||||
for (int y = getMinY(); y <= getMaxY(); y++) {
|
||||
positions.add(new IntPoint(x, y));
|
||||
}
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -123,3 +123,4 @@ public class Shell implements Item {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,16 +7,16 @@
|
||||
|
||||
package pp.battleship.model;
|
||||
|
||||
import pp.battleship.notification.GameEvent;
|
||||
import pp.battleship.notification.GameEventBroker;
|
||||
import pp.battleship.notification.ItemAddedEvent;
|
||||
import pp.battleship.notification.ItemRemovedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import pp.battleship.notification.GameEvent;
|
||||
import pp.battleship.notification.GameEventBroker;
|
||||
import pp.battleship.notification.ItemAddedEvent;
|
||||
import pp.battleship.notification.ItemRemovedEvent;
|
||||
|
||||
/**
|
||||
* Represents a rectangular map that holds ships and registers shots fired.
|
||||
* It also supports event notification for game state changes such as item addition or removal.
|
||||
@@ -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.
|
||||
@@ -258,4 +249,8 @@ public class ShipMap {
|
||||
if (eventBroker != null)
|
||||
eventBroker.notifyListeners(event);
|
||||
}
|
||||
|
||||
public void add(Shell shell) {
|
||||
addItem(shell);
|
||||
}
|
||||
}
|
||||
|
@@ -31,9 +31,10 @@ public interface Visitor<T> {
|
||||
|
||||
/**
|
||||
* Visits a Shell element
|
||||
*
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
* @return the result of visitung the Battleship element
|
||||
*/
|
||||
T visit(Shell shell);
|
||||
}
|
||||
|
||||
|
@@ -32,3 +32,4 @@ public interface VoidVisitor {
|
||||
*/
|
||||
void visit(Shell shell);
|
||||
}
|
||||
|
||||
|
@@ -22,9 +22,9 @@ public enum Sound {
|
||||
/**
|
||||
* Sound of a ship being destroyed.
|
||||
*/
|
||||
DESTROYED_SHIP,
|
||||
DESTROYED_SHIP,
|
||||
/**
|
||||
* Sound of a ship being destroyed.
|
||||
* Sound of flying Shell
|
||||
*/
|
||||
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,4 @@ 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
|
||||
|
||||
|
@@ -7,6 +7,15 @@
|
||||
|
||||
package pp.battleship.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
import com.jme3.network.Message;
|
||||
@@ -14,6 +23,7 @@ import com.jme3.network.MessageListener;
|
||||
import com.jme3.network.Network;
|
||||
import com.jme3.network.Server;
|
||||
import com.jme3.network.serializing.Serializer;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.game.server.Player;
|
||||
import pp.battleship.game.server.ServerGameLogic;
|
||||
@@ -30,15 +40,6 @@ import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
*/
|
||||
@@ -116,17 +117,17 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
Serializer.registerClass(ShootMessage.class);
|
||||
Serializer.registerClass(EffectMessage.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,7 +19,6 @@ dependencyResolutionManagement {
|
||||
library('jme3-testdata', 'org.jmonkeyengine', 'jme3-testdata').versionRef('jme')
|
||||
library('jme3-lwjgl', 'org.jmonkeyengine', 'jme3-lwjgl').versionRef('jme')
|
||||
library('jme3-lwjgl3', 'org.jmonkeyengine', 'jme3-lwjgl3').versionRef('jme')
|
||||
library('jme3-effects', 'org.jmonkeyengine', 'jme3-effects').versionRef('jme')
|
||||
|
||||
library('lemur', 'com.simsilica:lemur:1.16.0')
|
||||
library('lemur-proto', 'com.simsilica:lemur-proto:1.13.0')
|
||||
|