mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 01:09:46 +01:00
task 11
This commit is contained in:
parent
c0a3e8b37a
commit
b962444506
@ -9,6 +9,8 @@ dependencies {
|
||||
implementation project(":battleship:model")
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
implementation project(path: ':battleship:server')
|
||||
implementation project(path: ':battleship:server')
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
|
@ -7,10 +7,12 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import pp.battleship.server.BattleshipServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
@ -35,6 +37,7 @@ class NetworkDialog extends SimpleDialog {
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
private String hostname;
|
||||
private int portNumber;
|
||||
private final Button serverButton = new Button(lookup("client.server-start"));
|
||||
private Future<Object> connectionFuture;
|
||||
private Dialog progressDialog;
|
||||
|
||||
@ -65,7 +68,11 @@ class NetworkDialog extends SimpleDialog {
|
||||
.setOkClose(false)
|
||||
.setNoClose(false)
|
||||
.build(this);
|
||||
addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread));
|
||||
}
|
||||
//Add the button to start the sever
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles the action for the connect button in the connection dialog.
|
||||
@ -150,4 +157,21 @@ class NetworkDialog extends SimpleDialog {
|
||||
network.getApp().errorDialog(lookup("server.connection.failed"));
|
||||
network.getApp().setInfoText(e.getLocalizedMessage());
|
||||
}
|
||||
/**
|
||||
* Starts the server in a separate thread.
|
||||
*/
|
||||
private void startServerInThread() {
|
||||
serverButton.setEnabled(false);
|
||||
Thread serverThread = new Thread(() -> {
|
||||
try {
|
||||
BattleshipServer.main(null);
|
||||
} catch (Exception e) {
|
||||
serverButton.setEnabled(true);
|
||||
LOGGER.log(Level.ERROR, "Server could not be started", e);
|
||||
network.getApp().errorDialog("Could not start server: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
serverThread.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,3 +37,4 @@ dialog.error=Error
|
||||
dialog.question=Question
|
||||
port.must.be.integer=Port must be an integer number
|
||||
map.doesnt.fit=The map doesn't fit to this game
|
||||
client.server-start=Start server
|
@ -4,7 +4,7 @@
|
||||
## www.unibw.de/inf2
|
||||
## (c) Mark Minas (mark.minas@unibw.de)
|
||||
########################################
|
||||
#
|
||||
|
||||
battleship.name=Schiffe versenken
|
||||
button.ready=Bereit
|
||||
button.rotate=Rotiere
|
||||
@ -37,3 +37,4 @@ dialog.error=Fehler
|
||||
dialog.question=Frage
|
||||
port.must.be.integer=Der Port muss eine ganze Zahl sein
|
||||
map.doesnt.fit=Diese Karte passt nicht zu diesem Spiel
|
||||
client.server-start=Server starten
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
@ -5,7 +6,7 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.server;
|
||||
package pp.battleship.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
@ -176,4 +177,4 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
else
|
||||
LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user