Code cleanup
added JavaDocs removed unnecessary lines
This commit is contained in:
1084
Dokumente/BattleshipDiagramm.drawio
Normal file
1084
Dokumente/BattleshipDiagramm.drawio
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
*/
|
||||
@@ -56,7 +59,8 @@ public BackgroundMusic(Application app) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,7 +87,8 @@ public void play(AudioNode audioNode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* pauses the music
|
||||
* Pauses the music
|
||||
*
|
||||
* @param audioNode the audio node to be paused
|
||||
*/
|
||||
public void pause(AudioNode audioNode) {
|
||||
@@ -92,7 +98,8 @@ public void pause(AudioNode audioNode){
|
||||
}
|
||||
|
||||
/**
|
||||
* stops the music
|
||||
* Stops the music
|
||||
*
|
||||
* @param audioNode the audio node to be stopped
|
||||
*/
|
||||
public void stop(AudioNode audioNode) {
|
||||
@@ -102,7 +109,7 @@ public void stop(AudioNode audioNode){
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Method to control the music
|
||||
* Controls which music should be played
|
||||
*/
|
||||
public void toggleMusic() {
|
||||
this.musicEnabled = !this.musicEnabled;
|
||||
@@ -133,7 +140,7 @@ 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
|
||||
*/
|
||||
@@ -145,21 +152,24 @@ public void changeMusic(Music music) {
|
||||
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,7 +180,7 @@ public void changeMusic(Music music) {
|
||||
}
|
||||
|
||||
/**
|
||||
* the method which receives the Event
|
||||
* Receives the different MusicEvents
|
||||
*
|
||||
* @param music the received Event
|
||||
*/
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
@@ -62,7 +55,6 @@ public Menu(BattleshipApp app) {
|
||||
|
||||
volumeRef = volumeSlider.getModel().createReference();
|
||||
|
||||
|
||||
addChild(loadButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton)
|
||||
@@ -76,7 +68,8 @@ 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
|
||||
@@ -88,7 +81,7 @@ public void update(float tpf){
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
@@ -168,34 +161,36 @@ private void connect() {
|
||||
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 {
|
||||
BattleshipServer battleshipServer = new BattleshipServer(Integer.parseInt(port.getText()));
|
||||
battleshipServer.run();
|
||||
} catch (Exception 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() {
|
||||
hostServer = !hostServer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
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) {
|
||||
@@ -28,7 +28,8 @@ public HitEffectHandler(Application app){
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -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,7 +103,8 @@ 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) {
|
||||
@@ -177,5 +178,4 @@ protected void controlUpdate(float tpf) {
|
||||
@Override
|
||||
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -161,7 +156,6 @@ public Spatial visit(Shell shell) {
|
||||
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.
|
||||
@@ -276,8 +270,6 @@ private Spatial createMissile() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a Uboat.
|
||||
*
|
||||
@@ -313,7 +305,6 @@ private Spatial createPatrolBoat(Battleship ship) {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the rotation angle for the specified rotation.
|
||||
*
|
||||
|
||||
@@ -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,11 +21,22 @@ 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());
|
||||
@@ -33,9 +47,16 @@ public void controlUpdate(float tpf) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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.exporter;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
@@ -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;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@@ -11,10 +11,20 @@
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* Represents the state in which the animation is played
|
||||
*/
|
||||
public class AnimationState extends ClientState {
|
||||
|
||||
private boolean myTurn;
|
||||
|
||||
/**
|
||||
* Constructor for the AnimationState class
|
||||
*
|
||||
* @param logic the client logic
|
||||
* @param turn a boolean containing if it's the client's turn
|
||||
* @param position the position a Shell gets created
|
||||
*/
|
||||
public AnimationState(ClientGameLogic logic, boolean turn, IntPoint position) {
|
||||
super(logic);
|
||||
logic.playMusic(Music.GAME_THEME);
|
||||
@@ -27,6 +37,11 @@ public AnimationState(ClientGameLogic logic, boolean turn, IntPoint position) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the client renders the correct view
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
boolean showBattle() {
|
||||
return true;
|
||||
@@ -52,6 +67,11 @@ public void receivedEffect(EffectMessage msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the client back to the battle state
|
||||
*
|
||||
* @param msg the received SwitchToBattleState message
|
||||
*/
|
||||
@Override
|
||||
public void receivedSwitchToBattleState(SwitchToBattleState msg) {
|
||||
logic.setState(new BattleState(logic, msg.getTurn()));
|
||||
@@ -89,6 +109,7 @@ private void playSound(EffectMessage msg) {
|
||||
else if (msg.getDestroyedShip() == null)
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
else
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
logic.playSound(Sound.DESTROYED_SHIP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -35,11 +30,21 @@ public BattleState(ClientGameLogic logic, boolean myTurn) {
|
||||
this.myTurn = myTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the client renders the correct view
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean showBattle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a shoot event if it's client's turn
|
||||
*
|
||||
* @param pos the position where the click occurred
|
||||
*/
|
||||
@Override
|
||||
public void clickOpponentMap(IntPoint pos) {
|
||||
if (!myTurn)
|
||||
@@ -48,6 +53,11 @@ else if (logic.getOpponentMap().isValid(pos))
|
||||
logic.send(new ShootMessage(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers an animation if StartAnimationMessage is received
|
||||
*
|
||||
* @param msg the received Startanimation message
|
||||
*/
|
||||
@Override
|
||||
public void receivedStartAnimation(StartAnimationMessage msg) {
|
||||
logic.setState(new AnimationState(logic, msg.isMyTurn(), msg.getPosition()));
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -231,6 +226,8 @@ public void received(EffectMessage msg) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that client should play an animation
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@Override
|
||||
@@ -239,6 +236,8 @@ public void received(StartAnimationMessage msg) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that client should switch to the battle state
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@Override
|
||||
@@ -375,6 +374,7 @@ public void update(float delta) {
|
||||
|
||||
/**
|
||||
* Triggers an event to play specified music
|
||||
*
|
||||
* @param music the music to be played
|
||||
*/
|
||||
public void playMusic(Music music) {
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -167,10 +162,20 @@ void receivedEffect(EffectMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedEffect not allowed in {0}", getName()); //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that client should switch to battle state
|
||||
*
|
||||
* @param msg the received SwitchToBattleState message
|
||||
*/
|
||||
void receivedSwitchToBattleState(SwitchToBattleState msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedSwitchToBattleState not allowed in {0}", getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that the client should start an animation
|
||||
*
|
||||
* @param msg the received StartAnimation message
|
||||
*/
|
||||
void receivedStartAnimation(StartAnimationMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedStartAnimation not allowed in {0}", getName());
|
||||
}
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -251,6 +246,12 @@ else if (!checkMapToLoad(dto)) {
|
||||
selectedInHarbor = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided map meets the requirements
|
||||
*
|
||||
* @param dto the data transfer object to check
|
||||
* @return boolean if the map meets the requirements
|
||||
*/
|
||||
private boolean checkMapToLoad(ShipMapDTO dto) {
|
||||
int mapWidth = dto.getWidth();
|
||||
int mapHeight = dto.getHeight();
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -58,6 +53,11 @@ private void fillHarbor(GameDetails details) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if map may be saved to file
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
@Override
|
||||
public boolean maySaveMap() {
|
||||
return false;
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
@@ -40,6 +35,11 @@ public void receivedStartBattle(StartBattleMessage msg) {
|
||||
logic.setState(new BattleState(logic, msg.isMyTurn()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts the client back to the editor state if an invalid map is provided
|
||||
*
|
||||
* @param details the game details including map size and ships
|
||||
*/
|
||||
@Override
|
||||
public void receivedGameDetails(GameDetails details) {
|
||||
ClientGameLogic.LOGGER.log(Level.WARNING, "Invalid Map"); //NON-NLS
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
@@ -157,14 +150,14 @@ else if (!checkMap(msg, from)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param msg
|
||||
* Handles the reception of an EndAnimation message
|
||||
* @param msg received EndAnimation message
|
||||
*/
|
||||
@Override
|
||||
public void received(EndAnimationMessage msg, int from) {
|
||||
if (state != ServerState.WAIT_ANIMATION)
|
||||
LOGGER.log(Level.ERROR, "animation not allowed in {0}", state);
|
||||
else
|
||||
if(getPlayerById(from) == players.get(0)){
|
||||
else if (getPlayerById(from) == players.get(0)) {
|
||||
LOGGER.log(Level.DEBUG, "{0} set to true", getPlayerById(from));
|
||||
p1AnimationFinished = true;
|
||||
shoot(getPlayerById(from), msg.getPosition());
|
||||
@@ -183,7 +176,6 @@ else if (getPlayerById(from) == players.get(1)){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the map contains correct ship placement and is of the correct size
|
||||
*
|
||||
@@ -258,6 +250,11 @@ void playerReady(Player player, List<Battleship> ships) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles what Effect should be triggered based on the shot
|
||||
* @param player the player receiving the message
|
||||
* @param position the position the shot hit
|
||||
*/
|
||||
void shoot(Player player, IntPoint position) {
|
||||
final Battleship selectedShip;
|
||||
selectedShip = getSelectedShip(player, position);
|
||||
@@ -269,6 +266,12 @@ void shoot(Player player, IntPoint position) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ship at a given position
|
||||
* @param player the player whose map will be checked for a ship
|
||||
* @param position the position to be checked for a ship
|
||||
* @return if there is a ship at the given position, returns the ship, else null
|
||||
*/
|
||||
Battleship getSelectedShip(Player player, IntPoint position) {
|
||||
if (player != activePlayer) {
|
||||
return player.getMap().findShipAt(position);
|
||||
@@ -278,6 +281,11 @@ Battleship getSelectedShip(Player player, IntPoint position) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the client that the shot missed
|
||||
* @param player the player receiving the message
|
||||
* @param position the position at which the shot hit in the water
|
||||
*/
|
||||
void shotMissed(Player player, IntPoint position) {
|
||||
if (player != activePlayer) {
|
||||
send(player, EffectMessage.miss(false, position));
|
||||
@@ -292,6 +300,12 @@ void shotMissed(Player player, IntPoint position) {
|
||||
activePlayer = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the client that the shot missed
|
||||
* @param player the player receiving the message
|
||||
* @param position the position at which the shot hit in the ship
|
||||
* @param ship the ship that has been hit
|
||||
*/
|
||||
void shotHit(Player player, IntPoint position, Battleship ship) {
|
||||
ship.hit(position);
|
||||
if (getOpponent(activePlayer).getMap().getRemainingShips().isEmpty()) {
|
||||
@@ -319,5 +333,4 @@ else if (ship.isDestroyed()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.game.server;
|
||||
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.game.singlemode;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
|
||||
@@ -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.game.singlemode;
|
||||
|
||||
@@ -65,8 +60,9 @@ public void received(MapMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param msg
|
||||
* @param from
|
||||
* Creates a copy of the provided EndAnimation message
|
||||
* @param msg thr received EndAnimation message
|
||||
* @param from the identifier of the sender
|
||||
*/
|
||||
@Override
|
||||
public void received(EndAnimationMessage msg, int from) {
|
||||
|
||||
@@ -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.game.singlemode;
|
||||
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
@@ -21,6 +14,7 @@ class InterpreterProxy implements ServerInterpreter {
|
||||
private final BattleshipClient playerClient;
|
||||
|
||||
static final System.Logger LOGGER = System.getLogger(InterpreterProxy.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs an InterpreterProxy with the specified BattleshipClient.
|
||||
*
|
||||
|
||||
@@ -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.game.singlemode;
|
||||
|
||||
|
||||
@@ -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.message.client;
|
||||
|
||||
/**
|
||||
@@ -27,5 +20,10 @@ public interface ClientInterpreter {
|
||||
*/
|
||||
void received(MapMessage msg, int from);
|
||||
|
||||
/**
|
||||
* Processes a received EndAnimation message
|
||||
* @param msg the received EndAnimation message
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
void received(EndAnimationMessage msg, int from);
|
||||
}
|
||||
|
||||
@@ -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.message.client;
|
||||
|
||||
import com.jme3.network.AbstractMessage;
|
||||
|
||||
@@ -3,13 +3,23 @@
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.battleship.model.IntPoint;
|
||||
|
||||
/**
|
||||
* A message sent by the client telling the server the animation is finished
|
||||
*/
|
||||
@Serializable
|
||||
public class EndAnimationMessage extends ClientMessage {
|
||||
|
||||
private IntPoint position;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private EndAnimationMessage() {/*do nothing */}
|
||||
|
||||
/**
|
||||
* Constructs an EndAnimation message
|
||||
* @param position the position to be effected
|
||||
*/
|
||||
public EndAnimationMessage(final IntPoint position) {
|
||||
this.position = position;
|
||||
}
|
||||
@@ -25,9 +35,11 @@ public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the position
|
||||
* @return IntPoint position
|
||||
*/
|
||||
public IntPoint getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.message.server;
|
||||
|
||||
import pp.battleship.message.client.EndAnimationMessage;
|
||||
@@ -36,7 +29,15 @@ public interface ServerInterpreter {
|
||||
*/
|
||||
void received(EffectMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a StartAnimation message received from the server
|
||||
* @param msg the received StartAnimation message
|
||||
*/
|
||||
void received(StartAnimationMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a SwitchToBattleState message received from the server
|
||||
* @param msg the received SwitchToBattleState message
|
||||
*/
|
||||
void received(SwitchToBattleState msg);
|
||||
}
|
||||
|
||||
@@ -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.message.server;
|
||||
|
||||
import com.jme3.network.AbstractMessage;
|
||||
|
||||
@@ -3,14 +3,25 @@
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.battleship.model.IntPoint;
|
||||
|
||||
/**
|
||||
* A message sent by the server to inform clients about the start of an animation
|
||||
*/
|
||||
@Serializable
|
||||
public class StartAnimationMessage extends ServerMessage {
|
||||
|
||||
private IntPoint position;
|
||||
private boolean myTurn;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private StartAnimationMessage() {/*do nothing */}
|
||||
|
||||
/**
|
||||
* Constructs a StartAnimation message
|
||||
* @param position the position a Shell will affect
|
||||
* @param myTurn boolean if it's client's turn
|
||||
*/
|
||||
public StartAnimationMessage(IntPoint position, boolean myTurn) {
|
||||
this.position = position;
|
||||
this.myTurn = myTurn;
|
||||
@@ -37,9 +48,15 @@ public String getInfoTextKey() {
|
||||
return "started animation at " + position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the position
|
||||
* @return IntPoint position
|
||||
*/
|
||||
public IntPoint getPosition() {return position;}
|
||||
|
||||
/**
|
||||
* Getter for myTurn
|
||||
* @return boolean myTurn
|
||||
*/
|
||||
public boolean isMyTurn() {return myTurn;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to tell client to switch to battle state
|
||||
*/
|
||||
@Serializable
|
||||
public class SwitchToBattleState extends ServerMessage {
|
||||
|
||||
private boolean myTurn;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private SwitchToBattleState() {/*do nothing */}
|
||||
|
||||
/**
|
||||
* Constructs a SwitchToBattleState message
|
||||
* @param turn boolean it's client's turn
|
||||
*/
|
||||
public SwitchToBattleState(boolean turn) {
|
||||
myTurn = turn;
|
||||
}
|
||||
@@ -34,7 +44,9 @@ public String getInfoTextKey() {
|
||||
return "switched to battle state";
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for myTurn
|
||||
* @return boolean myTurn
|
||||
*/
|
||||
public boolean getTurn() {return myTurn;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class Shell implements Item {
|
||||
private int y;
|
||||
|
||||
/**
|
||||
* constructs a new shell object
|
||||
* Constructs a new Shell object
|
||||
*
|
||||
* @param position the end position of the shell
|
||||
*/
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import pp.battleship.notification.GameEvent;
|
||||
@@ -92,8 +85,9 @@ public void add(Shot shot) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shell on the map
|
||||
* @param shell the shell to be registered
|
||||
* Registers a Shell on the map
|
||||
*
|
||||
* @param shell the Shell to be registered
|
||||
*/
|
||||
public void add(Shell shell) {
|
||||
addItem(shell);
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
/**
|
||||
@@ -29,5 +22,10 @@ public interface Visitor<T> {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
/**
|
||||
@@ -26,5 +19,9 @@ public interface VoidVisitor {
|
||||
*/
|
||||
void visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* Visits a Shell element
|
||||
* @param shell the Shell to be visited
|
||||
*/
|
||||
void visit(Shell shell);
|
||||
}
|
||||
|
||||
@@ -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.model.dto;
|
||||
|
||||
import pp.battleship.model.Battleship;
|
||||
|
||||
@@ -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.model.dto;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -117,15 +110,15 @@ public static ShipMapDTO loadFrom(File file) throws IOException {
|
||||
|
||||
/**
|
||||
* This method returns the width of the DTO
|
||||
*
|
||||
* @return with of DTO
|
||||
*/
|
||||
|
||||
public int getWidth() {return width;}
|
||||
|
||||
/**
|
||||
* This method returns the height of the DTO
|
||||
*
|
||||
* @return height of DTO
|
||||
*/
|
||||
|
||||
public int getHeight() {return height;}
|
||||
}
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
@@ -52,5 +45,4 @@ default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
||||
* @param event the received Event
|
||||
*/
|
||||
default void receivedEvent(MusicEvent event) { /* do nothing */ }
|
||||
|
||||
}
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
import pp.battleship.model.Item;
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
import pp.battleship.model.Item;
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
*/
|
||||
public enum Music {
|
||||
/**
|
||||
* menu music
|
||||
* Menu music
|
||||
*/
|
||||
MENU_THEME,
|
||||
/**
|
||||
* ingame music
|
||||
* In game music
|
||||
*/
|
||||
GAME_THEME,
|
||||
/**
|
||||
* music for a victory
|
||||
* Victory music
|
||||
*/
|
||||
VICTORY_THEME,
|
||||
/**
|
||||
* music for a loss
|
||||
* Loss music
|
||||
*/
|
||||
LOSE_THEME,
|
||||
}
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.notification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.client;
|
||||
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.game.server;
|
||||
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
########################################
|
||||
## Programming project code
|
||||
########################################## Programming project code
|
||||
## UniBw M, 2022, 2023, 2024
|
||||
## www.unibw.de/inf2
|
||||
## (c) Mark Minas (mark.minas@unibw.de)
|
||||
|
||||
@@ -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.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
@@ -81,12 +74,18 @@ public static void main(String[] args) {
|
||||
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
|
||||
@@ -102,6 +101,9 @@ private void startServer() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes next received message
|
||||
*/
|
||||
private void processNextMessage() {
|
||||
try {
|
||||
pendingMessages.take().process(logic);
|
||||
@@ -112,6 +114,9 @@ private void processNextMessage() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all serializable classes
|
||||
*/
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(GameDetails.class);
|
||||
Serializer.registerClass(StartBattleMessage.class);
|
||||
@@ -126,6 +131,9 @@ private void initializeSerializables() {
|
||||
Serializer.registerClass(SwitchToBattleState.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all listeners
|
||||
*/
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
@@ -133,6 +141,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
|
||||
@@ -140,12 +153,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
|
||||
@@ -158,6 +181,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)
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.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);
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user