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

@@ -30,7 +30,6 @@ class BattleState extends ClientState {
*/
public BattleState(ClientGameLogic logic, boolean myTurn) {
super(logic);
System.out.println("battle state");
this.myTurn = myTurn;
}

View File

@@ -27,7 +27,6 @@ public class ShootingState extends ClientState {
*/
public ShootingState(ClientGameLogic logic, Shell shell, boolean myTurn, EffectMessage msg) {
super(logic);
System.out.println("shooting state");
this.msg = msg;
this.myTurn = myTurn;
this.shell = shell;

View File

@@ -167,6 +167,7 @@ public void received(AnimationFinishedMessage msg, int from) {
LOGGER.log(Level.ERROR, "animation finished not allowed in {0}", state);
}
else {
LOGGER.log(Level.DEBUG, "anim received from {0}", getPlayerById(from));
Player player = getPlayerById(from);
if (!waitPlayers.add(player)) {
LOGGER.log(Level.ERROR, "{0} already sent animation finished", player); //NON-NLS
@@ -222,8 +223,11 @@ private boolean checkMap(List<Battleship> ships) {
public void received(ShootMessage msg, int from) {
if (state != ServerState.BATTLE)
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
else
else{
setState(ServerState.ANIMATION);
shoot(getPlayerById(from), msg.getPosition());
}
}
/**
@@ -283,6 +287,5 @@ else if (selectedShip.isDestroyed()) {
send(otherPlayer, EffectMessage.hit(false, pos));
}
}
setState(ServerState.ANIMATION);
}
}

View File

@@ -66,7 +66,7 @@ public void received(MapMessage msg, int from) {
@Override
public void received(AnimationFinishedMessage msg, int from) {
copiedMessage = msg;
}
/**

View File

@@ -1,6 +1,7 @@
package pp.battleship.game.singlemode;
import pp.battleship.game.client.BattleshipClient;
import pp.battleship.message.client.AnimationFinishedMessage;
import pp.battleship.message.client.MapMessage;
import pp.battleship.message.client.ShootMessage;
import pp.battleship.message.server.EffectMessage;
@@ -71,6 +72,7 @@ public void run() {
* Makes the RobotClient take a shot by sending a ShootMessage with the target position.
*/
private void robotShot() {
connection.sendRobotMessage(new ShootMessage(getShotPosition()));
}
@@ -121,6 +123,7 @@ public void received(StartBattleMessage msg) {
@Override
public void received(EffectMessage msg) {
LOGGER.log(Level.INFO, "Received EffectMessage: {0}", msg); //NON-NLS
connection.sendRobotMessage(new AnimationFinishedMessage());
if (msg.isMyTurn())
shoot();
}