Compare commits
17 Commits
b_Beck_Ced
...
b_Bauer_Lu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66798eb3e4 | ||
|
|
edff9e1ad9 | ||
|
|
bf16a18b71 | ||
|
|
6100e95e76 | ||
|
|
1b7b842ca7 | ||
|
|
865b0fc33c | ||
|
|
5a9b0b1de0 | ||
|
|
8650fa5b58 | ||
|
|
113da79df6 | ||
|
|
e41d21584a | ||
|
|
5e773ca1ba | ||
|
|
b2b3bc23bf | ||
|
|
ce490fb877 | ||
|
|
ce5e908349 | ||
|
|
07e922d01e | ||
|
|
42b442e937 | ||
|
|
93ade34282 |
@@ -1,18 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="BattleshipApp (Mac)" type="Application" factoryName="Application"
|
||||
singleton="false">
|
||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp"/>
|
||||
<module name="Projekte.battleship.client.main"/>
|
||||
<option name="VM_PARAMETERS" value="-XstartOnFirstThread"/>
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pp.battleship.client.*"/>
|
||||
<option name="ENABLED" value="true"/>
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true"/>
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="false" name="BattleshipApp (Mac)" type="Application" factoryName="Application" singleton="false">
|
||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp" />
|
||||
<module name="Projekte.battleship.client.main" />
|
||||
<option name="VM_PARAMETERS" value="-XstartOnFirstThread" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pp.battleship.client.server.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,18 +1,19 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="BattleshipApp" type="Application" factoryName="Application" singleton="false"
|
||||
nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp"/>
|
||||
<module name="Projekte.battleship.client.main"/>
|
||||
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/>
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
||||
<configuration default="false" name="BattleshipApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true">
|
||||
<option name="ALTERNATIVE_JRE_PATH" value="temurin-20" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
|
||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp" />
|
||||
<module name="Gruppe-01" />
|
||||
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="pp.battleship.client.*"/>
|
||||
<option name="ENABLED" value="true"/>
|
||||
<option name="PATTERN" value="pp.battleship.client.server.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true"/>
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -9,6 +9,7 @@ implementation project(":jme-common")
|
||||
implementation project(":battleship:model")
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.jme3.effects
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
|
||||
66
Projekte/battleship/client/maps/map3.json
Normal file
66
Projekte/battleship/client/maps/map3.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"width": 10,
|
||||
"height": 10,
|
||||
"ships": [
|
||||
{
|
||||
"length": 4,
|
||||
"x": 2,
|
||||
"y": 8,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 3,
|
||||
"x": 2,
|
||||
"y": 5,
|
||||
"rot": "DOWN"
|
||||
},
|
||||
{
|
||||
"length": 3,
|
||||
"x": 5,
|
||||
"y": 6,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 4,
|
||||
"y": 4,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 7,
|
||||
"y": 4,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 7,
|
||||
"y": 4,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
66
Projekte/battleship/client/maps/map4.json
Normal file
66
Projekte/battleship/client/maps/map4.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"width": 10,
|
||||
"height": 10,
|
||||
"ships": [
|
||||
{
|
||||
"length": 1,
|
||||
"x": 9,
|
||||
"y": 0,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 1,
|
||||
"x": 9,
|
||||
"y": 1,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 1,
|
||||
"x": 8,
|
||||
"y": 0,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 1,
|
||||
"x": 8,
|
||||
"y": 1,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 8,
|
||||
"y": 2,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 2,
|
||||
"x": 6,
|
||||
"y": 1,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 3,
|
||||
"x": 5,
|
||||
"y": 2,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 3,
|
||||
"x": 7,
|
||||
"y": 3,
|
||||
"rot": "RIGHT"
|
||||
},
|
||||
{
|
||||
"length": 4,
|
||||
"x": 6,
|
||||
"y": 4,
|
||||
"rot": "RIGHT"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.audio.AudioData.DataType;
|
||||
import com.jme3.audio.AudioNode;
|
||||
import com.jme3.audio.AudioSource.Status;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
public class BackgroundMusic {
|
||||
|
||||
private static final String VOLUME_PREF = "volume";
|
||||
private static final String MUSIC_ENABLED_PREF = "musicEnabled";
|
||||
private Preferences prefs = Preferences.userNodeForPackage(BackgroundMusic.class);
|
||||
|
||||
private final AudioNode backgroundMusic;
|
||||
private boolean musicEnabled;
|
||||
private float volume;
|
||||
|
||||
/**
|
||||
* Constuctor for the BackgroundMusic
|
||||
* @param app for synchronising and saving data with the application
|
||||
* @param musicFilePath the filepath for the BackgroundMusic
|
||||
*/
|
||||
public BackgroundMusic(Application app, String musicFilePath) {
|
||||
this.volume = prefs.getFloat(VOLUME_PREF, 1.0f);
|
||||
this.musicEnabled = prefs.getBoolean(MUSIC_ENABLED_PREF, true);
|
||||
|
||||
backgroundMusic = new AudioNode(app.getAssetManager(), musicFilePath, DataType.Stream);
|
||||
backgroundMusic.setLooping(true);
|
||||
backgroundMusic.setPositional(false);
|
||||
backgroundMusic.setVolume(1.0f);
|
||||
|
||||
if (musicEnabled) {
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the condition is met to play BackgroundMusic
|
||||
*/
|
||||
public void play() {
|
||||
if (musicEnabled && (backgroundMusic.getStatus() == Status.Stopped || backgroundMusic.getStatus() == Status.Paused)) {
|
||||
backgroundMusic.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function to stop the BackgroundMusic
|
||||
*/
|
||||
public void stop() {
|
||||
if (backgroundMusic.getStatus() == Status.Playing) {
|
||||
backgroundMusic.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function to toggle the Backgroundmusic also sets the volume to the previous session
|
||||
*/
|
||||
public void toogleMusic() {
|
||||
this.musicEnabled = !this.musicEnabled;
|
||||
if (musicEnabled) {
|
||||
play();
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
prefs.putFloat(VOLUME_PREF, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Volume also safes the volume from the previous session
|
||||
* @param volume variable for the volume of the BackgroundMusic
|
||||
*/
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
backgroundMusic.setVolume(volume);
|
||||
prefs.putFloat(VOLUME_PREF, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for Volume
|
||||
* @return a float value of the volume
|
||||
*/
|
||||
public float getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for musicEnabled
|
||||
* @return if the music is enabled return true, false otherwise
|
||||
*/
|
||||
public boolean isMusicEnabled() {
|
||||
return musicEnabled;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,10 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
* Listener for handling actions triggered by the Escape key.
|
||||
*/
|
||||
private final ActionListener escapeListener = (name, isPressed, tpf) -> escape(isPressed);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private BackgroundMusic backgroundMusic;
|
||||
|
||||
static {
|
||||
// Configure logging
|
||||
@@ -141,6 +145,7 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new BattleshipApp().start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,6 +230,7 @@ public void simpleInitApp() {
|
||||
setupStates();
|
||||
setupGui();
|
||||
serverConnection.connect();
|
||||
backgroundMusic = new BackgroundMusic(this, "Sound/Effects/BackgroundMusic/boss_battle_#2_metal_opening.wav");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,4 +432,12 @@ void errorDialog(String errorMessage) {
|
||||
.build()
|
||||
.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the BackgroundMusic
|
||||
* @return the BackgroundMusic
|
||||
*/
|
||||
public BackgroundMusic getBackgroundMusic(){
|
||||
return backgroundMusic;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
private AudioNode splashSound;
|
||||
private AudioNode shipDestroyedSound;
|
||||
private AudioNode explosionSound;
|
||||
private AudioNode missileLaunch;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
@@ -44,13 +45,6 @@ public static boolean enabledInPreferences() {
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
@@ -78,6 +72,7 @@ public void initialize(AppStateManager stateManager, Application app) {
|
||||
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
|
||||
missileLaunch = loadSound(app, "Sound/Effects/missileLaunch.wav");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,13 +88,19 @@ private AudioNode loadSound(Application app, String name) {
|
||||
sound.setLooping(false);
|
||||
sound.setPositional(false);
|
||||
return sound;
|
||||
}
|
||||
catch (AssetLoadException | AssetNotFoundException ex) {
|
||||
} catch (AssetLoadException | AssetNotFoundException ex) {
|
||||
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the missile launch sound effect.
|
||||
*/
|
||||
public void missileLaunch() {
|
||||
missileLaunch.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the splash sound effect.
|
||||
*/
|
||||
@@ -124,12 +125,17 @@ public void shipDestroyed() {
|
||||
shipDestroyedSound.playInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the according case for the soundeffect
|
||||
* @param event the received event
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(SoundEvent event) {
|
||||
switch (event.sound()) {
|
||||
case EXPLOSION -> explosion();
|
||||
case SPLASH -> splash();
|
||||
case DESTROYED_SHIP -> shipDestroyed();
|
||||
case MISSILE_LAUNCH -> missileLaunch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.dialog.TextInputDialog;
|
||||
import com.simsilica.lemur.DefaultRangedValueModel;
|
||||
import com.simsilica.lemur.Slider;
|
||||
import com.simsilica.lemur.core.VersionedReference;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -33,6 +37,7 @@ class Menu extends Dialog {
|
||||
private final BattleshipApp app;
|
||||
private final Button loadButton = new Button(lookup("menu.map.load"));
|
||||
private final Button saveButton = new Button(lookup("menu.map.save"));
|
||||
private final VersionedReference<Double> volumeRef;
|
||||
|
||||
/**
|
||||
* Constructs the Menu dialog for the Battleship application.
|
||||
@@ -45,6 +50,20 @@ public Menu(BattleshipApp app) {
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
||||
addChild(new Checkbox(lookup("menu.sound-enabled"),
|
||||
new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
Checkbox musicToggle = new Checkbox(lookup("menu.music.toggle"));
|
||||
musicToggle.setChecked(app.getBackgroundMusic().isMusicEnabled());
|
||||
musicToggle.addClickCommands(s -> toggleMusic());
|
||||
|
||||
addChild(musicToggle);
|
||||
|
||||
Slider volumeSlider = new Slider();
|
||||
volumeSlider.setModel(new DefaultRangedValueModel(0.0 , 2.0, app.getBackgroundMusic().getVolume()));
|
||||
volumeSlider.setDelta(0.1);
|
||||
addChild(volumeSlider);
|
||||
|
||||
volumeRef = volumeSlider.getModel().createReference();
|
||||
|
||||
addChild(loadButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton)
|
||||
@@ -56,6 +75,33 @@ public Menu(BattleshipApp app) {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the volume if there is a change and adjusts it accordingly.
|
||||
* @param tmp unused time parameter
|
||||
*/
|
||||
public void update(float tmp){
|
||||
if(volumeRef.update()) {
|
||||
double newVolume = volumeRef.get();
|
||||
adjustVolume(newVolume);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the background music volume to the specified value.
|
||||
* @param newVolume the new volume level
|
||||
*/
|
||||
|
||||
private void adjustVolume(double newVolume) {
|
||||
app.getBackgroundMusic().setVolume((float) newVolume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the background music on or off.
|
||||
*/
|
||||
private void toggleMusic(){
|
||||
app.getBackgroundMusic().toogleMusic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of the load and save buttons based on the game logic.
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import pp.battleship.client.server.BattleshipServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
@@ -37,6 +36,10 @@ class NetworkDialog extends SimpleDialog {
|
||||
private int portNumber;
|
||||
private Future<Object> connectionFuture;
|
||||
private Dialog progressDialog;
|
||||
private BattleshipServer battleshipServer;
|
||||
private boolean GUI = true;
|
||||
private Container menu;
|
||||
private boolean serverToggle = false;
|
||||
|
||||
/**
|
||||
* Constructs a new NetworkDialog.
|
||||
@@ -50,47 +53,127 @@ class NetworkDialog extends SimpleDialog {
|
||||
host.setPreferredWidth(400f);
|
||||
port.setSingleLine(true);
|
||||
|
||||
final BattleshipApp app = network.getApp();
|
||||
final Container input = new Container(new SpringGridLayout());
|
||||
input.addChild(new Label(lookup("host.name") + ": "));
|
||||
input.addChild(host, 1);
|
||||
input.addChild(new Label(lookup("port.number") + ": "));
|
||||
input.addChild(port, 1);
|
||||
this.menu = new Container();
|
||||
menu();
|
||||
addChild(menu);
|
||||
}
|
||||
|
||||
DialogBuilder.simple(app.getDialogManager())
|
||||
.setTitle(lookup("server.dialog"))
|
||||
.setExtension(d -> d.addChild(input))
|
||||
.setOkButton(lookup("button.connect"), d -> connect())
|
||||
.setNoButton(lookup("button.cancel"), app::closeApp)
|
||||
.setOkClose(false)
|
||||
.setNoClose(false)
|
||||
.build(this);
|
||||
/**
|
||||
* Main Menu creation
|
||||
*/
|
||||
private void menu() {
|
||||
|
||||
Button connectGame = new Button("Multiplayer");
|
||||
connectGame.addClickCommands(source -> serverConnectGUI());
|
||||
Checkbox serverHost = new Checkbox("Host own Game");
|
||||
serverHost.addClickCommands(source -> toggleServer());
|
||||
|
||||
|
||||
menu.addChild(serverHost);
|
||||
menu.addChild(connectGame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic for the ServerGUI
|
||||
*/
|
||||
private void serverConnectGUI() {
|
||||
LOGGER.log(Level.INFO, "Hosting Server...");
|
||||
|
||||
if (GUI) {
|
||||
host.setSingleLine(true);
|
||||
host.setPreferredWidth(400f);
|
||||
port.setSingleLine(true);
|
||||
|
||||
final BattleshipApp app = network.getApp();
|
||||
final Container input = new Container(new SpringGridLayout());
|
||||
|
||||
input.addChild(new Label(lookup("host.name") + ": "));
|
||||
input.addChild(host, 1);
|
||||
input.addChild(new Label(lookup("port.number") + ": "));
|
||||
input.addChild(port, 1);
|
||||
|
||||
DialogBuilder.simple(app.getDialogManager())
|
||||
.setTitle(lookup("server.dialog"))
|
||||
.setExtension(d -> d.addChild(input))
|
||||
.setOkButton(lookup("button.connect"), d -> connect())
|
||||
.setOkClose(false)
|
||||
.build(this);
|
||||
GUI = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to server if serverToggle is false hosts otherwise
|
||||
*/
|
||||
private void connect(){
|
||||
if (serverToggle) {
|
||||
hostServer();
|
||||
} else {
|
||||
connectServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the action for the connect button in the connection dialog.
|
||||
* Tries to parse the port number and initiate connection to the server.
|
||||
*/
|
||||
private void connect() {
|
||||
private void connectServer() {
|
||||
LOGGER.log(Level.INFO, "connect to host={0}, port={1}", host, port); //NON-NLS
|
||||
try {
|
||||
hostname = host.getText().trim().isEmpty() ? LOCALHOST : host.getText();
|
||||
portNumber = Integer.parseInt(port.getText());
|
||||
openProgressDialog();
|
||||
connectionFuture = network.getApp().getExecutor().submit(this::initNetwork);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
network.getApp().errorDialog(lookup("port.must.be.integer"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Server is running or starts the Server and handles Exceptions *
|
||||
*/
|
||||
private void hostServer() {
|
||||
if (battleshipServer == null) {
|
||||
startServer(); // Starts the server in a new thread
|
||||
try {
|
||||
Thread.sleep(1000); // Wait for the server to start
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
// Proceed with connecting to the server
|
||||
connectServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Method for Boolean
|
||||
*/
|
||||
private void toggleServer(){
|
||||
serverToggle = !serverToggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows Client to Start a Server in a new Thread
|
||||
*/
|
||||
private void startServer() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// Initialize and run the server
|
||||
battleshipServer = new BattleshipServer();
|
||||
battleshipServer.run(Integer.parseInt(port.getText()));
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.ERROR, e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a dialog indicating that the connection is in progress.
|
||||
*/
|
||||
private void openProgressDialog() {
|
||||
progressDialog = DialogBuilder.simple(network.getApp().getDialogManager())
|
||||
.setText(lookup("label.connecting"))
|
||||
.build();
|
||||
.setText(lookup("label.connecting"))
|
||||
.build();
|
||||
progressDialog.open();
|
||||
}
|
||||
|
||||
@@ -103,8 +186,7 @@ private Object initNetwork() {
|
||||
try {
|
||||
network.initNetwork(hostname, portNumber);
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -119,11 +201,9 @@ public void update(float delta) {
|
||||
try {
|
||||
connectionFuture.get();
|
||||
success();
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
} catch (ExecutionException e) {
|
||||
failure(e.getCause());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Interrupted!", e); //NON-NLS
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh.Type;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* Manages the visual effects for impact events such as hits and misses.
|
||||
*/
|
||||
public class ImpactEffectManager {
|
||||
|
||||
private final AssetManager assetManager;
|
||||
private static final Logger LOGGER = System.getLogger(ImpactEffectManager.class.getName());
|
||||
|
||||
private Material particleMaterial;
|
||||
private BattleshipApp app;
|
||||
|
||||
/**
|
||||
* Constructor to initialize the asset manager via the main application.
|
||||
*
|
||||
* @param app The main application instance.
|
||||
*/
|
||||
public ImpactEffectManager(BattleshipApp app) {
|
||||
this.app = app;
|
||||
this.assetManager = app.getAssetManager();
|
||||
this.particleMaterial = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a visual effect for a hit at the specified position.
|
||||
*
|
||||
* @param battleshipNode The node where the effect should be attached.
|
||||
* @param shot The details of the shot where the hit occurred.
|
||||
*/
|
||||
public void triggerHitEffect(Node battleshipNode, Shot shot) {
|
||||
ParticleEmitter hitEffect = createParticleEmitter("HitEffect", 50, ColorRGBA.Orange, ColorRGBA.Red, 0.45f, 0.1f, 1f, 2f);
|
||||
|
||||
hitEffect.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
|
||||
|
||||
LOGGER.log(Level.DEBUG, "Hit effect created at position: {0}", hitEffect.getLocalTranslation().toString());
|
||||
|
||||
// hitEffect.emitAllParticles();
|
||||
hitEffect.addControl(new EffectCleanupControl(hitEffect));
|
||||
|
||||
app.getRootNode().attachChild(hitEffect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a visual effect for a missed shot at the specified location.
|
||||
*
|
||||
* @param shot The details of the missed shot.
|
||||
* @return The particle emitter representing the miss effect.
|
||||
*/
|
||||
public ParticleEmitter triggerMissEffect(Shot shot) {
|
||||
ParticleEmitter missEffect = createParticleEmitter("MissEffect", 50, ColorRGBA.Blue, ColorRGBA.Cyan, 0.3f, 0.05f, 0.5f, 1.5f);
|
||||
missEffect.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
|
||||
missEffect.addControl(new EffectCleanupControl(missEffect));
|
||||
return missEffect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a particle emitter with predefined parameters.
|
||||
*
|
||||
* @param name The name of the particle emitter.
|
||||
* @param count The number of particles to emit.
|
||||
* @param startColor The initial color of the particles.
|
||||
* @param endColor The final color of the particles.
|
||||
* @param startSize The initial size of the particles.
|
||||
* @param endSize The final size of the particles.
|
||||
* @param lowLife The minimum lifetime of the particles.
|
||||
* @param highLife The maximum lifetime of the particles.
|
||||
* @return The configured ParticleEmitter instance.
|
||||
*/
|
||||
private ParticleEmitter createParticleEmitter(String name, int count, ColorRGBA startColor, ColorRGBA endColor, float startSize, float endSize, float lowLife, float highLife) {
|
||||
ParticleEmitter emitter = new ParticleEmitter(name, Type.Triangle, count);
|
||||
emitter.setNumParticles(0);
|
||||
emitter.setMaterial(particleMaterial);
|
||||
emitter.setImagesX(2);
|
||||
emitter.setImagesY(2);
|
||||
emitter.setStartColor(startColor);
|
||||
emitter.setEndColor(endColor);
|
||||
emitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 1, 0));
|
||||
emitter.setStartSize(startSize);
|
||||
emitter.setEndSize(endSize);
|
||||
emitter.setGravity(0, -0.5f, 0);
|
||||
emitter.setLowLife(lowLife);
|
||||
emitter.setHighLife(highLife);
|
||||
return emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom control class to handle the cleanup of particle effects once they are no longer visible.
|
||||
*/
|
||||
private static class EffectCleanupControl extends AbstractControl {
|
||||
|
||||
private final ParticleEmitter emitter;
|
||||
|
||||
private float currentTime = 0;
|
||||
private final float duration = 3.5f;
|
||||
|
||||
/**
|
||||
* Constructor for managing cleanup of a standalone particle emitter.
|
||||
*
|
||||
* @param emitter The particle emitter to manage.
|
||||
*/
|
||||
public EffectCleanupControl(ParticleEmitter emitter) {
|
||||
this.emitter = emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the emitter when all particles are no longer visible.
|
||||
*
|
||||
* @param tpf Time per frame.
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
currentTime += tpf;
|
||||
if (currentTime <= duration) {
|
||||
}
|
||||
if (currentTime >= 1f && currentTime <= 1.1) {
|
||||
//Start
|
||||
emitter.setNumParticles(50);
|
||||
emitter.setParticlesPerSec(50);
|
||||
}
|
||||
if (currentTime >= duration){
|
||||
emitter.setParticlesPerSec(0);
|
||||
}
|
||||
if (currentTime >= duration+1f) {
|
||||
//Ende
|
||||
spatial.removeFromParent();
|
||||
emitter.emitAllParticles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* No custom rendering needed; particle behavior is handled in controlUpdate.
|
||||
* @param rm handles rendering, and ViewPort
|
||||
* @param vp defines the view where the scene is displayed.
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {
|
||||
// No rendering-specific behavior needed for this control.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,10 @@
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.util.Position;
|
||||
import java.lang.System.Logger;
|
||||
|
||||
/**
|
||||
* Synchronizes the visual representation of the ship map with the game model.
|
||||
@@ -27,6 +29,8 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
private static final float SHIP_DEPTH = 0f;
|
||||
private static final float INDENT = 4f;
|
||||
|
||||
private static final float SHELL_DEPTH = 8f;
|
||||
|
||||
// Colors used for different visual elements
|
||||
private static final ColorRGBA HIT_COLOR = ColorRGBA.Red;
|
||||
private static final ColorRGBA MISS_COLOR = ColorRGBA.Blue;
|
||||
@@ -109,6 +113,24 @@ public Spatial visit(Battleship ship) {
|
||||
return shipNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a visual representation (Spatial) for the given shell, attaching a control for its behavior.
|
||||
* @param shell the shell to visit and visualize
|
||||
* @return the constructed shell node (Spatial)
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
LOGGER.log(Logger.Level.DEBUG, "Visiting {0}", shell);
|
||||
final Node shellNode = new Node("shell");
|
||||
final Position startPosition = view.modelToView(shell.getCurrentPosition().x,shell.getCurrentPosition().z);
|
||||
|
||||
shellNode.attachChild(view.getApp().getDraw().makeRectangle(startPosition.getX(),startPosition.getY(), SHELL_DEPTH, 30, 30, ColorRGBA.Black));
|
||||
|
||||
shellNode.addControl(new ShellControl(shell, this.view, shell.getLogic()));
|
||||
return shellNode;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a line geometry representing part of the ship's border.
|
||||
*
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
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.ShipMap;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.battleship.model.*;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static pp.util.FloatMath.HALF_PI;
|
||||
@@ -34,7 +31,11 @@
|
||||
*/
|
||||
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 KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o";//NON-NLS
|
||||
private static final String DESTROYER = "Models/Destroyer/Destroyer.j3o";
|
||||
private static final String FERRY = "Models/Ferry/13922_Staten_Island_Ferry_V1_l1.obj";
|
||||
private static final String SMALL = "Models/Small/10634_SpeedBoat_v01_LOD3.obj";
|
||||
private static final String BOMB = "Models/Bomb/BombGBU.j3o";
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
@@ -44,6 +45,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
|
||||
private final ShipMap map;
|
||||
private final BattleshipApp app;
|
||||
private ImpactEffectManager effectHandler;
|
||||
|
||||
/**
|
||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||
@@ -56,6 +58,7 @@ public SeaSynchronizer(BattleshipApp app, Node root, ShipMap map) {
|
||||
super(app.getGameLogic().getOwnMap(), root);
|
||||
this.app = app;
|
||||
this.map = map;
|
||||
effectHandler = new ImpactEffectManager(app);
|
||||
addExisting();
|
||||
}
|
||||
|
||||
@@ -69,7 +72,7 @@ public SeaSynchronizer(BattleshipApp app, Node root, ShipMap map) {
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shot shot) {
|
||||
return shot.isHit() ? handleHit(shot) : createCylinder(shot);
|
||||
return shot.isHit() ? handleHit(shot) : effectHandler.triggerMissEffect(shot);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,9 +87,8 @@ private Spatial handleHit(Shot shot) {
|
||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
|
||||
|
||||
final Geometry representation = createCylinder(shot);
|
||||
representation.getLocalTranslation().subtractLocal(shipNode.getLocalTranslation());
|
||||
shipNode.attachChild(representation);
|
||||
System.out.println(shot.getX() + " " + shot.getY());
|
||||
effectHandler.triggerHitEffect(shipNode, shot);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -107,7 +109,7 @@ private Geometry createCylinder(Shot shot) {
|
||||
|
||||
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);
|
||||
|
||||
return geometry;
|
||||
@@ -133,15 +135,42 @@ public Spatial visit(Battleship ship) {
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
final Spatial bombModel = app.getAssetManager().loadModel(BOMB);
|
||||
|
||||
// Apply transformations to the bomb model (scale, rotate, etc. if needed)
|
||||
bombModel.scale(0.05f);
|
||||
bombModel.rotate(-HALF_PI, 0f, 0f);
|
||||
|
||||
// Set the position of the bomb at the shell's current position
|
||||
bombModel.setLocalTranslation(shell.getCurrentPosition());
|
||||
|
||||
// Add a control to animate the bomb's movement (similar to the previous cylinder animation)
|
||||
bombModel.addControl(new ShellControl(shell,shell.getLogic()));
|
||||
|
||||
return bombModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the appropriate graphical representation of the specified battleship.
|
||||
* The representation is either a detailed model or a simple box based on the length of the ship.
|
||||
* The representation is a detailed model based on the length of the ship.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the battleship
|
||||
*/
|
||||
private Spatial createShip(Battleship ship) {
|
||||
return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
||||
// return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
||||
if (ship.getLength() == 4) {
|
||||
return createBattleship(ship);
|
||||
} else if (ship.getLength() == 3) {
|
||||
return createBigShip(ship);
|
||||
} else if (ship.getLength() == 2) {
|
||||
return createMediumShip(ship);
|
||||
} else if (ship.getLength() == 1) {
|
||||
return createSmallShip(ship);
|
||||
}
|
||||
return createBattleship(ship);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,6 +225,53 @@ private Spatial createBattleship(Battleship ship) {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a "Big Ship"
|
||||
* @param ship The Battleship object with position and rotation info.
|
||||
* @return the spatial representing the "Big Ship" battleship
|
||||
*/
|
||||
private Spatial createBigShip(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(DESTROYER);
|
||||
|
||||
model.move(0,0.4f,0);
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||
model.scale(0.0001f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a "Medium Ship"
|
||||
* @param ship The Battleship object with position and rotation info.
|
||||
* @return the spatial representing the "Medium Ship" battleship
|
||||
*/
|
||||
private Spatial createMediumShip(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(FERRY);
|
||||
|
||||
model.move(0,0.25f,0);
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.00025f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a "Small Ship"
|
||||
* @param ship The Battleship object with position and rotation info.
|
||||
* @return the spatial representing the "Small Ship" battleship
|
||||
*/
|
||||
private Spatial createSmallShip(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(SMALL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||
model.scale(0.0009f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation angle for the specified rotation.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.game.client.ClientGameLogic;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.notification.Sound;
|
||||
import pp.util.Position;
|
||||
|
||||
/**
|
||||
* Controls the oscillating pitch motion of a battleship model in the game.
|
||||
* The ship oscillates to simulate a realistic movement on water, based on its orientation and length.
|
||||
*/
|
||||
class ShellControl extends AbstractControl {
|
||||
|
||||
private final Shell shell;
|
||||
private MapView view;
|
||||
private final ClientGameLogic logic;
|
||||
private final EffectMessage msg;
|
||||
private boolean hasPlayedSound = false;
|
||||
|
||||
/**
|
||||
* Constructs a new ShipControl instance for the specified Battleship.
|
||||
* The ship's orientation determines the axis of rotation, while its length influences
|
||||
* the cycle duration and amplitude of the oscillation.
|
||||
*
|
||||
* @param shell the Battleship object to control
|
||||
*/
|
||||
public ShellControl(Shell shell, ClientGameLogic clientGameLogic) {
|
||||
this.shell = shell;
|
||||
this.logic = clientGameLogic;
|
||||
this.msg = shell.getMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes ShellControl with a shell, map view, and game logic.
|
||||
* @param shell the shell to be controlled
|
||||
* @param view the map view to display the shell
|
||||
* @param clientGameLogic the game logic instance
|
||||
*/
|
||||
public ShellControl(Shell shell, MapView view, ClientGameLogic clientGameLogic) {
|
||||
this.shell = shell;
|
||||
this.view = view;
|
||||
this.logic = clientGameLogic;
|
||||
this.msg = shell.getMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the ship's pitch oscillation each frame. The ship's pitch is adjusted
|
||||
* to create a continuous tilting motion, simulating the effect of waves.
|
||||
*
|
||||
* @param tpf time per frame (in seconds), used to calculate the new pitch angle
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
|
||||
if (spatial == null)
|
||||
return;
|
||||
if (shell.isFinished() && !hasPlayedSound) {
|
||||
if (!msg.getShot().isHit())
|
||||
logic.playSound(Sound.SPLASH);
|
||||
else if (msg.getDestroyedShip() == null)
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
else
|
||||
logic.playSound(Sound.DESTROYED_SHIP);
|
||||
hasPlayedSound = true;
|
||||
}
|
||||
if (view == null) {
|
||||
shell.updatePosition(tpf);
|
||||
spatial.setLocalTranslation(shell.getCurrentPosition());
|
||||
} else {
|
||||
shell.updatePosition(tpf);
|
||||
Position pos2d = view.modelToView(shell.getCurrentPosition().x - 0.3f, shell.getCurrentPosition().z - 0.3f);
|
||||
spatial.setLocalTranslation(pos2d.getY(), pos2d.getX(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during rendering, but no operations are needed as this control only affects spatial transformation.
|
||||
* @param rm the RenderManager rendering the spatial
|
||||
* @param vp the ViewPort being rendered
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering logic is needed for this control
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,10 @@
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.model.Battleship;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
|
||||
import static pp.util.FloatMath.DEG_TO_RAD;
|
||||
import static pp.util.FloatMath.TWO_PI;
|
||||
import static pp.util.FloatMath.sin;
|
||||
@@ -47,6 +51,14 @@ class ShipControl extends AbstractControl {
|
||||
* The current time within the oscillation cycle, used to calculate the ship's pitch angle.
|
||||
*/
|
||||
private float time;
|
||||
/**
|
||||
* The current Ship
|
||||
*/
|
||||
private final Battleship battleship;
|
||||
/**
|
||||
* Logger for logging messages related to ShipControl operations.
|
||||
*/
|
||||
static final Logger LOGGER = System.getLogger(ShipControl.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs a new ShipControl instance for the specified Battleship.
|
||||
@@ -56,6 +68,7 @@ class ShipControl extends AbstractControl {
|
||||
* @param ship the Battleship object to control
|
||||
*/
|
||||
public ShipControl(Battleship ship) {
|
||||
battleship = ship;
|
||||
// Determine the axis of rotation based on the ship's orientation
|
||||
axis = switch (ship.getRot()) {
|
||||
case LEFT, RIGHT -> Vector3f.UNIT_X;
|
||||
@@ -63,7 +76,7 @@ public ShipControl(Battleship ship) {
|
||||
};
|
||||
|
||||
// Set the cycle duration and amplitude based on the ship's length
|
||||
cycle = ship.getLength() * 2f;
|
||||
cycle = battleship.getLength() * 2f;
|
||||
amplitude = 5f * DEG_TO_RAD / ship.getLength();
|
||||
}
|
||||
|
||||
@@ -80,15 +93,21 @@ protected void controlUpdate(float tpf) {
|
||||
|
||||
// Update the time within the oscillation cycle
|
||||
time = (time + tpf) % cycle;
|
||||
if (battleship.isDestroyed() && spatial.getLocalTranslation().getY() <= -0.6f) {
|
||||
LOGGER.log(Level.INFO, "Ship removed {0}", spatial.getName());
|
||||
spatial.getParent().detachChild(spatial);
|
||||
} else if (battleship.isDestroyed()) {
|
||||
spatial.move(0, -0.05f * tpf, 0);
|
||||
} else {
|
||||
// Update the time within the oscillation cycle
|
||||
time = (time + tpf) % cycle;
|
||||
|
||||
// Calculate the current angle of the oscillation
|
||||
final float angle = amplitude * sin(time * TWO_PI / cycle);
|
||||
// Apply the pitch rotation to the spatial
|
||||
spatial.setLocalRotation(pitch);
|
||||
}
|
||||
|
||||
// Update the pitch Quaternion with the new angle
|
||||
pitch.fromAngleAxis(angle, axis);
|
||||
|
||||
// Apply the pitch rotation to the spatial
|
||||
spatial.setLocalRotation(pitch);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.client.server;
|
||||
|
||||
import com.jme3.network.*;
|
||||
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.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;
|
||||
|
||||
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
|
||||
*/
|
||||
public class BattleshipServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(BattleshipServer.class.getName());
|
||||
private static final File CONFIG_FILE = new File("server.properties");
|
||||
|
||||
private Server myServer;
|
||||
private final ServerGameLogic logic;
|
||||
private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
|
||||
|
||||
static {
|
||||
// Configure logging
|
||||
LogManager manager = LogManager.getLogManager();
|
||||
try {
|
||||
manager.readConfiguration(new FileInputStream("logging.properties"));
|
||||
LOGGER.log(Level.INFO, "Successfully read logging properties"); //NON-NLS
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOGGER.log(Level.INFO, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the server.
|
||||
*/
|
||||
public BattleshipServer() {
|
||||
BattleshipConfig config = new BattleshipConfig();
|
||||
config.readFromIfExists(CONFIG_FILE);
|
||||
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
|
||||
logic = new ServerGameLogic(this, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the server on the given port and continuously processes incoming messages.
|
||||
* @param port the port to start the server on
|
||||
*/
|
||||
public void run(int port) {
|
||||
startServer(port);
|
||||
while (true)
|
||||
processNextMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes and starts the server on the specified port, handling exceptions if the server fails to start.
|
||||
* @param port the port to start the server on
|
||||
*/
|
||||
private void startServer(int port) {
|
||||
try {
|
||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||
myServer = Network.createServer(port);
|
||||
initializeSerializables();
|
||||
myServer.start();
|
||||
registerListeners();
|
||||
LOGGER.log(Level.INFO, "Server started: {0}", myServer.isRunning()); //NON-NLS
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOGGER.log(Level.ERROR, "Couldn't start server: {0}", e.getMessage()); //NON-NLS
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves and processes the next message from the queue, handling interruptions during the wait.
|
||||
*/
|
||||
private void processNextMessage() {
|
||||
try {
|
||||
pendingMessages.take().process(logic);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
LOGGER.log(Level.INFO, "Interrupted while waiting for messages"); //NON-NLS
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the next message from the queue, handling interruptions during message retrieval.
|
||||
*/
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(GameDetails.class);
|
||||
Serializer.registerClass(StartBattleMessage.class);
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
Serializer.registerClass(ShootMessage.class);
|
||||
Serializer.registerClass(EffectMessage.class);
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers message and connection listeners for the server.
|
||||
*/
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles received messages, logging the source and adding client messages to the pending queue.
|
||||
* @param source the connection the message was received from
|
||||
* @param message the received message
|
||||
*/
|
||||
@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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a new connection by logging it and adding a new player to the game logic.
|
||||
* @param server the server receiving the connection
|
||||
* @param hostedConnection the newly added connection
|
||||
*/
|
||||
@Override
|
||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
||||
logic.addPlayer(hostedConnection.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the removal of a connection by logging it, checking if it belongs to an active player, and exiting if necessary.
|
||||
* @param server the server losing the connection
|
||||
* @param hostedConnection the removed connection
|
||||
*/
|
||||
@Override
|
||||
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
||||
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
|
||||
final Player player = logic.getPlayerById(hostedConnection.getId());
|
||||
if (player == null)
|
||||
LOGGER.log(Level.INFO, "closed connection does not belong to an active player"); //NON-NLS
|
||||
else { //NON-NLS
|
||||
LOGGER.log(Level.INFO, "closed connection belongs to {0}", player); //NON-NLS
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all client connections and terminates the server with the given exit value.
|
||||
* @param exitValue the exit code to terminate the application with
|
||||
*/
|
||||
private void exit(int exitValue) { //NON-NLS
|
||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||
if (myServer != null)
|
||||
for (HostedConnection client : myServer.getConnections()) //NON-NLS
|
||||
if (client != null) client.close("Game over"); //NON-NLS
|
||||
System.exit(exitValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the specified message to the specified connection.
|
||||
*
|
||||
* @param id the connection id
|
||||
* @param message the message
|
||||
*/
|
||||
public void send(int id, ServerMessage message) {
|
||||
if (myServer == null || !myServer.isRunning()) {
|
||||
LOGGER.log(Level.ERROR, "no server running when trying to send {0}", message); //NON-NLS
|
||||
return;
|
||||
}
|
||||
final HostedConnection connection = myServer.getConnection(id);
|
||||
if (connection != null)
|
||||
connection.send(message);
|
||||
else
|
||||
LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.client.server;
|
||||
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
|
||||
record ReceivedMessage(ClientMessage message, int from) {
|
||||
void process(ClientInterpreter interpreter) {
|
||||
message.accept(interpreter, from);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
# Blender MTL File: 'untitletttd.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 0
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
map_Kd C:\Users\Convidado.Cliente-JMF-PC\Desktop\ghftht.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
newmtl Battleship
|
||||
illum 4
|
||||
Kd 0.00 0.00 0.00
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
map_Kd BattleshipC.jpg
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn1SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn2SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn3SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn4SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn5SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn6SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn7SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn8SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 360 KiB |
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/battleship-v1--611736.html
|
||||
License: Free Personal Use Only
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -0,0 +1,64 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 13.03.2012 15:35:28
|
||||
|
||||
newmtl metall
|
||||
Ns 31.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2431 0.2431 0.2431
|
||||
Kd 0.2431 0.2431 0.2431
|
||||
Ks 0.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 13922_StatenIslandFerry
|
||||
Ns 50.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.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 13922_StatenIslandFerry_diffuse.jpg
|
||||
map_Kd 13922_StatenIslandFerry_diffuse.jpg
|
||||
|
||||
newmtl metall2
|
||||
Ns 50.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2118 0.2824 0.3451
|
||||
Kd 0.2118 0.2824 0.3451
|
||||
Ks 0.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat
|
||||
Ns 34.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.6588 0.3059 0.1294
|
||||
Kd 0.6588 0.3059 0.1294
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl white
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.9686 0.9686 0.9686
|
||||
Kd 0.9686 0.9686 0.9686
|
||||
Ks 0.0000 0.0000 0.0000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/statenislandferry-v1--603882.html
|
||||
License: Free Personal Use Only
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 717 KiB |
@@ -0,0 +1,28 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 08.06.2011 15:26:00
|
||||
|
||||
newmtl _10634_SpeedBoat_v01_LOD310634_SpeedBoat_v01
|
||||
Ns 53.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.5882 0.5882 0.5882
|
||||
Kd 0.5882 0.5882 0.5882
|
||||
Ks 0.2000 0.2000 0.2000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 10634_SpeedBoat_v01.jpg
|
||||
map_Kd 10634_SpeedBoat_v01.jpg
|
||||
|
||||
newmtl glass
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 0.2000
|
||||
Tr 0.8000
|
||||
Tf 0.2000 0.2000 0.2000
|
||||
illum 2
|
||||
Ka 0.5882 0.5882 0.5882
|
||||
Kd 0.5882 0.5882 0.5882
|
||||
Ks 0.5000 0.5000 0.5000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/speedboat-v01--840133.html
|
||||
License: Free Personal Use Only
|
||||
Binary file not shown.
Binary file not shown.
BIN
Projekte/battleship/converter/KingGeorgeV.j3o
Normal file
BIN
Projekte/battleship/converter/KingGeorgeV.j3o
Normal file
Binary file not shown.
@@ -41,7 +41,7 @@ public static void main(String[] args) {
|
||||
*/
|
||||
@Override
|
||||
public void simpleInitApp() {
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o"); //NON-NLS
|
||||
export("Models/Destroyer/10619_Battleship.obj", "Destroyer.j3o"); //NON-NLS
|
||||
|
||||
stop();
|
||||
}
|
||||
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
# Blender MTL File: 'untitletttd.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 0
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
map_Kd C:\Users\Convidado.Cliente-JMF-PC\Desktop\ghftht.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,73 @@
|
||||
newmtl Battleship
|
||||
illum 4
|
||||
Kd 0.00 0.00 0.00
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
map_Kd BattleshipC.jpg
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn1SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn2SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn3SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn4SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn5SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn6SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn7SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn8SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 360 KiB |
@@ -0,0 +1,3 @@
|
||||
based on:
|
||||
https://free3d.com/3d-model/battleship-v1--611736.html
|
||||
License: Free Personal Use Only
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -0,0 +1,64 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 13.03.2012 15:35:28
|
||||
|
||||
newmtl metall
|
||||
Ns 31.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2431 0.2431 0.2431
|
||||
Kd 0.2431 0.2431 0.2431
|
||||
Ks 0.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl 13922_StatenIslandFerry
|
||||
Ns 50.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.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 13922_StatenIslandFerry_diffuse.jpg
|
||||
map_Kd 13922_StatenIslandFerry_diffuse.jpg
|
||||
|
||||
newmtl metall2
|
||||
Ns 50.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2118 0.2824 0.3451
|
||||
Kd 0.2118 0.2824 0.3451
|
||||
Ks 0.5850 0.5850 0.5850
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat
|
||||
Ns 34.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.6588 0.3059 0.1294
|
||||
Kd 0.6588 0.3059 0.1294
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl white
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.9686 0.9686 0.9686
|
||||
Kd 0.9686 0.9686 0.9686
|
||||
Ks 0.0000 0.0000 0.0000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,11 @@
|
||||
|
||||
package pp.battleship.game.client;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.notification.Sound;
|
||||
|
||||
@@ -32,11 +34,19 @@ public BattleState(ClientGameLogic logic, boolean myTurn) {
|
||||
this.myTurn = myTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the battle scene.
|
||||
* @return true to show the battle
|
||||
*/
|
||||
@Override
|
||||
public boolean showBattle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles clicking on the opponent's map. If it's the player's turn and the position is valid, a ShootMessage is sent.
|
||||
* @param pos the clicked position on the opponent's map
|
||||
*/
|
||||
@Override
|
||||
public void clickOpponentMap(IntPoint pos) {
|
||||
if (!myTurn)
|
||||
@@ -53,14 +63,15 @@ else if (logic.getOpponentMap().isValid(pos))
|
||||
@Override
|
||||
public void receivedEffect(EffectMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
|
||||
playSound(msg);
|
||||
myTurn = msg.isMyTurn();
|
||||
logic.playSound(Sound.MISSILE_LAUNCH);
|
||||
logic.setInfoText(msg.getInfoTextKey());
|
||||
affectedMap(msg).add(msg.getShot());
|
||||
affectedMap(msg).add(new Shell(new Vector3f(0, 50, 0), new Vector3f(msg.getShot().getY() + 0.5f, -0.4f, msg.getShot().getX() + 0.5f), 1f,msg,logic));
|
||||
if (destroyedOpponentShip(msg))
|
||||
logic.getOpponentMap().add(msg.getDestroyedShip());
|
||||
if (msg.isGameOver()) {
|
||||
msg.getRemainingOpponentShips().forEach(logic.getOwnMap()::add);
|
||||
msg.getRemainingOpponentShips().forEach(logic.getOpponentMap()::add);
|
||||
logic.setState(new GameOverState(logic));
|
||||
}
|
||||
}
|
||||
@@ -84,19 +95,4 @@ private ShipMap affectedMap(EffectMessage msg) {
|
||||
private boolean destroyedOpponentShip(EffectMessage msg) {
|
||||
return msg.getDestroyedShip() != null && msg.isOwnShot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound based on the outcome of the shot. Different sounds are played for a miss, hit,
|
||||
* or destruction of a ship.
|
||||
*
|
||||
* @param msg the effect message containing the result of the shot
|
||||
*/
|
||||
private void playSound(EffectMessage msg) {
|
||||
if (!msg.getShot().isHit())
|
||||
logic.playSound(Sound.SPLASH);
|
||||
else if (msg.getDestroyedShip() == null)
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
else
|
||||
logic.playSound(Sound.DESTROYED_SHIP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.List;
|
||||
|
||||
import static pp.battleship.Resources.lookup;
|
||||
import static pp.battleship.model.Battleship.Status.INVALID_PREVIEW;
|
||||
@@ -111,8 +112,7 @@ private void placeShip(IntPoint cursor) {
|
||||
harbor().remove(selectedInHarbor);
|
||||
preview = null;
|
||||
selectedInHarbor = null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
preview.setStatus(INVALID_PREVIEW);
|
||||
ownMap().add(preview);
|
||||
}
|
||||
@@ -135,8 +135,7 @@ public void clickHarbor(IntPoint pos) {
|
||||
harbor().add(selectedInHarbor);
|
||||
preview = null;
|
||||
selectedInHarbor = null;
|
||||
}
|
||||
else if (shipAtCursor != null) {
|
||||
} else if (shipAtCursor != null) {
|
||||
selectedInHarbor = shipAtCursor;
|
||||
selectedInHarbor.setStatus(VALID_PREVIEW);
|
||||
harbor().remove(selectedInHarbor);
|
||||
@@ -228,7 +227,7 @@ private ShipMap harbor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a map from the specified file.
|
||||
* Loads a map from the specified file. Also Checks if the map is valid
|
||||
*
|
||||
* @param file the file to load the map from
|
||||
* @throws IOException if the map cannot be loaded
|
||||
@@ -238,6 +237,9 @@ public void loadMap(File file) throws IOException {
|
||||
final ShipMapDTO dto = ShipMapDTO.loadFrom(file);
|
||||
if (!dto.fits(logic.getDetails()))
|
||||
throw new IOException(lookup("map.doesnt.fit"));
|
||||
if(!validMap(dto)){
|
||||
throw new IOException(lookup("map.is.invalid"));
|
||||
}
|
||||
ownMap().clear();
|
||||
dto.getShips().forEach(ownMap()::add);
|
||||
harbor().clear();
|
||||
@@ -264,4 +266,51 @@ public boolean mayLoadMap() {
|
||||
public boolean maySaveMap() {
|
||||
return harbor().getItems().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the map is valid in terms of overlapping and if the ship is within the boundries of the map
|
||||
* @param dto DataTransferObject is the loaded json file
|
||||
* @return returns true if the map is valid, false otherwhise
|
||||
*/
|
||||
private boolean validMap(ShipMapDTO dto) {
|
||||
return inBoundsClient(dto) && overLapClient(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Ships overlap on the map
|
||||
* @param dto DataTransferObject is the loaded json file
|
||||
* @return returns true if the ships arent overlapping, false otherwhise
|
||||
*/
|
||||
private boolean overLapClient(ShipMapDTO dto) {
|
||||
List<Battleship> battleshipList = dto.getShips();
|
||||
|
||||
for (int i = 0; i < battleshipList.size(); i++) {
|
||||
Battleship ship1 = battleshipList.get(i);
|
||||
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||
Battleship ship2 = battleshipList.get(j);
|
||||
if (ship1.collidesWith(ship2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Ship is in the map Boundries
|
||||
* @param dto DataTransferObject is the loaded json file
|
||||
* @return true if the ship is in the maps boundriess, false otherwhise
|
||||
*/
|
||||
private boolean inBoundsClient(ShipMapDTO dto) {
|
||||
int widht = dto.getWidth();
|
||||
int height = dto.getHeight();
|
||||
|
||||
for (int i = 0; i < dto.getShips().size(); i++) {
|
||||
Battleship localShip = dto.getShips().get(i);
|
||||
if (!(localShip.getMaxX() < widht && localShip.getMaxY() < height && localShip.getMinY() >= 0 && localShip.getMinX() >= 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public ServerGameLogic(ServerSender serverSender, BattleshipConfig config) {
|
||||
* Returns the state of the game.
|
||||
*/
|
||||
ServerState getState() {
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ public Player addPlayer(int id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a MapMessage.
|
||||
* Handles the reception of a MapMessage. Also Checks if the given map is valid or invalid
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
@@ -142,10 +143,65 @@ public Player addPlayer(int id) {
|
||||
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(!validMap(msg,from)){
|
||||
LOGGER.log(Level.ERROR, "Map message not valid",state);
|
||||
}
|
||||
else
|
||||
playerReady(getPlayerById(from), msg.getShips());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the map is Valid in terms of boundries and overlaps
|
||||
* *
|
||||
* @param msg the received MapMessage
|
||||
* @param id the ID of the sender client
|
||||
* @return returns true if the map is valid, false otherwhise
|
||||
*/
|
||||
private boolean validMap(MapMessage msg, int id) {
|
||||
return inBounds(msg, id) && overLap(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Ships overLap
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @return returns true if the ships arent overlapping, false otherwhise
|
||||
*/
|
||||
private boolean overLap(MapMessage msg) {
|
||||
List<Battleship> battleshipList = msg.getShips();
|
||||
|
||||
for (int i = 0; i < battleshipList.size(); i++) {
|
||||
Battleship ship1 = battleshipList.get(i);
|
||||
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||
Battleship ship2 = battleshipList.get(j);
|
||||
if (ship1.collidesWith(ship2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Ship is placed in Bounds with the Map
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param id the ID of the sender client
|
||||
* @return returns true if the ship is within the maps boundries, false otherwhise
|
||||
*/
|
||||
private boolean inBounds(MapMessage msg, int id) {
|
||||
int widht = getPlayerById(id).getMap().getWidth();
|
||||
int height = getPlayerById(id).getMap().getHeight();
|
||||
|
||||
for (int i = 0; i < msg.getShips().size(); i++) {
|
||||
Battleship localShip = msg.getShips().get(i);
|
||||
if (!(localShip.getMaxX() < widht && localShip.getMaxY() < height && localShip.getMinY() >= 0 && localShip.getMinX() >= 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a ShootMessage.
|
||||
*
|
||||
@@ -195,8 +251,7 @@ void shoot(Player p, IntPoint pos) {
|
||||
send(activePlayer, EffectMessage.miss(true, pos));
|
||||
send(otherPlayer, EffectMessage.miss(false, pos));
|
||||
activePlayer = otherPlayer;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// shot hit a ship
|
||||
selectedShip.hit(pos);
|
||||
if (otherPlayer.getMap().getRemainingShips().isEmpty()) {
|
||||
@@ -204,13 +259,11 @@ void shoot(Player p, IntPoint pos) {
|
||||
send(activePlayer, EffectMessage.won(pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.lost(pos, selectedShip, activePlayer.getMap().getRemainingShips()));
|
||||
setState(ServerState.GAME_OVER);
|
||||
}
|
||||
else if (selectedShip.isDestroyed()) {
|
||||
} else if (selectedShip.isDestroyed()) {
|
||||
// ship has been destroyed, but game is not yet over
|
||||
send(activePlayer, EffectMessage.shipDestroyed(true, pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.shipDestroyed(false, pos, selectedShip));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// ship has been hit, but it hasn't been destroyed
|
||||
send(activePlayer, EffectMessage.hit(true, pos));
|
||||
send(otherPlayer, EffectMessage.hit(false, pos));
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package pp.battleship.model;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.battleship.game.client.ClientGameLogic;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.util.FloatMath;
|
||||
|
||||
public class Shell implements Item {
|
||||
private final Vector3f startPosition; // Startposition des Geschosses
|
||||
private final Vector3f targetPosition; // Zielposition des Geschosses0
|
||||
private final Vector3f currentPosition; // Aktuelle Position des Geschosses
|
||||
private final float speed; // Geschwindigkeit des Geschosses
|
||||
private final EffectMessage msg;
|
||||
private final ClientGameLogic logic;
|
||||
|
||||
private float progress;
|
||||
|
||||
/**
|
||||
* Initializes a Shell with start position, target position, speed, message, and game logic.
|
||||
* @param startPosition initial position of the shell
|
||||
* @param targetPosition target position of the shell
|
||||
* @param speed movement speed of the shell
|
||||
* @param msg effect message related to the shell
|
||||
* @param logic game logic instance
|
||||
*/
|
||||
public Shell(Vector3f startPosition, Vector3f targetPosition, float speed, EffectMessage msg, ClientGameLogic logic) {
|
||||
this.startPosition = startPosition;
|
||||
this.targetPosition = targetPosition;
|
||||
this.currentPosition = new Vector3f(startPosition); // Initiale Position ist die Startposition
|
||||
this.speed = speed;
|
||||
this.msg = msg;
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the shell's position based on elapsed time, using eased interpolation between start and target positions.
|
||||
* @param deltaTime time elapsed since last update
|
||||
*/
|
||||
public void updatePosition(float deltaTime) {
|
||||
progress += deltaTime * speed;
|
||||
progress = FloatMath.clamp(progress, 0.0f, 1.0f);
|
||||
|
||||
float t = FloatMath.easeInOutElastic(progress);
|
||||
|
||||
// Interpoliere die Position zwischen Start- und Zielposition basierend auf dem Fortschritt
|
||||
currentPosition.y = FloatMath.extrapolateLinear(t, startPosition.y, targetPosition.y);
|
||||
currentPosition.x = FloatMath.extrapolateLinear(t, startPosition.x, targetPosition.x);
|
||||
currentPosition.z = FloatMath.extrapolateLinear(t, startPosition.z, targetPosition.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for Current Position
|
||||
* @return current position
|
||||
*/
|
||||
public Vector3f getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitor the visitor performing operations on the item
|
||||
* @param <T> generic type
|
||||
* @return shell
|
||||
*/
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitor pattern
|
||||
* @param visitor the visitor to accept
|
||||
*/
|
||||
@Override
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for the isFinished boolean
|
||||
* @return true if progress lesser than 1, false otherwise
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return progress >= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for EffectMessage
|
||||
* @return EffectMessage
|
||||
*/
|
||||
public EffectMessage getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for Client logic
|
||||
* @return Client logic
|
||||
*/
|
||||
public ClientGameLogic getLogic() {
|
||||
return logic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
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;
|
||||
@@ -77,6 +78,14 @@ public void add(Battleship ship) {
|
||||
addItem(ship);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param shell
|
||||
*/
|
||||
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.
|
||||
@@ -97,7 +106,7 @@ public void add(Shot shot) {
|
||||
*/
|
||||
public void remove(Item item) {
|
||||
items.remove(item);
|
||||
notifyListeners(new ItemAddedEvent(item, this));
|
||||
notifyListeners(new ItemRemovedEvent(item, this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,4 +28,12 @@ public interface Visitor<T> {
|
||||
* @return the result of visiting the Battleship element
|
||||
*/
|
||||
T visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* Visits a Shell element.
|
||||
*
|
||||
* @param shell the shell element to visit
|
||||
* @return the result of visiting the Shell element
|
||||
*/
|
||||
T visit(Shell shell);
|
||||
}
|
||||
|
||||
@@ -25,4 +25,11 @@ public interface VoidVisitor {
|
||||
* @param ship the Battleship element to visit
|
||||
*/
|
||||
void visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* Visits a Shell element
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
*/
|
||||
void visit(Shell shell);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,14 @@ public boolean fits(GameDetails details) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ships stored in this DTO.
|
||||
*
|
||||
|
||||
@@ -22,5 +22,9 @@ public enum Sound {
|
||||
/**
|
||||
* Sound of a ship being destroyed.
|
||||
*/
|
||||
DESTROYED_SHIP
|
||||
DESTROYED_SHIP,
|
||||
/**
|
||||
* Sound of a fired Missile
|
||||
*/
|
||||
MISSILE_LAUNCH
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ wait.for.opponent=Wait for your opponent!
|
||||
confirm.leaving=Would you really like to leave the game?
|
||||
you.lost.the.game=You lost the game!
|
||||
you.won.the.game=You won the game!
|
||||
menu.music.toggle=Musik
|
||||
button.yes=Yes
|
||||
button.no=No
|
||||
button.ok=Ok
|
||||
@@ -37,3 +38,4 @@ 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
|
||||
map.is.invalid=The Map is invalid
|
||||
|
||||
@@ -17,6 +17,7 @@ wait.for.opponent=Warte auf Deinen Gegner!
|
||||
confirm.leaving=Willst Du wirklich das Spiel verlassen?
|
||||
you.lost.the.game=Leider verloren!
|
||||
you.won.the.game=Du hast gewonnen!
|
||||
menu.music.toggle=Hintergrund Musik
|
||||
button.yes=Ja
|
||||
button.no=Nein
|
||||
button.ok=Ok
|
||||
@@ -28,7 +29,7 @@ port.number=Port
|
||||
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.sound-enabled=Sound
|
||||
menu.map.load=Karte von Datei laden...
|
||||
menu.map.save=Karte in Datei speichern...
|
||||
label.file=Datei:
|
||||
@@ -37,3 +38,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
|
||||
map.is.invalid=Diese Karte ist invalide
|
||||
@@ -96,6 +96,51 @@ public static float extrapolateLinear(float scale, float startValue, float endVa
|
||||
return ((1f - scale) * startValue) + (scale * endValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates a value to range [0,1] after given easing function
|
||||
* https://easings.net/#easeInOutElastic
|
||||
* @param value the value to interpolate
|
||||
* @return A new value in range [0,1]
|
||||
*/
|
||||
public static float easeInOutElastic(float value) {
|
||||
var c5 = (2 * Math.PI) / 4.5;
|
||||
|
||||
return value == 0
|
||||
? 0
|
||||
: (float) (value == 1
|
||||
? 1
|
||||
: value < 0.5
|
||||
? -(Math.pow(2, 20 * value - 10) * Math.sin((20 * value - 11.125) * c5)) / 2
|
||||
: (Math.pow(2, -20 * value + 10) * Math.sin((20 * value - 11.125) * c5)) / 2 + 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fancy effect for 2D Map animation
|
||||
* @param x Progress state of animation
|
||||
* @return new Value for animation
|
||||
*/
|
||||
public static float easeOutBounce(float x) {
|
||||
float n1 = 7.5625f;
|
||||
float d1 = 2.75f;
|
||||
|
||||
if (x < 1 / d1) {
|
||||
return n1 * x * x;
|
||||
} else if (x < 2 / d1) {
|
||||
return (float) (n1 * (x -= 1.5 / d1) * x + 0.75);
|
||||
} else if (x < 2.5 / d1) {
|
||||
return (float) (n1 * (x -= 2.25 / d1) * x + 0.9375);
|
||||
} else {
|
||||
return (float) (n1 * (x -= 2.625 / d1) * x + 0.984375);
|
||||
}
|
||||
}
|
||||
|
||||
public static float easeInBounce(float x) {
|
||||
return 1 - easeOutBounce(1 - x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the arc cosine of a value.<br>
|
||||
* Special cases:
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Abstract base class for keeping the scene graph (=view) in sync with the model.
|
||||
*/
|
||||
public abstract class ModelViewSynchronizer<I> {
|
||||
private static final Logger LOGGER = System.getLogger(ModelViewSynchronizer.class.getName());
|
||||
protected static final Logger LOGGER = System.getLogger(ModelViewSynchronizer.class.getName());
|
||||
private final Node itemNode = new Node("items"); //NON-NLS
|
||||
private final Map<I, Spatial> itemMap = new HashMap<>();
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
library('mockito-core', 'org.mockito:mockito-core:3.+')
|
||||
library('groovy-jsr223', 'org.apache.groovy:groovy-jsr223:4.0.22')
|
||||
library('slf4j-nop', 'org.slf4j:slf4j-nop:2.0.13')
|
||||
|
||||
library('jme3-effects', 'org.jmonkeyengine', 'jme3-effects').versionRef('jme')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user