fixed not working single mode, added read port from textline when client host server

This commit is contained in:
Cedric Beck
2024-10-12 16:17:46 +02:00
parent 9b85030050
commit bb1e3858bb
9 changed files with 15 additions and 13 deletions

View File

@@ -32,7 +32,7 @@ robot.targets=2, 0,\
2, 6
#
# Delay in milliseconds between each shot fired by the RobotClient.
robot.delay=500
robot.delay=4000
#
# The dimensions of the game map used in single mode.
# 'map.width' defines the number of columns, and 'map.height' defines the number of rows.

View File

@@ -84,9 +84,7 @@ public void initialize(AppStateManager stateManager, Application app) {
* Plays the shell flying sound effect.
*/
public void shellFly() {
System.out.println("shellFly");
if (isEnabled() && shellFlyingSound != null) {
System.out.println("play shell");
shellFlyingSound.playInstance();
}
}

View File

@@ -134,7 +134,7 @@ private Object initNetwork() {
private Object initServer() {
try {
server = new BattleshipServerClient();
server.run();
server.run(Integer.parseInt(port.getText()));
return null;
}
catch (Exception e) {

View File

@@ -85,8 +85,8 @@ public boolean isReady() {
/**
* Starts the server and continuously processes incoming messages.
*/
public void run() {
startServer();
public void run(int port) {
startServer(port);
while (true)
processNextMessage();
}
@@ -94,10 +94,10 @@ public void run() {
/**
* Starts the server by creating a network server on the specified port.
*/
private void startServer() {
private void startServer(int port) {
try {
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
myServer = Network.createServer(config.getPort());
myServer = Network.createServer(port);
initializeSerializables();
myServer.start();
registerListeners();