Remove moveOccupant

This commit is contained in:
Felix Koppe
2024-12-08 17:12:35 +01:00
parent d6e44c2d29
commit 884c5afc4e
5 changed files with 18 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true"> <configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true">
<option name="ALTERNATIVE_JRE_PATH" value="temurin-20" /> <option name="ALTERNATIVE_JRE_PATH" value="21" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp" /> <option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp" />
<module name="Projekte.mdga.client.main" /> <module name="Projekte.mdga.client.main" />

View File

@@ -51,12 +51,16 @@ public void received(MoveMessage msg){
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece); int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i); LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), i, msg.getTargetIndex()));
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece); Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
if (occ != null){ if (occ != null){
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ); logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor())); logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
} }
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), i, msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(msg.getPiece());
parent.getParent().setState(parent.getParent().getMovePiece()); parent.getParent().setState(parent.getParent().getMovePiece());
} }
} }

View File

@@ -43,12 +43,15 @@ public void selectPiece(Piece piece){
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()); Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(pieceToMove); Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex(), true));
if (occ != null){ if (occ != null){
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ); logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), pieceToMove.getColor())); logic.addNotification(new ThrowPieceNotification(occ.getUuid(), msg.getPiece().getColor()));
} }
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex(), true));
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(msg.getPiece());
pieceToMove.setState(PieceState.ACTIVE); pieceToMove.setState(PieceState.ACTIVE);
parent.getParent().setState(parent.getParent().getMovePiece()); parent.getParent().setState(parent.getParent().getMovePiece());
} }

View File

@@ -85,6 +85,7 @@ public int getInfieldIndexOfPiece(Piece piece) {
} }
} }
} }
return -1; return -1;
} }

View File

@@ -32,7 +32,7 @@ public WaitingPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic
*/ */
@Override @Override
public void enter() { public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered WaitingPieceState state."); LOGGER.log(System.Logger.Level.INFO, "Entered WaitingPieceState state.");
this.piece = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getWaitingPiece(); this.piece = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getWaitingPiece();
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new WaitPieceMessage(this.piece.getUuid())); logic.getServerSender().send(logic.getGame().getActivePlayerId(), new WaitPieceMessage(this.piece.getUuid()));
} }
@@ -41,10 +41,12 @@ public void enter() {
public void received(RequestMoveMessage msg, int from){ public void received(RequestMoveMessage msg, int from){
if (msg.getPiece().equals(this.piece)) { if (msg.getPiece().equals(this.piece)) {
piece.setState(PieceState.ACTIVE); piece.setState(PieceState.ACTIVE);
Piece thrownOcc = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].moveOccupant(this.piece); Piece thrownOcc = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].getOccupant();
if (thrownOcc != null) { if (thrownOcc != null) {
logic.getServerSender().broadcast(new MoveMessage());
logic.getGame().getPlayerByColor(thrownOcc.getColor()).addWaitingPiece(thrownOcc); logic.getGame().getPlayerByColor(thrownOcc.getColor()).addWaitingPiece(thrownOcc);
} }
logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].setOccupant(this.piece);
logic.getServerSender().broadcast(new MoveMessage(this.piece, false, logic.getGame().getPlayerById(logic.getGame().getActivePlayerId()).getStartNodeIndex())); logic.getServerSender().broadcast(new MoveMessage(this.piece, false, logic.getGame().getPlayerById(logic.getGame().getActivePlayerId()).getStartNodeIndex()));
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState()); this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
} }