Code cleanup

added JavaDocs
removed unnecessary lines
This commit is contained in:
Timo Brennförder
2024-10-13 01:59:46 +02:00
parent febdd63422
commit 8c45784246
131 changed files with 2291 additions and 1548 deletions

View File

@@ -12,6 +12,9 @@
import java.lang.System.Logger.Level;
import java.util.prefs.Preferences;
/**
* Class to play Background music in game
*/
public class BackgroundMusic implements GameEventListener {
private static final String VOLUME_PREF = "volume";
private static final String MUSIC_ENABLED_PREF = "musicEnabled";
@@ -32,7 +35,7 @@ public class BackgroundMusic implements GameEventListener {
private Application app;
/**
* Initializes and controls the BackgroundMusic
* Constructor for BackgroundMusic class
*
* @param app The main Application
*/
@@ -50,13 +53,14 @@ public BackgroundMusic(Application app) {
stop(loseMusic);
lastPlayedMusic = menuMusic.getName();
if(musicEnabled) {
if (musicEnabled) {
play(menuMusic);
}
}
/**
* creates an audio node for the music
* Creates an audio node for the music
*
* @param musicFilePath the file path to the music
* @return the created audio node
*/
@@ -71,7 +75,8 @@ private AudioNode createMusicNode(String musicFilePath) {
}
/**
* starts the music
* Starts the music
*
* @param audioNode the audio node to be played
*/
public void play(AudioNode audioNode) {
@@ -82,45 +87,47 @@ public void play(AudioNode audioNode) {
}
/**
* pauses the music
* Pauses the music
*
* @param audioNode the audio node to be paused
*/
public void pause(AudioNode audioNode){
if(audioNode.getStatus() == Status.Playing){
public void pause(AudioNode audioNode) {
if (audioNode.getStatus() == Status.Playing) {
audioNode.pause();
}
}
/**
* stops the music
* Stops the music
*
* @param audioNode the audio node to be stopped
*/
public void stop(AudioNode audioNode){
public void stop(AudioNode audioNode) {
if (audioNode.getStatus() == Status.Playing) {
audioNode.stop();
}
}
/**
* Toggle Method to control the music
* Controls which music should be played
*/
public void toggleMusic() {
this.musicEnabled = !this.musicEnabled;
if (musicEnabled) {
switch (lastPlayedMusic){
case MENU_MUSIC:
play(menuMusic);
break;
case GAME_MUSIC:
play(gameMusic);
break;
case VICTORY_MUSIC:
play(victoryMusic);
break;
case LOSE_MUSIC:
play(loseMusic);
break;
}
switch (lastPlayedMusic) {
case MENU_MUSIC:
play(menuMusic);
break;
case GAME_MUSIC:
play(gameMusic);
break;
case VICTORY_MUSIC:
play(victoryMusic);
break;
case LOSE_MUSIC:
play(loseMusic);
break;
}
}
else {
pause(menuMusic);
@@ -133,33 +140,36 @@ public void toggleMusic() {
}
/**
* changes the music to the specified music if it isn't already playing
* Changes the music to the specified music if it isn't already playing
*
* @param music the music to play
*/
public void changeMusic(Music music) {
if(music == Music.MENU_THEME && !lastPlayedMusic.equals(MENU_MUSIC)) {
if (music == Music.MENU_THEME && !lastPlayedMusic.equals(MENU_MUSIC)) {
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
stop(gameMusic);
stop(victoryMusic);
stop(loseMusic);
play(menuMusic);
lastPlayedMusic = menuMusic.getName();
} else if (music == Music.GAME_THEME && !lastPlayedMusic.equals(GAME_MUSIC)) {
}
else if (music == Music.GAME_THEME && !lastPlayedMusic.equals(GAME_MUSIC)) {
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
stop(menuMusic);
stop(loseMusic);
stop(victoryMusic);
play(gameMusic);
lastPlayedMusic = gameMusic.getName();
} else if (music == Music.VICTORY_THEME && !lastPlayedMusic.equals(VICTORY_MUSIC)) {
}
else if (music == Music.VICTORY_THEME && !lastPlayedMusic.equals(VICTORY_MUSIC)) {
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
stop(menuMusic);
stop(gameMusic);
stop(loseMusic);
play(victoryMusic);
lastPlayedMusic = victoryMusic.getName();
} else if (music == Music.LOSE_THEME && !lastPlayedMusic.equals(LOSE_MUSIC)){
}
else if (music == Music.LOSE_THEME && !lastPlayedMusic.equals(LOSE_MUSIC)) {
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
stop(menuMusic);
stop(gameMusic);
@@ -170,14 +180,14 @@ public void changeMusic(Music music) {
}
/**
* the method which receives the Event
* Receives the different MusicEvents
*
* @param music the received Event
*/
@Override
public void receivedEvent (MusicEvent music){
public void receivedEvent(MusicEvent music) {
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
switch (music.music()){
switch (music.music()) {
case MENU_THEME:
changeMusic(Music.MENU_THEME);
break;
@@ -193,9 +203,8 @@ public void receivedEvent (MusicEvent music){
}
}
/**
* Method to set the volume for the music
* Set the volume for the music
*
* @param volume float to transfer the new volume
*/
@@ -210,7 +219,7 @@ public void setVolume(float volume) {
}
/**
* This method returns the volume
* Returns the volume
*
* @return the current volume as a float
*/

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.jme3.app.DebugKeysAppState;
@@ -232,7 +225,6 @@ public void simpleInitApp() {
serverConnection.connect();
backgroundMusic = new BackgroundMusic(this);
logic.addListener(backgroundMusic);
}
/**
@@ -323,7 +315,7 @@ public Draw getDraw() {
return draw;
}
public BackgroundMusic getBackgroundMusic(){
public BackgroundMusic getBackgroundMusic() {
return backgroundMusic;
}

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.jme3.math.ColorRGBA;

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.jme3.app.Application;

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.jme3.app.Application;
@@ -135,6 +128,11 @@ public void shipDestroyed() {
shipDestroyedSound.playInstance();
}
/**
* Plays sound according to the received SoundEvent
*
* @param event the received SoundEvent
*/
@Override
public void receivedEvent(SoundEvent event) {
switch (event.sound()) {

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.simsilica.lemur.Button;
@@ -56,13 +49,12 @@ public Menu(BattleshipApp app) {
addChild(new Label(lookup("menu.music.volume"), new ElementId("slider_label")));
Slider volumeSlider = new Slider();
volumeSlider.setModel(new DefaultRangedValueModel(0.00 , 1.00, app.getBackgroundMusic().getVolume()));
volumeSlider.setModel(new DefaultRangedValueModel(0.00, 1.00, app.getBackgroundMusic().getVolume()));
volumeSlider.setDelta(0.05);
addChild(volumeSlider);
volumeRef = volumeSlider.getModel().createReference();
addChild(loadButton)
.addClickCommands(s -> ifTopDialog(this::loadDialog));
addChild(saveButton)
@@ -76,19 +68,20 @@ public Menu(BattleshipApp app) {
}
/**
* this method is used update the volume when the slider is used
* Updates the volume when the slider is moved
*
* @param tpf time per frame
*/
@Override
public void update(float tpf){
if(volumeRef.update()){
public void update(float tpf) {
if (volumeRef.update()) {
double newVolume = volumeRef.get();
adjustVolume(newVolume);
}
}
/**
* this method adjust the volume for the background music
* Adjusts the volume for the background music
*
* @param volume is the double value of the volume
*/
@@ -97,13 +90,12 @@ private void adjustVolume(double volume) {
}
/**
* this method toggles the background music on and off
* Toggles the background music on and off
*/
private void toggleMusic() {
app.getBackgroundMusic().toggleMusic();
}
/**
* Updates the state of the load and save buttons based on the game logic.
*/

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.simsilica.lemur.Checkbox;
@@ -55,7 +48,7 @@ class NetworkDialog extends SimpleDialog {
Checkbox hostServer = new Checkbox(lookup("start.own.server"));
hostServer.setChecked(false);
hostServer.addClickCommands(s->toggleOwnServer());
hostServer.addClickCommands(s -> toggleOwnServer());
final BattleshipApp app = network.getApp();
final Container input = new Container(new SpringGridLayout());
@@ -164,38 +157,40 @@ private void failure(Throwable e) {
* If hostServer-Checkbox is active, starts a new Server on the clients machine, else tries to connect to existing server
*/
private void connect() {
if(hostServer){
if (hostServer) {
startServer();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
catch (InterruptedException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
}
connectToServer();
} else {
}
else {
connectToServer();
}
}
/**
* starts a server on the clients machine
* Starts a server on the clients machine
*/
private void startServer() {
new Thread(() -> {
try{
try {
BattleshipServer battleshipServer = new BattleshipServer(Integer.parseInt(port.getText()));
battleshipServer.run();
} catch (Exception e) {
LOGGER.log(Level.ERROR,e);
}
catch (Exception e) {
LOGGER.log(Level.ERROR, e);
}
}).start();
}
/**
* handles the action for the hostServer-Checkbox
* Handles the action for the hostServer-Checkbox
*/
private void toggleOwnServer(){
private void toggleOwnServer() {
hostServer = !hostServer;
}
}

View File

@@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client;
import com.jme3.network.Client;

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;

View File

@@ -14,25 +14,26 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
public class HitEffectHandler {
private final AssetManager assetManager;
private static final Logger LOGGER = System.getLogger(HitEffectHandler.class.getName());
/**
* Constructor for the HitEffectHandler class
*
* @param app the main application
*/
public HitEffectHandler(Application app){
public HitEffectHandler(Application app) {
assetManager = app.getAssetManager();
}
/**
* Creates an explosion effect when ship gets hit
* Creates explosion, debris and fire effects when ship gets hit
*
* @param battleshipNode the node of the ship that gets hit and the effect should be attached to
* @param shot The shot taken on a field
* @param shot The shot taken on a field
*/
public void hitEffect(Node battleshipNode, Shot shot){
public void hitEffect(Node battleshipNode, Shot shot) {
//Explosion
ParticleEmitter explosion = new ParticleEmitter("Explosion", Type.Triangle, 30);
explosion.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"));
@@ -47,10 +48,10 @@ public void hitEffect(Node battleshipNode, Shot shot){
explosion.setLowLife(1f);
explosion.setHighLife(3.5f);
explosion.setParticlesPerSec(0);
explosion.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
explosion.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
explosion.emitAllParticles();
//Debris
//Debris
ParticleEmitter debris = new ParticleEmitter("Debris", Type.Triangle, 6);
Material debrisMaterial = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
debrisMaterial.setTexture("Texture", assetManager.loadTexture("Textures/Debris/debris.png"));
@@ -67,7 +68,7 @@ public void hitEffect(Node battleshipNode, Shot shot){
debris.setLowLife(1f);
debris.setHighLife(3.5f);
debris.setParticlesPerSec(0);
debris.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
debris.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
debris.emitAllParticles();
//Fire
@@ -92,8 +93,7 @@ public void hitEffect(Node battleshipNode, Shot shot){
// LOGGER.log(Level.DEBUG, "Created HitEffect at {0}", explosion.getLocalTranslation().toString());
// LOGGER.log(Level.DEBUG, "Created HitEffect at {0}", debris.getLocalTranslation().toString());
LOGGER.log(Level.INFO, "Created HitEffect at {0}", fire.getLocalTranslation().toString());
// LOGGER.log(Level.INFO, "Created HitEffect at {0}", fire.getLocalTranslation().toString());
battleshipNode.attachChild(explosion);
explosion.addControl(new EffectControl(explosion, battleshipNode));
@@ -103,10 +103,11 @@ public void hitEffect(Node battleshipNode, Shot shot){
}
/**
* Creates a splash effect if shot hits the water
* Creates a splash effect if the shot hits the water
*
* @param shot The shot taken on a field
*/
public ParticleEmitter missEffect(Shot shot){
public ParticleEmitter missEffect(Shot shot) {
ParticleEmitter missEffect = new ParticleEmitter("HitEffect", Type.Triangle, 45);
missEffect.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"));
missEffect.setImagesX(2);
@@ -120,7 +121,7 @@ public ParticleEmitter missEffect(Shot shot){
missEffect.setLowLife(0.7f);
missEffect.setHighLife(1.8f);
missEffect.setParticlesPerSec(0);
missEffect.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
missEffect.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
LOGGER.log(Level.DEBUG, "Created MissEffect at {0}", missEffect.getLocalTranslation().toString());
@@ -139,7 +140,7 @@ private static class EffectControl extends AbstractControl {
/**
* Constructor used to attach effect to a node
*
* @param emitter the particle emitter to be controlled
* @param emitter the particle emitter to be controlled
* @param parentNode the node to be attached
*/
public EffectControl(ParticleEmitter emitter, Node parentNode) {
@@ -152,7 +153,7 @@ public EffectControl(ParticleEmitter emitter, Node parentNode) {
*
* @param emitter the particle emitter to be controlled
*/
public EffectControl(ParticleEmitter emitter){
public EffectControl(ParticleEmitter emitter) {
this.emitter = emitter;
this.parentNode = null;
}
@@ -177,5 +178,4 @@ protected void controlUpdate(float tpf) {
@Override
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {}
}
}

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;
@@ -117,6 +112,12 @@ public Spatial visit(Battleship ship) {
return shipNode;
}
/**
* Creates a visual representation on the map
*
* @param shell the Shell element to visit
* @return the node the visual representation gets attached to.
*/
@Override
public Spatial visit(Shell shell) {
LOGGER.log(Logger.Level.DEBUG, "Visiting {0}", shell);

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;
@@ -51,7 +46,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
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 HitEffectHandler hitEffectHandler;
private final HitEffectHandler hitEffectHandler;
private final ShipMap map;
private final BattleshipApp app;
@@ -146,8 +141,8 @@ public Spatial visit(Battleship ship) {
/**
* Visits a Shell and creates a graphical representation of it.
*
* @param shell the battleship to be represented
* @return the node containing the graphical representation of the battleship
* @param shell the Shell to be represented
* @return the node containing the graphical representation of the Shell
*/
@Override
public Spatial visit(Shell shell) {
@@ -156,12 +151,11 @@ public Spatial visit(Shell shell) {
final float x = shell.getY();
final float z = shell.getX();
node.setLocalTranslation(x+0.5f, 10f, z+0.5f);
node.setLocalTranslation(x + 0.5f, 10f, z + 0.5f);
node.addControl(new ShellControl(shell, app));
return node;
}
/**
* 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.
@@ -170,7 +164,7 @@ public Spatial visit(Shell shell) {
* @return the spatial representing the battleship
*/
private Spatial createShip(Battleship ship) {
return switch (ship.getLength()){
return switch (ship.getLength()) {
case 1 -> createPatrolBoat(ship);
case 2 -> createModernBattleship(ship);
case 3 -> createUboat(ship);
@@ -250,7 +244,7 @@ private Spatial createModernBattleship(Battleship ship) {
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
model.scale(0.000075f);
model.setShadowMode(ShadowMode.CastAndReceive);
model.move(0,0.2f,0);
model.move(0, 0.2f, 0);
return model;
}
@@ -269,15 +263,13 @@ private Spatial createMissile() {
model.setQueueBucket(RenderQueue.Bucket.Opaque);
model.rotate(-HALF_PI,0,0);
model.rotate(-HALF_PI, 0, 0);
model.scale(0.009f);
model.setShadowMode(ShadowMode.CastAndReceive);
model.move(0,0f,0);
model.move(0, 0f, 0);
return model;
}
/**
* Creates a detailed 3D model to represent a Uboat.
*
@@ -291,7 +283,7 @@ private Spatial createUboat(Battleship ship) {
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
model.scale(0.45f);
model.setShadowMode(ShadowMode.CastAndReceive);
model.move(0,-0.25f,0);
model.move(0, -0.25f, 0);
return model;
}
@@ -313,7 +305,6 @@ private Spatial createPatrolBoat(Battleship ship) {
return model;
}
/**
* Calculates the rotation angle for the specified rotation.
*

View File

@@ -11,6 +11,9 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
/**
* Class to control the 3D representation of a shell
*/
public class ShellControl extends AbstractControl {
private final Shell shell;
@@ -18,24 +21,42 @@ public class ShellControl extends AbstractControl {
private static final float TRAVEL_SPEED = 8.5f;
static final Logger LOGGER = System.getLogger(BattleshipApp.class.getName());
/**
* Constructor for ShellControl class
*
* @param shell The Shell to be displayed
* @param app the main application
*/
public ShellControl(Shell shell, BattleshipApp app) {
this.shell = shell;
this.app = app;
}
/**
* Method to control movement of the Shell and remove it when target is reached
*
* @param tpf time per frame (in seconds)
*/
@Override
public void controlUpdate(float tpf) {
//LOGGER.log(Level.DEBUG, "missile at x=" + shell.getX() + ", y=" + shell.getY());
spatial.move(0, -TRAVEL_SPEED*tpf, 0);
if(spatial.getLocalTranslation().getY() <= 0.2){
spatial.move(0, -TRAVEL_SPEED * tpf, 0);
if (spatial.getLocalTranslation().getY() <= 0.2) {
spatial.getParent().detachChild(spatial);
app.getGameLogic().send(new EndAnimationMessage(new IntPoint(shell.getX(), shell.getY())));
}
}
/**
* 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) {
}
}

View File

@@ -9,29 +9,52 @@
import pp.battleship.model.IntPoint;
import pp.util.Position;
/**
* Class to control the 2D representation of a shell
*/
public class ShellMapControl extends AbstractControl {
private final Position position;
private final IntPoint pos;
private static final Vector3f vector = new Vector3f();
private static final Vector3f VECTOR_3_F = new Vector3f();
private final BattleshipApp app;
/**
* Constructor for ShellMapControl
*
* @param position the target position of the shell
* @param app the main application
* @param pos the position the then to render shot goes to
*/
public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) {
super();
this.position = position;
this.pos = pos;
this.app = app;
vector.set(new Vector3f(position.getX(), position.getY(), 0));
VECTOR_3_F.set(new Vector3f(position.getX(), position.getY(), 0));
}
/**
* Method to control movement of the Shell on the map and remove it when target is reached
*
* @param tpf time per frame (in seconds)
*/
@Override
protected void controlUpdate(float tpf) {
spatial.move(vector.mult(tpf));
spatial.move(VECTOR_3_F.mult(tpf));
if (spatial.getLocalTranslation().getX() >= position.getX() && spatial.getLocalTranslation().getY() >= position.getY()) {
spatial.getParent().detachChild(spatial);
app.getGameLogic().send(new EndAnimationMessage(pos));
}
}
/**
* 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) {

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;
@@ -88,12 +83,12 @@ protected void controlUpdate(float tpf) {
// If spatial is null, do nothing
if (spatial == null) return;
if(battleship.isDestroyed() && spatial.getLocalTranslation().getY() < -0.6f){
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.2f*tpf,0);
spatial.move(0, -0.2f * tpf, 0);
}
else {
// Update the time within the oscillation cycle

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.battleship.client.gui;

View File

@@ -1,9 +1,4 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package server;
@@ -77,12 +72,18 @@ public BattleshipServer(int port) {
logic = new ServerGameLogic(this, config);
}
/**
* Runs a server
*/
public void run() {
startServer();
while (true)
processNextMessage();
}
/**
* Starts a server
*/
private void startServer() {
try {
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
@@ -98,6 +99,9 @@ private void startServer() {
}
}
/**
* Processes next received message
*/
private void processNextMessage() {
try {
pendingMessages.take().process(logic);
@@ -108,6 +112,9 @@ private void processNextMessage() {
}
}
/**
* Registers all serializable classes
*/
private void initializeSerializables() {
Serializer.registerClass(GameDetails.class);
Serializer.registerClass(StartBattleMessage.class);
@@ -122,6 +129,9 @@ private void initializeSerializables() {
Serializer.registerClass(SwitchToBattleState.class);
}
/**
* Registers all listeners
*/
private void registerListeners() {
myServer.addMessageListener(this, MapMessage.class);
myServer.addMessageListener(this, ShootMessage.class);
@@ -129,6 +139,11 @@ private void registerListeners() {
myServer.addConnectionListener(this);
}
/**
* Handles a received message
* @param source the connection the message comes 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
@@ -136,12 +151,22 @@ public void messageReceived(HostedConnection source, Message message) {
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
}
/**
* Adds a new connection to a server
* @param server the server to add the connection to
* @param hostedConnection the connection to be added
*/
@Override
public void connectionAdded(Server server, HostedConnection hostedConnection) {
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
logic.addPlayer(hostedConnection.getId());
}
/**
* Removes a standing connection from a server
* @param server the server to add the connection to
* @param hostedConnection the connection to be added
*/
@Override
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
@@ -154,6 +179,10 @@ public void connectionRemoved(Server server, HostedConnection hostedConnection)
}
}
/**
* Shuts down the server and terminates the application with the given exit code
* @param exitValue the exit status code
*/
private void exit(int exitValue) { //NON-NLS
LOGGER.log(Level.INFO, "close request"); //NON-NLS
if (myServer != null)

View File

@@ -1,15 +1,15 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package server;
import pp.battleship.message.client.ClientInterpreter;
import pp.battleship.message.client.ClientMessage;
/**
* Represents a message received from a client
* @param message the received message
* @param from the ID of the client that sent the message
*/
record ReceivedMessage(ClientMessage message, int from) {
void process(ClientInterpreter interpreter) {
message.accept(interpreter, from);

View File

@@ -6,7 +6,7 @@ newmtl white
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.6667 0.6667 0.6667
Kd 0.6667 0.6667 0.6667
@@ -18,7 +18,7 @@ newmtl boat_elements_black
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.0000 0.0000 0.0000
Kd 0.0000 0.0000 0.0000
@@ -30,7 +30,7 @@ newmtl boat_glass
Ni 7.0000
d 0.4000
Tr 0.6000
Tf 0.4000 0.4000 0.4000
Tf 0.4000 0.4000 0.4000
illum 2
Ka 0.1059 0.1569 0.1451
Kd 0.1059 0.1569 0.1451
@@ -42,7 +42,7 @@ newmtl boat_screw_hooks_bronze
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.2941 0.2157 0.0510
Kd 0.2941 0.2157 0.0510
@@ -54,7 +54,7 @@ newmtl boat_silver
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.3333 0.3333 0.3333
Kd 0.3333 0.3333 0.3333
@@ -66,7 +66,7 @@ newmtl boat_buffer
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000
@@ -80,7 +80,7 @@ newmtl boat_roof_accessory
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000
@@ -94,7 +94,7 @@ newmtl boat_body
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000

View File

@@ -6,7 +6,7 @@ newmtl default
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000

View File

@@ -2,4 +2,3 @@ Epic Cinematic Trailer | ELITE by Alex-Productions | https://onsound.eu/
Music promoted by https://www.chosic.com/free-music/all/
Creative Commons CC BY 3.0
https://creativecommons.org/licenses/by/3.0/