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.lang.System.Logger.Level;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to play Background music in game
|
||||||
|
*/
|
||||||
public class BackgroundMusic implements GameEventListener {
|
public class BackgroundMusic implements GameEventListener {
|
||||||
private static final String VOLUME_PREF = "volume";
|
private static final String VOLUME_PREF = "volume";
|
||||||
private static final String MUSIC_ENABLED_PREF = "musicEnabled";
|
private static final String MUSIC_ENABLED_PREF = "musicEnabled";
|
||||||
@@ -32,7 +35,7 @@ public class BackgroundMusic implements GameEventListener {
|
|||||||
private Application app;
|
private Application app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes and controls the BackgroundMusic
|
* Constructor for BackgroundMusic class
|
||||||
*
|
*
|
||||||
* @param app The main Application
|
* @param app The main Application
|
||||||
*/
|
*/
|
||||||
@@ -50,13 +53,14 @@ public BackgroundMusic(Application app) {
|
|||||||
stop(loseMusic);
|
stop(loseMusic);
|
||||||
lastPlayedMusic = menuMusic.getName();
|
lastPlayedMusic = menuMusic.getName();
|
||||||
|
|
||||||
if(musicEnabled) {
|
if (musicEnabled) {
|
||||||
play(menuMusic);
|
play(menuMusic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates an audio node for the music
|
* Creates an audio node for the music
|
||||||
|
*
|
||||||
* @param musicFilePath the file path to the music
|
* @param musicFilePath the file path to the music
|
||||||
* @return the created audio node
|
* @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
|
* @param audioNode the audio node to be played
|
||||||
*/
|
*/
|
||||||
public void play(AudioNode audioNode) {
|
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
|
* @param audioNode the audio node to be paused
|
||||||
*/
|
*/
|
||||||
public void pause(AudioNode audioNode){
|
public void pause(AudioNode audioNode) {
|
||||||
if(audioNode.getStatus() == Status.Playing){
|
if (audioNode.getStatus() == Status.Playing) {
|
||||||
audioNode.pause();
|
audioNode.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stops the music
|
* Stops the music
|
||||||
|
*
|
||||||
* @param audioNode the audio node to be stopped
|
* @param audioNode the audio node to be stopped
|
||||||
*/
|
*/
|
||||||
public void stop(AudioNode audioNode){
|
public void stop(AudioNode audioNode) {
|
||||||
if (audioNode.getStatus() == Status.Playing) {
|
if (audioNode.getStatus() == Status.Playing) {
|
||||||
audioNode.stop();
|
audioNode.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle Method to control the music
|
* Controls which music should be played
|
||||||
*/
|
*/
|
||||||
public void toggleMusic() {
|
public void toggleMusic() {
|
||||||
this.musicEnabled = !this.musicEnabled;
|
this.musicEnabled = !this.musicEnabled;
|
||||||
if (musicEnabled) {
|
if (musicEnabled) {
|
||||||
switch (lastPlayedMusic){
|
switch (lastPlayedMusic) {
|
||||||
case MENU_MUSIC:
|
case MENU_MUSIC:
|
||||||
play(menuMusic);
|
play(menuMusic);
|
||||||
break;
|
break;
|
||||||
case GAME_MUSIC:
|
case GAME_MUSIC:
|
||||||
play(gameMusic);
|
play(gameMusic);
|
||||||
break;
|
break;
|
||||||
case VICTORY_MUSIC:
|
case VICTORY_MUSIC:
|
||||||
play(victoryMusic);
|
play(victoryMusic);
|
||||||
break;
|
break;
|
||||||
case LOSE_MUSIC:
|
case LOSE_MUSIC:
|
||||||
play(loseMusic);
|
play(loseMusic);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pause(menuMusic);
|
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
|
* @param music the music to play
|
||||||
*/
|
*/
|
||||||
public void changeMusic(Music music) {
|
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());
|
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
||||||
stop(gameMusic);
|
stop(gameMusic);
|
||||||
stop(victoryMusic);
|
stop(victoryMusic);
|
||||||
stop(loseMusic);
|
stop(loseMusic);
|
||||||
play(menuMusic);
|
play(menuMusic);
|
||||||
lastPlayedMusic = menuMusic.getName();
|
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());
|
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
||||||
stop(menuMusic);
|
stop(menuMusic);
|
||||||
stop(loseMusic);
|
stop(loseMusic);
|
||||||
stop(victoryMusic);
|
stop(victoryMusic);
|
||||||
play(gameMusic);
|
play(gameMusic);
|
||||||
lastPlayedMusic = gameMusic.getName();
|
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());
|
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
||||||
stop(menuMusic);
|
stop(menuMusic);
|
||||||
stop(gameMusic);
|
stop(gameMusic);
|
||||||
stop(loseMusic);
|
stop(loseMusic);
|
||||||
play(victoryMusic);
|
play(victoryMusic);
|
||||||
lastPlayedMusic = victoryMusic.getName();
|
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());
|
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
||||||
stop(menuMusic);
|
stop(menuMusic);
|
||||||
stop(gameMusic);
|
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
|
* @param music the received Event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent (MusicEvent music){
|
public void receivedEvent(MusicEvent music) {
|
||||||
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
LOGGER.log(Level.DEBUG, "Received Music change Event {0}", music.toString());
|
||||||
switch (music.music()){
|
switch (music.music()) {
|
||||||
case MENU_THEME:
|
case MENU_THEME:
|
||||||
changeMusic(Music.MENU_THEME);
|
changeMusic(Music.MENU_THEME);
|
||||||
break;
|
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
|
* @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
|
* @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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.jme3.app.DebugKeysAppState;
|
import com.jme3.app.DebugKeysAppState;
|
||||||
@@ -232,7 +225,6 @@ public void simpleInitApp() {
|
|||||||
serverConnection.connect();
|
serverConnection.connect();
|
||||||
backgroundMusic = new BackgroundMusic(this);
|
backgroundMusic = new BackgroundMusic(this);
|
||||||
logic.addListener(backgroundMusic);
|
logic.addListener(backgroundMusic);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,7 +315,7 @@ public Draw getDraw() {
|
|||||||
return draw;
|
return draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackgroundMusic getBackgroundMusic(){
|
public BackgroundMusic getBackgroundMusic() {
|
||||||
return backgroundMusic;
|
return 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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.jme3.math.ColorRGBA;
|
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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
import com.jme3.app.Application;
|
||||||
@@ -135,6 +128,11 @@ public void shipDestroyed() {
|
|||||||
shipDestroyedSound.playInstance();
|
shipDestroyedSound.playInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays sound according to the received SoundEvent
|
||||||
|
*
|
||||||
|
* @param event the received SoundEvent
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(SoundEvent event) {
|
public void receivedEvent(SoundEvent event) {
|
||||||
switch (event.sound()) {
|
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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
@@ -56,13 +49,12 @@ public Menu(BattleshipApp app) {
|
|||||||
|
|
||||||
addChild(new Label(lookup("menu.music.volume"), new ElementId("slider_label")));
|
addChild(new Label(lookup("menu.music.volume"), new ElementId("slider_label")));
|
||||||
Slider volumeSlider = new Slider();
|
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);
|
volumeSlider.setDelta(0.05);
|
||||||
addChild(volumeSlider);
|
addChild(volumeSlider);
|
||||||
|
|
||||||
volumeRef = volumeSlider.getModel().createReference();
|
volumeRef = volumeSlider.getModel().createReference();
|
||||||
|
|
||||||
|
|
||||||
addChild(loadButton)
|
addChild(loadButton)
|
||||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||||
addChild(saveButton)
|
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
|
* @param tpf time per frame
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(float tpf){
|
public void update(float tpf) {
|
||||||
if(volumeRef.update()){
|
if (volumeRef.update()) {
|
||||||
double newVolume = volumeRef.get();
|
double newVolume = volumeRef.get();
|
||||||
adjustVolume(newVolume);
|
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
|
* @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() {
|
private void toggleMusic() {
|
||||||
app.getBackgroundMusic().toggleMusic();
|
app.getBackgroundMusic().toggleMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the state of the load and save buttons based on the game logic.
|
* 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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.simsilica.lemur.Checkbox;
|
import com.simsilica.lemur.Checkbox;
|
||||||
@@ -55,7 +48,7 @@ class NetworkDialog extends SimpleDialog {
|
|||||||
|
|
||||||
Checkbox hostServer = new Checkbox(lookup("start.own.server"));
|
Checkbox hostServer = new Checkbox(lookup("start.own.server"));
|
||||||
hostServer.setChecked(false);
|
hostServer.setChecked(false);
|
||||||
hostServer.addClickCommands(s->toggleOwnServer());
|
hostServer.addClickCommands(s -> toggleOwnServer());
|
||||||
|
|
||||||
final BattleshipApp app = network.getApp();
|
final BattleshipApp app = network.getApp();
|
||||||
final Container input = new Container(new SpringGridLayout());
|
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
|
* If hostServer-Checkbox is active, starts a new Server on the clients machine, else tries to connect to existing server
|
||||||
*/
|
*/
|
||||||
private void connect() {
|
private void connect() {
|
||||||
if(hostServer){
|
if (hostServer) {
|
||||||
startServer();
|
startServer();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, e.getMessage(), e);
|
LOGGER.log(Level.WARNING, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
connectToServer();
|
connectToServer();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
connectToServer();
|
connectToServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts a server on the clients machine
|
* Starts a server on the clients machine
|
||||||
*/
|
*/
|
||||||
private void startServer() {
|
private void startServer() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try{
|
try {
|
||||||
BattleshipServer battleshipServer = new BattleshipServer(Integer.parseInt(port.getText()));
|
BattleshipServer battleshipServer = new BattleshipServer(Integer.parseInt(port.getText()));
|
||||||
battleshipServer.run();
|
battleshipServer.run();
|
||||||
} catch (Exception e) {
|
}
|
||||||
LOGGER.log(Level.ERROR,e);
|
catch (Exception e) {
|
||||||
|
LOGGER.log(Level.ERROR, e);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handles the action for the hostServer-Checkbox
|
* Handles the action for the hostServer-Checkbox
|
||||||
*/
|
*/
|
||||||
private void toggleOwnServer(){
|
private void toggleOwnServer() {
|
||||||
hostServer = !hostServer;
|
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;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.jme3.network.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;
|
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;
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
|
|||||||
@@ -14,25 +14,26 @@
|
|||||||
import java.lang.System.Logger;
|
import java.lang.System.Logger;
|
||||||
import java.lang.System.Logger.Level;
|
import java.lang.System.Logger.Level;
|
||||||
|
|
||||||
|
|
||||||
public class HitEffectHandler {
|
public class HitEffectHandler {
|
||||||
private final AssetManager assetManager;
|
private final AssetManager assetManager;
|
||||||
private static final Logger LOGGER = System.getLogger(HitEffectHandler.class.getName());
|
private static final Logger LOGGER = System.getLogger(HitEffectHandler.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the HitEffectHandler class
|
* Constructor for the HitEffectHandler class
|
||||||
|
*
|
||||||
* @param app the main application
|
* @param app the main application
|
||||||
*/
|
*/
|
||||||
public HitEffectHandler(Application app){
|
public HitEffectHandler(Application app) {
|
||||||
assetManager = app.getAssetManager();
|
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 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
|
//Explosion
|
||||||
ParticleEmitter explosion = new ParticleEmitter("Explosion", Type.Triangle, 30);
|
ParticleEmitter explosion = new ParticleEmitter("Explosion", Type.Triangle, 30);
|
||||||
explosion.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"));
|
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.setLowLife(1f);
|
||||||
explosion.setHighLife(3.5f);
|
explosion.setHighLife(3.5f);
|
||||||
explosion.setParticlesPerSec(0);
|
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();
|
explosion.emitAllParticles();
|
||||||
|
|
||||||
//Debris
|
//Debris
|
||||||
ParticleEmitter debris = new ParticleEmitter("Debris", Type.Triangle, 6);
|
ParticleEmitter debris = new ParticleEmitter("Debris", Type.Triangle, 6);
|
||||||
Material debrisMaterial = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
Material debrisMaterial = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
||||||
debrisMaterial.setTexture("Texture", assetManager.loadTexture("Textures/Debris/debris.png"));
|
debrisMaterial.setTexture("Texture", assetManager.loadTexture("Textures/Debris/debris.png"));
|
||||||
@@ -67,7 +68,7 @@ public void hitEffect(Node battleshipNode, Shot shot){
|
|||||||
debris.setLowLife(1f);
|
debris.setLowLife(1f);
|
||||||
debris.setHighLife(3.5f);
|
debris.setHighLife(3.5f);
|
||||||
debris.setParticlesPerSec(0);
|
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();
|
debris.emitAllParticles();
|
||||||
|
|
||||||
//Fire
|
//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}", explosion.getLocalTranslation().toString());
|
||||||
// LOGGER.log(Level.DEBUG, "Created HitEffect at {0}", debris.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);
|
battleshipNode.attachChild(explosion);
|
||||||
explosion.addControl(new EffectControl(explosion, battleshipNode));
|
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
|
* @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);
|
ParticleEmitter missEffect = new ParticleEmitter("HitEffect", Type.Triangle, 45);
|
||||||
missEffect.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"));
|
missEffect.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"));
|
||||||
missEffect.setImagesX(2);
|
missEffect.setImagesX(2);
|
||||||
@@ -120,7 +121,7 @@ public ParticleEmitter missEffect(Shot shot){
|
|||||||
missEffect.setLowLife(0.7f);
|
missEffect.setLowLife(0.7f);
|
||||||
missEffect.setHighLife(1.8f);
|
missEffect.setHighLife(1.8f);
|
||||||
missEffect.setParticlesPerSec(0);
|
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());
|
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
|
* 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
|
* @param parentNode the node to be attached
|
||||||
*/
|
*/
|
||||||
public EffectControl(ParticleEmitter emitter, Node parentNode) {
|
public EffectControl(ParticleEmitter emitter, Node parentNode) {
|
||||||
@@ -152,7 +153,7 @@ public EffectControl(ParticleEmitter emitter, Node parentNode) {
|
|||||||
*
|
*
|
||||||
* @param emitter the particle emitter to be controlled
|
* @param emitter the particle emitter to be controlled
|
||||||
*/
|
*/
|
||||||
public EffectControl(ParticleEmitter emitter){
|
public EffectControl(ParticleEmitter emitter) {
|
||||||
this.emitter = emitter;
|
this.emitter = emitter;
|
||||||
this.parentNode = null;
|
this.parentNode = null;
|
||||||
}
|
}
|
||||||
@@ -177,5 +178,4 @@ protected void controlUpdate(float tpf) {
|
|||||||
@Override
|
@Override
|
||||||
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {}
|
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;
|
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;
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
@@ -117,6 +112,12 @@ public Spatial visit(Battleship ship) {
|
|||||||
return shipNode;
|
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
|
@Override
|
||||||
public Spatial visit(Shell shell) {
|
public Spatial visit(Shell shell) {
|
||||||
LOGGER.log(Logger.Level.DEBUG, "Visiting {0}", 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;
|
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;
|
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 BOX_COLOR = ColorRGBA.Gray;
|
||||||
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
|
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
|
||||||
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
||||||
private HitEffectHandler hitEffectHandler;
|
private final HitEffectHandler hitEffectHandler;
|
||||||
|
|
||||||
private final ShipMap map;
|
private final ShipMap map;
|
||||||
private final BattleshipApp app;
|
private final BattleshipApp app;
|
||||||
@@ -146,8 +141,8 @@ public Spatial visit(Battleship ship) {
|
|||||||
/**
|
/**
|
||||||
* Visits a Shell and creates a graphical representation of it.
|
* Visits a Shell and creates a graphical representation of it.
|
||||||
*
|
*
|
||||||
* @param shell the battleship to be represented
|
* @param shell the Shell to be represented
|
||||||
* @return the node containing the graphical representation of the battleship
|
* @return the node containing the graphical representation of the Shell
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shell shell) {
|
public Spatial visit(Shell shell) {
|
||||||
@@ -156,12 +151,11 @@ public Spatial visit(Shell shell) {
|
|||||||
|
|
||||||
final float x = shell.getY();
|
final float x = shell.getY();
|
||||||
final float z = shell.getX();
|
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));
|
node.addControl(new ShellControl(shell, app));
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the appropriate graphical representation of the specified battleship.
|
* Creates the appropriate graphical representation of the specified battleship.
|
||||||
* The representation is either a detailed model or a simple box based on the length of the ship.
|
* The representation is 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
|
* @return the spatial representing the battleship
|
||||||
*/
|
*/
|
||||||
private Spatial createShip(Battleship ship) {
|
private Spatial createShip(Battleship ship) {
|
||||||
return switch (ship.getLength()){
|
return switch (ship.getLength()) {
|
||||||
case 1 -> createPatrolBoat(ship);
|
case 1 -> createPatrolBoat(ship);
|
||||||
case 2 -> createModernBattleship(ship);
|
case 2 -> createModernBattleship(ship);
|
||||||
case 3 -> createUboat(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.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||||
model.scale(0.000075f);
|
model.scale(0.000075f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
model.move(0,0.2f,0);
|
model.move(0, 0.2f, 0);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,15 +263,13 @@ private Spatial createMissile() {
|
|||||||
|
|
||||||
model.setQueueBucket(RenderQueue.Bucket.Opaque);
|
model.setQueueBucket(RenderQueue.Bucket.Opaque);
|
||||||
|
|
||||||
model.rotate(-HALF_PI,0,0);
|
model.rotate(-HALF_PI, 0, 0);
|
||||||
model.scale(0.009f);
|
model.scale(0.009f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
model.move(0,0f,0);
|
model.move(0, 0f, 0);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a detailed 3D model to represent a Uboat.
|
* 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.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||||
model.scale(0.45f);
|
model.scale(0.45f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
model.move(0,-0.25f,0);
|
model.move(0, -0.25f, 0);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@@ -313,7 +305,6 @@ private Spatial createPatrolBoat(Battleship ship) {
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the rotation angle for the specified rotation.
|
* Calculates the rotation angle for the specified rotation.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
import java.lang.System.Logger;
|
import java.lang.System.Logger;
|
||||||
import java.lang.System.Logger.Level;
|
import java.lang.System.Logger.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to control the 3D representation of a shell
|
||||||
|
*/
|
||||||
public class ShellControl extends AbstractControl {
|
public class ShellControl extends AbstractControl {
|
||||||
|
|
||||||
private final Shell shell;
|
private final Shell shell;
|
||||||
@@ -18,24 +21,42 @@ public class ShellControl extends AbstractControl {
|
|||||||
private static final float TRAVEL_SPEED = 8.5f;
|
private static final float TRAVEL_SPEED = 8.5f;
|
||||||
static final Logger LOGGER = System.getLogger(BattleshipApp.class.getName());
|
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) {
|
public ShellControl(Shell shell, BattleshipApp app) {
|
||||||
this.shell = shell;
|
this.shell = shell;
|
||||||
this.app = app;
|
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
|
@Override
|
||||||
public void controlUpdate(float tpf) {
|
public void controlUpdate(float tpf) {
|
||||||
//LOGGER.log(Level.DEBUG, "missile at x=" + shell.getX() + ", y=" + shell.getY());
|
//LOGGER.log(Level.DEBUG, "missile at x=" + shell.getX() + ", y=" + shell.getY());
|
||||||
spatial.move(0, -TRAVEL_SPEED*tpf, 0);
|
spatial.move(0, -TRAVEL_SPEED * tpf, 0);
|
||||||
if(spatial.getLocalTranslation().getY() <= 0.2){
|
if (spatial.getLocalTranslation().getY() <= 0.2) {
|
||||||
spatial.getParent().detachChild(spatial);
|
spatial.getParent().detachChild(spatial);
|
||||||
app.getGameLogic().send(new EndAnimationMessage(new IntPoint(shell.getX(), shell.getY())));
|
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
|
@Override
|
||||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,29 +9,52 @@
|
|||||||
import pp.battleship.model.IntPoint;
|
import pp.battleship.model.IntPoint;
|
||||||
import pp.util.Position;
|
import pp.util.Position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to control the 2D representation of a shell
|
||||||
|
*/
|
||||||
public class ShellMapControl extends AbstractControl {
|
public class ShellMapControl extends AbstractControl {
|
||||||
private final Position position;
|
private final Position position;
|
||||||
private final IntPoint pos;
|
private final IntPoint pos;
|
||||||
private static final Vector3f vector = new Vector3f();
|
private static final Vector3f VECTOR_3_F = new Vector3f();
|
||||||
private final BattleshipApp app;
|
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) {
|
public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) {
|
||||||
super();
|
super();
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.app = app;
|
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
|
@Override
|
||||||
protected void controlUpdate(float tpf) {
|
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()) {
|
if (spatial.getLocalTranslation().getX() >= position.getX() && spatial.getLocalTranslation().getY() >= position.getY()) {
|
||||||
spatial.getParent().detachChild(spatial);
|
spatial.getParent().detachChild(spatial);
|
||||||
app.getGameLogic().send(new EndAnimationMessage(pos));
|
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
|
@Override
|
||||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
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;
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
@@ -88,12 +83,12 @@ protected void controlUpdate(float tpf) {
|
|||||||
// If spatial is null, do nothing
|
// If spatial is null, do nothing
|
||||||
if (spatial == null) return;
|
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());
|
LOGGER.log(Level.INFO, "Ship removed {0}", spatial.getName());
|
||||||
spatial.getParent().detachChild(spatial);
|
spatial.getParent().detachChild(spatial);
|
||||||
}
|
}
|
||||||
else if (battleship.isDestroyed()) {
|
else if (battleship.isDestroyed()) {
|
||||||
spatial.move(0,-0.2f*tpf,0);
|
spatial.move(0, -0.2f * tpf, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Update the time within the oscillation cycle
|
// Update the time within the oscillation cycle
|
||||||
|
|||||||
@@ -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;
|
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;
|
package server;
|
||||||
|
|
||||||
@@ -77,12 +72,18 @@ public BattleshipServer(int port) {
|
|||||||
logic = new ServerGameLogic(this, config);
|
logic = new ServerGameLogic(this, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a server
|
||||||
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
startServer();
|
startServer();
|
||||||
while (true)
|
while (true)
|
||||||
processNextMessage();
|
processNextMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a server
|
||||||
|
*/
|
||||||
private void startServer() {
|
private void startServer() {
|
||||||
try {
|
try {
|
||||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||||
@@ -98,6 +99,9 @@ private void startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes next received message
|
||||||
|
*/
|
||||||
private void processNextMessage() {
|
private void processNextMessage() {
|
||||||
try {
|
try {
|
||||||
pendingMessages.take().process(logic);
|
pendingMessages.take().process(logic);
|
||||||
@@ -108,6 +112,9 @@ private void processNextMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all serializable classes
|
||||||
|
*/
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
Serializer.registerClass(GameDetails.class);
|
Serializer.registerClass(GameDetails.class);
|
||||||
Serializer.registerClass(StartBattleMessage.class);
|
Serializer.registerClass(StartBattleMessage.class);
|
||||||
@@ -122,6 +129,9 @@ private void initializeSerializables() {
|
|||||||
Serializer.registerClass(SwitchToBattleState.class);
|
Serializer.registerClass(SwitchToBattleState.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all listeners
|
||||||
|
*/
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
myServer.addMessageListener(this, MapMessage.class);
|
myServer.addMessageListener(this, MapMessage.class);
|
||||||
myServer.addMessageListener(this, ShootMessage.class);
|
myServer.addMessageListener(this, ShootMessage.class);
|
||||||
@@ -129,6 +139,11 @@ private void registerListeners() {
|
|||||||
myServer.addConnectionListener(this);
|
myServer.addConnectionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a received message
|
||||||
|
* @param source the connection the message comes from
|
||||||
|
* @param message the received message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
public void messageReceived(HostedConnection source, Message message) {
|
||||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
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()));
|
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
|
@Override
|
||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
||||||
logic.addPlayer(hostedConnection.getId());
|
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
|
@Override
|
||||||
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
|
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
|
private void exit(int exitValue) { //NON-NLS
|
||||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||||
if (myServer != null)
|
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;
|
package server;
|
||||||
|
|
||||||
import pp.battleship.message.client.ClientInterpreter;
|
import pp.battleship.message.client.ClientInterpreter;
|
||||||
import pp.battleship.message.client.ClientMessage;
|
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) {
|
record ReceivedMessage(ClientMessage message, int from) {
|
||||||
void process(ClientInterpreter interpreter) {
|
void process(ClientInterpreter interpreter) {
|
||||||
message.accept(interpreter, from);
|
message.accept(interpreter, from);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ newmtl white
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 0.6667 0.6667 0.6667
|
Ka 0.6667 0.6667 0.6667
|
||||||
Kd 0.6667 0.6667 0.6667
|
Kd 0.6667 0.6667 0.6667
|
||||||
@@ -18,7 +18,7 @@ newmtl boat_elements_black
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.0000 0.0000 0.0000
|
||||||
Kd 0.0000 0.0000 0.0000
|
Kd 0.0000 0.0000 0.0000
|
||||||
@@ -30,7 +30,7 @@ newmtl boat_glass
|
|||||||
Ni 7.0000
|
Ni 7.0000
|
||||||
d 0.4000
|
d 0.4000
|
||||||
Tr 0.6000
|
Tr 0.6000
|
||||||
Tf 0.4000 0.4000 0.4000
|
Tf 0.4000 0.4000 0.4000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 0.1059 0.1569 0.1451
|
Ka 0.1059 0.1569 0.1451
|
||||||
Kd 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
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 0.2941 0.2157 0.0510
|
Ka 0.2941 0.2157 0.0510
|
||||||
Kd 0.2941 0.2157 0.0510
|
Kd 0.2941 0.2157 0.0510
|
||||||
@@ -54,7 +54,7 @@ newmtl boat_silver
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 0.3333 0.3333 0.3333
|
Ka 0.3333 0.3333 0.3333
|
||||||
Kd 0.3333 0.3333 0.3333
|
Kd 0.3333 0.3333 0.3333
|
||||||
@@ -66,7 +66,7 @@ newmtl boat_buffer
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 1.0000 1.0000 1.0000
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
@@ -80,7 +80,7 @@ newmtl boat_roof_accessory
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 1.0000 1.0000 1.0000
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
@@ -94,7 +94,7 @@ newmtl boat_body
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 1.0000 1.0000 1.0000
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ newmtl default
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 1.0000 1.0000 1.0000
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
|
|||||||
@@ -2,4 +2,3 @@ Epic Cinematic Trailer | ELITE by Alex-Productions | https://onsound.eu/
|
|||||||
Music promoted by https://www.chosic.com/free-music/all/
|
Music promoted by https://www.chosic.com/free-music/all/
|
||||||
Creative Commons CC BY 3.0
|
Creative Commons CC BY 3.0
|
||||||
https://creativecommons.org/licenses/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;
|
package pp.battleship.exporter;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ newmtl _King_George_V
|
|||||||
Ni 1.5000
|
Ni 1.5000
|
||||||
d 1.0000
|
d 1.0000
|
||||||
Tr 0.0000
|
Tr 0.0000
|
||||||
Tf 1.0000 1.0000 1.0000
|
Tf 1.0000 1.0000 1.0000
|
||||||
illum 2
|
illum 2
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 1.0000 1.0000 1.0000
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
|
|||||||
@@ -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;
|
package pp.battleship;
|
||||||
|
|
||||||
import pp.util.config.Config;
|
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;
|
package pp.battleship;
|
||||||
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|||||||
@@ -11,15 +11,25 @@
|
|||||||
|
|
||||||
import java.lang.System.Logger.Level;
|
import java.lang.System.Logger.Level;
|
||||||
|
|
||||||
public class AnimationState extends ClientState{
|
/**
|
||||||
|
* Represents the state in which the animation is played
|
||||||
|
*/
|
||||||
|
public class AnimationState extends ClientState {
|
||||||
|
|
||||||
private boolean myTurn;
|
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) {
|
public AnimationState(ClientGameLogic logic, boolean turn, IntPoint position) {
|
||||||
super(logic);
|
super(logic);
|
||||||
logic.playMusic(Music.GAME_THEME);
|
logic.playMusic(Music.GAME_THEME);
|
||||||
myTurn = turn;
|
myTurn = turn;
|
||||||
if (myTurn){
|
if (myTurn) {
|
||||||
logic.getOpponentMap().add(new Shell(position));
|
logic.getOpponentMap().add(new Shell(position));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -27,8 +37,13 @@ public AnimationState(ClientGameLogic logic, boolean turn, IntPoint position) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure the client renders the correct view
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
boolean showBattle(){
|
boolean showBattle() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +67,13 @@ public void receivedEffect(EffectMessage msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the client back to the battle state
|
||||||
|
*
|
||||||
|
* @param msg the received SwitchToBattleState message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedSwitchToBattleState(SwitchToBattleState msg){
|
public void receivedSwitchToBattleState(SwitchToBattleState msg) {
|
||||||
logic.setState(new BattleState(logic, msg.getTurn()));
|
logic.setState(new BattleState(logic, msg.getTurn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +109,7 @@ private void playSound(EffectMessage msg) {
|
|||||||
else if (msg.getDestroyedShip() == null)
|
else if (msg.getDestroyedShip() == null)
|
||||||
logic.playSound(Sound.EXPLOSION);
|
logic.playSound(Sound.EXPLOSION);
|
||||||
else
|
else
|
||||||
logic.playSound(Sound.DESTROYED_SHIP);
|
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;
|
package pp.battleship.game.client;
|
||||||
|
|
||||||
@@ -35,11 +30,21 @@ public BattleState(ClientGameLogic logic, boolean myTurn) {
|
|||||||
this.myTurn = myTurn;
|
this.myTurn = myTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure the client renders the correct view
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean showBattle() {
|
public boolean showBattle() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a shoot event if it's client's turn
|
||||||
|
*
|
||||||
|
* @param pos the position where the click occurred
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clickOpponentMap(IntPoint pos) {
|
public void clickOpponentMap(IntPoint pos) {
|
||||||
if (!myTurn)
|
if (!myTurn)
|
||||||
@@ -48,9 +53,14 @@ else if (logic.getOpponentMap().isValid(pos))
|
|||||||
logic.send(new ShootMessage(pos));
|
logic.send(new ShootMessage(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers an animation if StartAnimationMessage is received
|
||||||
|
*
|
||||||
|
* @param msg the received Startanimation message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedStartAnimation(StartAnimationMessage msg){
|
public void receivedStartAnimation(StartAnimationMessage msg) {
|
||||||
logic.setState(new AnimationState(logic, msg.isMyTurn(), msg.getPosition() ));
|
logic.setState(new AnimationState(logic, msg.isMyTurn(), msg.getPosition()));
|
||||||
logic.playSound(Sound.MISSILE_LAUNCH);
|
logic.playSound(Sound.MISSILE_LAUNCH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
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;
|
package pp.battleship.game.client;
|
||||||
|
|
||||||
@@ -231,6 +226,8 @@ public void received(EffectMessage msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Reports that client should play an animation
|
||||||
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -239,6 +236,8 @@ public void received(StartAnimationMessage msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Reports that client should switch to the battle state
|
||||||
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -375,9 +374,10 @@ public void update(float delta) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers an event to play specified music
|
* Triggers an event to play specified music
|
||||||
|
*
|
||||||
* @param music the music to be played
|
* @param music the music to be played
|
||||||
*/
|
*/
|
||||||
public void playMusic(Music music){
|
public void playMusic(Music music) {
|
||||||
notifyListeners(new MusicEvent(music));
|
notifyListeners(new MusicEvent(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;
|
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;
|
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
|
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) {
|
void receivedSwitchToBattleState(SwitchToBattleState msg) {
|
||||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedSwitchToBattleState not allowed in {0}", getName());
|
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) {
|
void receivedStartAnimation(StartAnimationMessage msg) {
|
||||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedStartAnimation not allowed in {0}", getName());
|
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;
|
package pp.battleship.game.client;
|
||||||
|
|
||||||
@@ -251,6 +246,12 @@ else if (!checkMapToLoad(dto)) {
|
|||||||
selectedInHarbor = null;
|
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) {
|
private boolean checkMapToLoad(ShipMapDTO dto) {
|
||||||
int mapWidth = dto.getWidth();
|
int mapWidth = dto.getWidth();
|
||||||
int mapHeight = dto.getHeight();
|
int mapHeight = dto.getHeight();
|
||||||
@@ -266,7 +267,7 @@ private boolean checkMapToLoad(ShipMapDTO dto) {
|
|||||||
|
|
||||||
// check if ships overlap
|
// check if ships overlap
|
||||||
List<Battleship> ships = dto.getShips();
|
List<Battleship> ships = dto.getShips();
|
||||||
for(Battleship ship:ships) {
|
for (Battleship ship : ships) {
|
||||||
for (Battleship compareShip : ships) {
|
for (Battleship compareShip : ships) {
|
||||||
if (!(ship == compareShip)) {
|
if (!(ship == compareShip)) {
|
||||||
if (ship.collidesWith(compareShip)) {
|
if (ship.collidesWith(compareShip)) {
|
||||||
|
|||||||
@@ -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;
|
package pp.battleship.game.client;
|
||||||
|
|
||||||
@@ -20,7 +15,7 @@ class GameOverState extends ClientState {
|
|||||||
*/
|
*/
|
||||||
GameOverState(ClientGameLogic logic, boolean loser) {
|
GameOverState(ClientGameLogic logic, boolean loser) {
|
||||||
super(logic);
|
super(logic);
|
||||||
if(loser){
|
if (loser) {
|
||||||
logic.playMusic(Music.LOSE_THEME);
|
logic.playMusic(Music.LOSE_THEME);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -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;
|
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
|
@Override
|
||||||
public boolean maySaveMap() {
|
public boolean maySaveMap() {
|
||||||
return false;
|
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;
|
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;
|
package pp.battleship.game.client;
|
||||||
|
|
||||||
@@ -40,6 +35,11 @@ public void receivedStartBattle(StartBattleMessage msg) {
|
|||||||
logic.setState(new BattleState(logic, msg.isMyTurn()));
|
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
|
@Override
|
||||||
public void receivedGameDetails(GameDetails details) {
|
public void receivedGameDetails(GameDetails details) {
|
||||||
ClientGameLogic.LOGGER.log(Level.WARNING, "Invalid Map"); //NON-NLS
|
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;
|
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;
|
package pp.battleship.game.server;
|
||||||
|
|
||||||
import pp.battleship.BattleshipConfig;
|
import pp.battleship.BattleshipConfig;
|
||||||
@@ -157,33 +150,32 @@ else if (!checkMap(msg, from)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param msg
|
* Handles the reception of an EndAnimation message
|
||||||
|
* @param msg received EndAnimation message
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(EndAnimationMessage msg, int from){
|
public void received(EndAnimationMessage msg, int from) {
|
||||||
if(state != ServerState.WAIT_ANIMATION)
|
if (state != ServerState.WAIT_ANIMATION)
|
||||||
LOGGER.log(Level.ERROR, "animation not allowed in {0}", state);
|
LOGGER.log(Level.ERROR, "animation not allowed in {0}", state);
|
||||||
else
|
else if (getPlayerById(from) == players.get(0)) {
|
||||||
if(getPlayerById(from) == players.get(0)){
|
LOGGER.log(Level.DEBUG, "{0} set to true", getPlayerById(from));
|
||||||
LOGGER.log(Level.DEBUG, "{0} set to true", getPlayerById(from));
|
p1AnimationFinished = true;
|
||||||
p1AnimationFinished = true;
|
shoot(getPlayerById(from), msg.getPosition());
|
||||||
shoot(getPlayerById(from), msg.getPosition());
|
}
|
||||||
}
|
else if (getPlayerById(from) == players.get(1)) {
|
||||||
else if (getPlayerById(from) == players.get(1)){
|
LOGGER.log(Level.DEBUG, "{0} set to true {1}", getPlayerById(from), getPlayerById(from).toString());
|
||||||
LOGGER.log(Level.DEBUG, "{0} set to true {1}", getPlayerById(from), getPlayerById(from).toString());
|
p2AnimationFinished = true;
|
||||||
p2AnimationFinished = true;
|
shoot(getPlayerById(from), msg.getPosition());
|
||||||
shoot(getPlayerById(from), msg.getPosition());
|
}
|
||||||
}
|
if (p1AnimationFinished && p2AnimationFinished) {
|
||||||
if(p1AnimationFinished && p2AnimationFinished) {
|
setState(ServerState.BATTLE);
|
||||||
setState(ServerState.BATTLE);
|
for (Player player : players)
|
||||||
for (Player player : players)
|
send(player, new SwitchToBattleState(player == activePlayer));
|
||||||
send(player, new SwitchToBattleState(player == activePlayer));
|
p1AnimationFinished = false;
|
||||||
p1AnimationFinished = false;
|
p2AnimationFinished = false;
|
||||||
p2AnimationFinished = false;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the map contains correct ship placement and is of the correct size
|
* 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) {
|
void shoot(Player player, IntPoint position) {
|
||||||
final Battleship selectedShip;
|
final Battleship selectedShip;
|
||||||
selectedShip = getSelectedShip(player, position);
|
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) {
|
Battleship getSelectedShip(Player player, IntPoint position) {
|
||||||
if (player != activePlayer) {
|
if (player != activePlayer) {
|
||||||
return player.getMap().findShipAt(position);
|
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) {
|
void shotMissed(Player player, IntPoint position) {
|
||||||
if (player != activePlayer) {
|
if (player != activePlayer) {
|
||||||
send(player, EffectMessage.miss(false, position));
|
send(player, EffectMessage.miss(false, position));
|
||||||
@@ -292,6 +300,12 @@ void shotMissed(Player player, IntPoint position) {
|
|||||||
activePlayer = player;
|
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) {
|
void shotHit(Player player, IntPoint position, Battleship ship) {
|
||||||
ship.hit(position);
|
ship.hit(position);
|
||||||
if (getOpponent(activePlayer).getMap().getRemainingShips().isEmpty()) {
|
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;
|
package pp.battleship.game.server;
|
||||||
|
|
||||||
import pp.battleship.message.server.ServerMessage;
|
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;
|
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;
|
package pp.battleship.game.singlemode;
|
||||||
|
|
||||||
import pp.battleship.BattleshipConfig;
|
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;
|
package pp.battleship.game.singlemode;
|
||||||
|
|
||||||
@@ -65,8 +60,9 @@ public void received(MapMessage msg, int from) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param msg
|
* Creates a copy of the provided EndAnimation message
|
||||||
* @param from
|
* @param msg thr received EndAnimation message
|
||||||
|
* @param from the identifier of the sender
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(EndAnimationMessage msg, int from) {
|
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;
|
package pp.battleship.game.singlemode;
|
||||||
|
|
||||||
import pp.battleship.game.client.BattleshipClient;
|
import pp.battleship.game.client.BattleshipClient;
|
||||||
@@ -21,6 +14,7 @@ class InterpreterProxy implements ServerInterpreter {
|
|||||||
private final BattleshipClient playerClient;
|
private final BattleshipClient playerClient;
|
||||||
|
|
||||||
static final System.Logger LOGGER = System.getLogger(InterpreterProxy.class.getName());
|
static final System.Logger LOGGER = System.getLogger(InterpreterProxy.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an InterpreterProxy with the specified BattleshipClient.
|
* Constructs an InterpreterProxy with the specified BattleshipClient.
|
||||||
*
|
*
|
||||||
@@ -96,7 +90,7 @@ public void received(StartAnimationMessage msg) {
|
|||||||
* @param msg the SwitchBattleState received from the server
|
* @param msg the SwitchBattleState received from the server
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(SwitchToBattleState msg){
|
public void received(SwitchToBattleState msg) {
|
||||||
LOGGER.log(System.Logger.Level.INFO, "Received SwitchBattleState");
|
LOGGER.log(System.Logger.Level.INFO, "Received SwitchBattleState");
|
||||||
forward(msg);
|
forward(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public void received(StartAnimationMessage msg) {
|
|||||||
* @param msg the SwitchBattleState received
|
* @param msg the SwitchBattleState received
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(SwitchToBattleState msg){
|
public void received(SwitchToBattleState msg) {
|
||||||
LOGGER.log(Level.INFO, "Received SwitchBattleStateMessage: {0}", msg);
|
LOGGER.log(Level.INFO, "Received SwitchBattleStateMessage: {0}", msg);
|
||||||
if (msg.getTurn())
|
if (msg.getTurn())
|
||||||
shoot();
|
shoot();
|
||||||
|
|||||||
@@ -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;
|
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;
|
package pp.battleship.message.client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,5 +20,10 @@ public interface ClientInterpreter {
|
|||||||
*/
|
*/
|
||||||
void received(MapMessage msg, int from);
|
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);
|
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;
|
package pp.battleship.message.client;
|
||||||
|
|
||||||
import com.jme3.network.AbstractMessage;
|
import com.jme3.network.AbstractMessage;
|
||||||
|
|||||||
@@ -3,14 +3,24 @@
|
|||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
import pp.battleship.model.IntPoint;
|
import pp.battleship.model.IntPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message sent by the client telling the server the animation is finished
|
||||||
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class EndAnimationMessage extends ClientMessage{
|
public class EndAnimationMessage extends ClientMessage {
|
||||||
|
|
||||||
private IntPoint position;
|
private IntPoint position;
|
||||||
|
|
||||||
private EndAnimationMessage(){/*do nothing */}
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private EndAnimationMessage() {/*do nothing */}
|
||||||
|
|
||||||
public EndAnimationMessage(final IntPoint position){
|
/**
|
||||||
|
* Constructs an EndAnimation message
|
||||||
|
* @param position the position to be effected
|
||||||
|
*/
|
||||||
|
public EndAnimationMessage(final IntPoint position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,9 +35,11 @@ public void accept(ClientInterpreter interpreter, int from) {
|
|||||||
interpreter.received(this, from);
|
interpreter.received(this, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the position
|
||||||
|
* @return IntPoint position
|
||||||
|
*/
|
||||||
public IntPoint getPosition() {
|
public IntPoint getPosition() {
|
||||||
return position;
|
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;
|
package pp.battleship.message.client;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.message.client;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.message.server;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.message.server;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.message.server;
|
||||||
|
|
||||||
import pp.battleship.message.client.EndAnimationMessage;
|
import pp.battleship.message.client.EndAnimationMessage;
|
||||||
@@ -36,7 +29,15 @@ public interface ServerInterpreter {
|
|||||||
*/
|
*/
|
||||||
void received(EffectMessage msg);
|
void received(EffectMessage msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a StartAnimation message received from the server
|
||||||
|
* @param msg the received StartAnimation message
|
||||||
|
*/
|
||||||
void received(StartAnimationMessage msg);
|
void received(StartAnimationMessage msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a SwitchToBattleState message received from the server
|
||||||
|
* @param msg the received SwitchToBattleState message
|
||||||
|
*/
|
||||||
void received(SwitchToBattleState msg);
|
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;
|
package pp.battleship.message.server;
|
||||||
|
|
||||||
import com.jme3.network.AbstractMessage;
|
import com.jme3.network.AbstractMessage;
|
||||||
|
|||||||
@@ -3,14 +3,25 @@
|
|||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
import pp.battleship.model.IntPoint;
|
import pp.battleship.model.IntPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message sent by the server to inform clients about the start of an animation
|
||||||
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class StartAnimationMessage extends ServerMessage {
|
public class StartAnimationMessage extends ServerMessage {
|
||||||
|
|
||||||
private IntPoint position;
|
private IntPoint position;
|
||||||
private boolean myTurn;
|
private boolean myTurn;
|
||||||
|
|
||||||
private StartAnimationMessage(){/*do nothing */}
|
/**
|
||||||
|
* 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) {
|
public StartAnimationMessage(IntPoint position, boolean myTurn) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.myTurn = myTurn;
|
this.myTurn = myTurn;
|
||||||
@@ -37,9 +48,15 @@ public String getInfoTextKey() {
|
|||||||
return "started animation at " + position;
|
return "started animation at " + position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the position
|
||||||
|
* @return IntPoint position
|
||||||
|
*/
|
||||||
public IntPoint getPosition() {return position;}
|
public IntPoint getPosition() {return position;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for myTurn
|
||||||
|
* @return boolean myTurn
|
||||||
|
*/
|
||||||
public boolean isMyTurn() {return 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;
|
package pp.battleship.message.server;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|||||||
@@ -2,14 +2,24 @@
|
|||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message sent by the server to tell client to switch to battle state
|
||||||
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class SwitchToBattleState extends ServerMessage{
|
public class SwitchToBattleState extends ServerMessage {
|
||||||
|
|
||||||
private boolean myTurn;
|
private boolean myTurn;
|
||||||
|
|
||||||
private SwitchToBattleState(){/*do nothing */}
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private SwitchToBattleState() {/*do nothing */}
|
||||||
|
|
||||||
public SwitchToBattleState(boolean turn){
|
/**
|
||||||
|
* Constructs a SwitchToBattleState message
|
||||||
|
* @param turn boolean it's client's turn
|
||||||
|
*/
|
||||||
|
public SwitchToBattleState(boolean turn) {
|
||||||
myTurn = turn;
|
myTurn = turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +44,9 @@ public String getInfoTextKey() {
|
|||||||
return "switched to battle state";
|
return "switched to battle state";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getTurn(){return myTurn;}
|
/**
|
||||||
|
* 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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
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;
|
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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class Shell implements Item {
|
|||||||
private int y;
|
private int y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs a new shell object
|
* Constructs a new Shell object
|
||||||
*
|
*
|
||||||
* @param position the end position of the shell
|
* @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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
import pp.battleship.notification.GameEvent;
|
import pp.battleship.notification.GameEvent;
|
||||||
@@ -92,8 +85,9 @@ public void add(Shot shot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a shell on the map
|
* Registers a Shell on the map
|
||||||
* @param shell the shell to be registered
|
*
|
||||||
|
* @param shell the Shell to be registered
|
||||||
*/
|
*/
|
||||||
public void add(Shell shell) {
|
public void add(Shell shell) {
|
||||||
addItem(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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,5 +22,10 @@ public interface Visitor<T> {
|
|||||||
*/
|
*/
|
||||||
T visit(Battleship ship);
|
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);
|
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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,5 +19,9 @@ public interface VoidVisitor {
|
|||||||
*/
|
*/
|
||||||
void visit(Battleship ship);
|
void visit(Battleship ship);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits a Shell element
|
||||||
|
* @param shell the Shell to be visited
|
||||||
|
*/
|
||||||
void visit(Shell shell);
|
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;
|
package pp.battleship.model.dto;
|
||||||
|
|
||||||
import pp.battleship.model.Battleship;
|
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;
|
package pp.battleship.model.dto;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
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
|
* This method returns the width of the DTO
|
||||||
|
*
|
||||||
* @return with of DTO
|
* @return with of DTO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public int getWidth() {return width;}
|
public int getWidth() {return width;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the height of the DTO
|
* This method returns the height of the DTO
|
||||||
|
*
|
||||||
* @return height of DTO
|
* @return height of DTO
|
||||||
*/
|
*/
|
||||||
|
public int getHeight() {return height;}
|
||||||
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;
|
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;
|
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;
|
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;
|
package pp.battleship.notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,5 +45,4 @@ default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
|||||||
* @param event the received Event
|
* @param event the received Event
|
||||||
*/
|
*/
|
||||||
default void receivedEvent(MusicEvent event) { /* do nothing */ }
|
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;
|
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;
|
package pp.battleship.notification;
|
||||||
|
|
||||||
import pp.battleship.model.Item;
|
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;
|
package pp.battleship.notification;
|
||||||
|
|
||||||
import pp.battleship.model.Item;
|
import pp.battleship.model.Item;
|
||||||
|
|||||||
@@ -5,19 +5,19 @@
|
|||||||
*/
|
*/
|
||||||
public enum Music {
|
public enum Music {
|
||||||
/**
|
/**
|
||||||
* menu music
|
* Menu music
|
||||||
*/
|
*/
|
||||||
MENU_THEME,
|
MENU_THEME,
|
||||||
/**
|
/**
|
||||||
* ingame music
|
* In game music
|
||||||
*/
|
*/
|
||||||
GAME_THEME,
|
GAME_THEME,
|
||||||
/**
|
/**
|
||||||
* music for a victory
|
* Victory music
|
||||||
*/
|
*/
|
||||||
VICTORY_THEME,
|
VICTORY_THEME,
|
||||||
/**
|
/**
|
||||||
* music for a loss
|
* Loss music
|
||||||
*/
|
*/
|
||||||
LOSE_THEME,
|
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;
|
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;
|
package pp.battleship.notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ dialog.error=Error
|
|||||||
dialog.question=Question
|
dialog.question=Question
|
||||||
port.must.be.integer=Port must be an integer number
|
port.must.be.integer=Port must be an integer number
|
||||||
map.doesnt.fit=The map doesn't fit to this game
|
map.doesnt.fit=The map doesn't fit to this game
|
||||||
map.invalid = map is invalid
|
map.invalid=map is invalid
|
||||||
ships.dont.fit.the.map=Ships are out of bounds
|
ships.dont.fit.the.map=Ships are out of bounds
|
||||||
menu.music.toggle = Music on/off
|
menu.music.toggle=Music on/off
|
||||||
menu.music.volume = Volume
|
menu.music.volume=Volume
|
||||||
start.own.server = start server
|
start.own.server=start server
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ dialog.error=Fehler
|
|||||||
dialog.question=Frage
|
dialog.question=Frage
|
||||||
port.must.be.integer=Der Port muss eine ganze Zahl sein
|
port.must.be.integer=Der Port muss eine ganze Zahl sein
|
||||||
map.doesnt.fit=Diese Karte passt nicht zu diesem Spiel
|
map.doesnt.fit=Diese Karte passt nicht zu diesem Spiel
|
||||||
map.invalid = Karte ung<6E>ltig
|
map.invalid=Karte ung<6E>ltig
|
||||||
ships.dont.fit.the.map=Schiffe sind au<61>erhalb der Map
|
ships.dont.fit.the.map=Schiffe sind au<61>erhalb der Map
|
||||||
menu.music.toggle = Musik an/aus
|
menu.music.toggle=Musik an/aus
|
||||||
menu.music.volume = Lautst<EFBFBD>rke
|
menu.music.volume=Lautst<EFBFBD>rke
|
||||||
start.own.server = Server starten
|
start.own.server=Server starten
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
package pp.battleship.model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
########################################
|
########################################## Programming project code
|
||||||
## Programming project code
|
|
||||||
## UniBw M, 2022, 2023, 2024
|
## UniBw M, 2022, 2023, 2024
|
||||||
## www.unibw.de/inf2
|
## www.unibw.de/inf2
|
||||||
## (c) Mark Minas (mark.minas@unibw.de)
|
## (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;
|
package pp.battleship.server;
|
||||||
|
|
||||||
import com.jme3.network.ConnectionListener;
|
import com.jme3.network.ConnectionListener;
|
||||||
@@ -81,12 +74,18 @@ public static void main(String[] args) {
|
|||||||
logic = new ServerGameLogic(this, config);
|
logic = new ServerGameLogic(this, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a server
|
||||||
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
startServer();
|
startServer();
|
||||||
while (true)
|
while (true)
|
||||||
processNextMessage();
|
processNextMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a server
|
||||||
|
*/
|
||||||
private void startServer() {
|
private void startServer() {
|
||||||
try {
|
try {
|
||||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||||
@@ -102,6 +101,9 @@ private void startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes next received message
|
||||||
|
*/
|
||||||
private void processNextMessage() {
|
private void processNextMessage() {
|
||||||
try {
|
try {
|
||||||
pendingMessages.take().process(logic);
|
pendingMessages.take().process(logic);
|
||||||
@@ -112,6 +114,9 @@ private void processNextMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all serializable classes
|
||||||
|
*/
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
Serializer.registerClass(GameDetails.class);
|
Serializer.registerClass(GameDetails.class);
|
||||||
Serializer.registerClass(StartBattleMessage.class);
|
Serializer.registerClass(StartBattleMessage.class);
|
||||||
@@ -126,6 +131,9 @@ private void initializeSerializables() {
|
|||||||
Serializer.registerClass(SwitchToBattleState.class);
|
Serializer.registerClass(SwitchToBattleState.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all listeners
|
||||||
|
*/
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
myServer.addMessageListener(this, MapMessage.class);
|
myServer.addMessageListener(this, MapMessage.class);
|
||||||
myServer.addMessageListener(this, ShootMessage.class);
|
myServer.addMessageListener(this, ShootMessage.class);
|
||||||
@@ -133,6 +141,11 @@ private void registerListeners() {
|
|||||||
myServer.addConnectionListener(this);
|
myServer.addConnectionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a received message
|
||||||
|
* @param source the connection the message comes from
|
||||||
|
* @param message the received message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
public void messageReceived(HostedConnection source, Message message) {
|
||||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
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()));
|
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
|
@Override
|
||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
||||||
logic.addPlayer(hostedConnection.getId());
|
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
|
@Override
|
||||||
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
|
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
|
private void exit(int exitValue) { //NON-NLS
|
||||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||||
if (myServer != null)
|
if (myServer != null)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user