fixed the equals method in piece
This commit is contained in:
@@ -80,7 +80,6 @@ public void received(ServerStartGameMessage msg) {
|
||||
}
|
||||
}
|
||||
logic.getGame().setBoard(msg.getBoard());
|
||||
System.out.println(logic.getGame().getPlayerById(logic.getOwnPlayerId()).toString());
|
||||
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
|
||||
for (var player : logic.getGame().getPlayers().values()) {
|
||||
List<UUID> pieces = new ArrayList<>();
|
||||
|
||||
@@ -46,6 +46,7 @@ public void enter() {
|
||||
for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
|
||||
logic.addNotification(new MovePieceNotification(entry.getValue().getPieces()[0].getUuid(), entry.getValue().getStartNodeIndex(), true));
|
||||
logic.getGame().getBoard().getInfield()[entry.getValue().getStartNodeIndex()].setOccupant(entry.getValue().getPieces()[0]);
|
||||
entry.getValue().getWaitingArea()[0] = null;
|
||||
animationCounter++;
|
||||
if(entry.getKey() == logic.getOwnPlayerId()){
|
||||
logic.addNotification(new AcquireCardNotification(entry.getValue().getHandCards().get(0).getCard()));
|
||||
|
||||
@@ -79,13 +79,13 @@ private StartNode createStartNode(int i) {
|
||||
*/
|
||||
public int getInfieldIndexOfPiece(Piece piece) {
|
||||
for (int i = 0; i < infield.length; i++) {
|
||||
if(infield[i].getOccupant() == null) {
|
||||
continue;
|
||||
}
|
||||
System.out.println(infield[i].getOccupant());
|
||||
if(infield[i].isOccupied()) {
|
||||
if (infield[i].getOccupant().equals(piece)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -159,7 +160,9 @@ public boolean equals(Object obj) {
|
||||
if (obj instanceof Piece) {
|
||||
Piece piece = (Piece) obj;
|
||||
|
||||
return this.hashCode() == piece.hashCode();
|
||||
System.out.println("own UUID: " + this.uuid + ". Other UUID: " + piece.uuid);
|
||||
return Objects.equals(this.uuid.toString(), piece.uuid.toString());
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -187,7 +187,7 @@ public int getHomeIndexOfPiece(Piece piece) {
|
||||
|
||||
public boolean pieceInsideOfHome(Piece piece) {
|
||||
for (Node node : this.homeNodes) {
|
||||
if (node.getOccupant().equals(piece)) {
|
||||
if (piece.equals(node.getOccupant())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public void initializeGame() {
|
||||
for (var player : this.logic.getGame().getPlayers().values()) {
|
||||
player.initialize();
|
||||
player.addHandCard(this.logic.getGame().draw());
|
||||
Piece piece = player.getWaitingArea()[0];
|
||||
Piece piece = player.getPieces()[0];
|
||||
player.getWaitingArea()[0] = null;
|
||||
piece.setState(PieceState.ACTIVE);
|
||||
this.logic.getGame().getBoard().getInfield()[player.getStartNodeIndex()].setOccupant(piece);
|
||||
|
||||
@@ -11,6 +11,7 @@ public abstract class ChoosePieceAutomatonState extends ServerState {
|
||||
* Create ChoosePieceAutomatonState attributes.
|
||||
*/
|
||||
protected final ChoosePieceState choosePieceAutomaton;
|
||||
private final System.Logger LOGGER = System.getLogger(ChoosePieceAutomatonState.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -92,6 +93,7 @@ private boolean canHomeMove(Piece piece, int moveIndex){
|
||||
|
||||
protected int calculateTargetIndex(Piece piece){
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
LOGGER.log(System.Logger.Level.INFO, "Calculating target index for piece: " + piece.getUuid() + " with steps: " + steps + "start index: " + logic.getGame().getBoard().getInfieldIndexOfPiece(piece));
|
||||
return (logic.getGame().getBoard().getInfieldIndexOfPiece(piece) + steps) % logic.getGame().getBoard().getInfield().length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,20 +30,21 @@ public StartPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic lo
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited StartPieceState state.");
|
||||
LOGGER.log(System.Logger.Level.INFO, "Enter StartPieceState state.");
|
||||
piece = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].getOccupant();
|
||||
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new StartPieceMessage(piece.getUuid(), calculateTargetIndex(piece)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received RequestMoveMessage message. is piece equals: " + piece.equals(msg.getPiece()));
|
||||
if (piece.equals(msg.getPiece())) {
|
||||
logic.getServerSender().broadcast(new MoveMessage(piece, false, calculateTargetIndex(piece)));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(piece.getColor()).getStartNodeIndex()].getOccupant();
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
}
|
||||
logic.getServerSender().broadcast(new MoveMessage(piece, false, calculateTargetIndex(piece)));
|
||||
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user