Merge branch 'development2' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-01 into development2
This commit is contained in:
@@ -294,17 +294,14 @@ public void received(ChoosePieceStateMessage msg){
|
||||
|
||||
@Override
|
||||
public void received(DrawCardMessage msg){
|
||||
if(msg.getCard() instanceof HiddenCard){
|
||||
logic.getGame().getActivePlayer().addHandCard(msg.getCard());
|
||||
if (msg.getCard() instanceof HiddenCard) {
|
||||
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
|
||||
} else if(msg.getCard() instanceof TurboCard) {
|
||||
logic.addNotification(new AcquireCardNotification(BonusCard.TURBO));
|
||||
} else if(msg.getCard() instanceof ShieldCard) {
|
||||
logic.addNotification(new AcquireCardNotification(BonusCard.SHIELD));
|
||||
} else if(msg.getCard() instanceof SwapCard) {
|
||||
logic.addNotification(new AcquireCardNotification(BonusCard.SWAP));
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
else{
|
||||
logic.addNotification(new AcquireCardNotification(msg.getCard().getCard()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,18 +37,13 @@ protected void handlePowerCard(PlayCardMessage msg) {
|
||||
logic.getGame().getDiscardPile().add(msg.getCard());
|
||||
}
|
||||
|
||||
protected void throwPiece(Piece piece) {
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).addWaitingPiece(piece);
|
||||
logic.addNotification(new ThrowPieceNotification(piece.getUuid(), piece.getColor()));
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
|
||||
logic.getGame().getGameStatistics().increasePiecesBeingThrown();
|
||||
piece.setState(PieceState.WAITING);
|
||||
}
|
||||
|
||||
private void handleShield(UUID uuid) {
|
||||
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(uuid)) % 10 != 0) {
|
||||
Board board = logic.getGame().getBoard();
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(uuid);
|
||||
Node node = board.getInfield()[board.getInfieldIndexOfPiece(piece)];
|
||||
if (node.isStart()) {
|
||||
logic.getGame().getPieceThroughUUID(uuid).setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldActiveNotification(uuid));
|
||||
logic.addNotification(new ShieldSuppressedNotification(uuid));
|
||||
} else {
|
||||
logic.getGame().getPieceThroughUUID(uuid).setShield(ShieldState.ACTIVE);
|
||||
@@ -66,6 +61,22 @@ private void swapPieces(Piece messageOwn, Piece messageEnemy) {
|
||||
|
||||
ownNode.setOccupant(modelEnemy);
|
||||
enemyNode.setOccupant(modelOwn);
|
||||
|
||||
logic.addNotification(new SwapPieceNotification(modelOwn.getUuid(), modelEnemy.getUuid()));
|
||||
checkShieldAfterSwap(enemyNode, modelOwn);
|
||||
checkShieldAfterSwap(ownNode, modelEnemy);
|
||||
|
||||
}
|
||||
|
||||
private void checkShieldAfterSwap(Node node, Piece piece){
|
||||
if (node.isStart()){
|
||||
if (piece.isShielded()){
|
||||
piece.setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
|
||||
}
|
||||
} else if (piece.isSuppressed()){
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.GameState;
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.game.card.HiddenCard;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
@@ -33,7 +35,12 @@ public void received(CeremonyMessage msg) {
|
||||
|
||||
@Override
|
||||
public void received(DrawCardMessage msg){
|
||||
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
|
||||
logic.getGame().getActivePlayer().addHandCard(msg.getCard());
|
||||
if (msg.getCard() instanceof HiddenCard) {
|
||||
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
|
||||
}
|
||||
|
||||
//stats
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
|
||||
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
logic = logic;
|
||||
for (Piece piece : logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPieces()) {
|
||||
if (piece.isShielded() || piece.isSuppressed()){
|
||||
piece.setShield(ShieldState.NONE);
|
||||
@@ -159,11 +160,6 @@ public void received(ChoosePieceStateMessage msg){
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DrawCardMessage msg){
|
||||
|
||||
}
|
||||
|
||||
public ChoosePieceState getChoosePiece() {
|
||||
return choosePieceState;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.GameState;
|
||||
import pp.mdga.game.Node;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.game.ShieldState;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
@@ -33,12 +35,6 @@ public void received(CeremonyMessage msg) {
|
||||
logic.setState(logic.getCeremony());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DiceNowMessage msg) {
|
||||
logic.addNotification(new DiceNowNotification());
|
||||
parent.setState(parent.getTurn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DieMessage msg) {
|
||||
logic.getGame().setDiceEyes(msg.getDiceEye());
|
||||
@@ -48,8 +44,6 @@ public void received(DieMessage msg) {
|
||||
else {
|
||||
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
|
||||
}
|
||||
// logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes()));
|
||||
|
||||
|
||||
//stats
|
||||
if (msg.getDiceEye() == 6) {
|
||||
@@ -73,24 +67,61 @@ public void received(ActivePlayerMessage msg) {
|
||||
logic.getGame().setActiveColor(msg.getColor());
|
||||
if(msg.getColor() == logic.getGame().getPlayers().get(logic.getOwnPlayerId()).getColor()) {
|
||||
parent.setState(parent.getTurn());
|
||||
} else {
|
||||
for (Piece piece : logic.getGame().getActivePlayer().getPieces()){
|
||||
if (piece.isShielded() || piece.isSuppressed()){
|
||||
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
|
||||
piece.setShield(ShieldState.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void received(DrawCardMessage msg){
|
||||
// logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
|
||||
// logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
|
||||
// logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
} else {
|
||||
if(piece.getState().equals(PieceState.HOME)){
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
Node pieceNode = logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex];
|
||||
|
||||
//gets the oldNode
|
||||
int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getActivePlayer().getHomeNodes()[homeIndex];
|
||||
//gets the targetNode
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
|
||||
if (msg.getTargetIndex() ==logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else{
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
|
||||
}
|
||||
else{
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
|
||||
|
||||
//gets the targetNode
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
|
||||
|
||||
if (msg.getTargetIndex() ==logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else{
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
|
||||
if (occ != null) {
|
||||
@@ -110,7 +141,17 @@ public void received(MoveMessage msg) {
|
||||
}
|
||||
//set new node
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isStart()){
|
||||
if (piece.isShielded()){
|
||||
piece.setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
|
||||
}
|
||||
} else if (piece.isSuppressed()){
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
|
||||
}
|
||||
}
|
||||
System.out.println("send AnimationEndMessage");
|
||||
logic.getGame().setTurboFlag(false);
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.DetermineStartPlayerState;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.notification.AcquireCardNotification;
|
||||
import pp.mdga.notification.ActivePlayerNotification;
|
||||
@@ -48,10 +49,12 @@ public void enter() {
|
||||
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()));
|
||||
} else {
|
||||
logic.addNotification(new DrawCardNotification(entry.getValue().getColor(), entry.getValue().getHandCards().get(0).getCard()));
|
||||
for (PowerCard card : entry.getValue().getHandCards()){
|
||||
if(entry.getKey() == logic.getOwnPlayerId()){
|
||||
logic.addNotification(new AcquireCardNotification(card.getCard()));
|
||||
} else {
|
||||
logic.addNotification(new DrawCardNotification(entry.getValue().getColor(), card.getCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public void received(StartPieceMessage msg){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NoTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg){
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.TurnState;
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.card.ShieldCard;
|
||||
import pp.mdga.game.card.SwapCard;
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.notification.PlayCardNotification;
|
||||
@@ -12,6 +15,7 @@ public class PlayPowerCardState extends TurnStates {
|
||||
private final TurnState parent;
|
||||
|
||||
private PlayCardMessage playCardMessage;
|
||||
private int extraAnimationCounter = 0;
|
||||
|
||||
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
@@ -20,7 +24,12 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard().getCard()));
|
||||
if(playCardMessage.getCard().getCard().equals(BonusCard.SWAP)) {
|
||||
extraAnimationCounter++;
|
||||
}
|
||||
|
||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), playCardMessage.getCard().getCard()));
|
||||
logic.getGame().getActivePlayer().removeHandCard(playCardMessage.getCard());
|
||||
handlePowerCard(playCardMessage);
|
||||
}
|
||||
|
||||
@@ -35,6 +44,11 @@ public void setPlayCard(PlayCardMessage playCardMessage) {
|
||||
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
if(extraAnimationCounter > 0) {
|
||||
extraAnimationCounter--;
|
||||
return;
|
||||
}
|
||||
|
||||
logic.send(new AnimationEndMessage());
|
||||
parent.setState(parent.getRollDice());
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ public void exit() {
|
||||
|
||||
@Override
|
||||
public void received(SelectPieceMessage msg) {
|
||||
//TODO
|
||||
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new));
|
||||
parent.getSelectPiece().setPossiblePieces(pieces);
|
||||
ArrayList<UUID> listPiece = pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new));
|
||||
@@ -71,7 +70,7 @@ public void received(StartPieceMessage msg){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NoTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg){
|
||||
logic.getGame().setTurboFlag(false);
|
||||
parent.getParent().getParent().setState(parent.getParent().getParent().getWaiting());
|
||||
}
|
||||
|
||||
@@ -4,11 +4,15 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.ShieldState;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.notification.HomeMoveNotification;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.ShieldActiveNotification;
|
||||
import pp.mdga.notification.ShieldSuppressedNotification;
|
||||
import pp.mdga.notification.ThrowPieceNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -49,11 +53,38 @@ public void selectPiece(Piece piece) {
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
//logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
System.out.println("Client: selectPieceState: receivedMoveMessage: msg.isHomeMoved():" + msg.isHomeMove());
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
} else {
|
||||
System.out.println("Client: selectPieceState: receivedMoveMessage: msg.getPiece.getState():" + piece.getState());
|
||||
if (piece.getState().equals(PieceState.ACTIVE)) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
int infieldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
System.out.println("Client: SelectState: activePiece in Home: infieldIndex" + infieldIndex);
|
||||
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
logic.getGame().getBoard().getInfield()[infieldIndex].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
}
|
||||
else {
|
||||
System.out.println("Client: SelectPieceState: receivedMoveMessage:reached else");
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
System.out.println("Client: electPieceState: homeindex" + logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece));
|
||||
int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
|
||||
@@ -70,6 +101,16 @@ public void received(MoveMessage msg) {
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
//set new node
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isStart()) {
|
||||
if (piece.isShielded()) {
|
||||
piece.setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
|
||||
}
|
||||
}
|
||||
else if (piece.isSuppressed()) {
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
|
||||
}
|
||||
}
|
||||
logic.getGame().setTurboFlag(false);
|
||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||
|
||||
@@ -5,10 +5,14 @@
|
||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
|
||||
import pp.mdga.game.Node;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.ShieldState;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.RemoveShieldNotification;
|
||||
import pp.mdga.notification.ShieldActiveNotification;
|
||||
import pp.mdga.notification.ShieldSuppressedNotification;
|
||||
import pp.mdga.notification.ThrowPieceNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -63,6 +67,17 @@ public void received(MoveMessage msg){
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
}
|
||||
|
||||
if (targetNode.isStart()){
|
||||
if (piece.isShielded()){
|
||||
piece.setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
|
||||
}
|
||||
} else if (piece.isSuppressed()){
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
|
||||
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
|
||||
}
|
||||
|
||||
targetNode.setOccupant(msg.getPiece());
|
||||
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, targetIndex));
|
||||
logic.getGame().setTurboFlag(false);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import pp.mdga.client.gamestate.turnstate.PowerCardState;
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.card.*;
|
||||
import pp.mdga.message.client.NoPowerCardMessage;
|
||||
import pp.mdga.message.client.SelectCardMessage;
|
||||
@@ -73,8 +74,14 @@ public void received(PossibleCardsMessage msg){
|
||||
*/
|
||||
@Override
|
||||
public void selectCard(BonusCard card){
|
||||
Player player = logic.getGame().getPlayers().get(logic.getOwnPlayerId());
|
||||
ArrayList<PowerCard> handCards = player.getHandCards();
|
||||
if(card != null){
|
||||
logic.send(new SelectCardMessage(logic.getGame().getPlayers().get(logic.getOwnPlayerId()).getPowerCardByType(card)));
|
||||
PowerCard select = player.getPowerCardByType(card);
|
||||
if(select == null){
|
||||
select = select;
|
||||
}
|
||||
logic.send(new SelectCardMessage(select));
|
||||
} else {
|
||||
logic.send(new NoPowerCardMessage());
|
||||
}
|
||||
@@ -112,7 +119,6 @@ public void received(PossiblePieceMessage msg){
|
||||
if (msg.getEnemyPossiblePieces().isEmpty()){
|
||||
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
|
||||
parent.setState(parent.getShield());
|
||||
logic.addNotification(new SelectableShieldNotification(msg.getOwnPossiblePieces().stream().map(Piece::getUuid).toList()));
|
||||
} else {
|
||||
System.out.println("Should enter Swap State");
|
||||
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import pp.mdga.message.client.RequestPlayCardMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.notification.SelectableShieldNotification;
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,8 +28,7 @@ public ShieldState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
logic.addNotification(null);
|
||||
//TODO: selectable piece notification
|
||||
logic.addNotification(new SelectableShieldNotification(possiblePieces.stream().map(Piece::getUuid).toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,17 +18,17 @@ public class Die {
|
||||
/**
|
||||
* The probability of rolling a zero eye.
|
||||
*/
|
||||
public static final double ZERO_EYE = 0.2;
|
||||
public static final double ZERO_EYE = 0;
|
||||
|
||||
/**
|
||||
* The probability of rolling a normal eye.
|
||||
*/
|
||||
public static final double NORMAL_EYE = 0.2;
|
||||
public static final double NORMAL_EYE = 0;
|
||||
|
||||
/**
|
||||
* The probability of rolling a double eye.
|
||||
*/
|
||||
public static final double DOUBLE_EYE = 0.6;
|
||||
public static final double DOUBLE_EYE = 1;
|
||||
|
||||
/**
|
||||
* The modifier applied to the die roll.
|
||||
|
||||
@@ -87,15 +87,15 @@ public Game() {
|
||||
gameStatistics = new Statistic();
|
||||
initializeDrawPile();
|
||||
board = new Board();
|
||||
die = new Die(2,1,6,2,1,3);
|
||||
die = new Die(1,4);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the draw pile with the predefined number of bonus cards.
|
||||
*/
|
||||
private void initializeDrawPile() {
|
||||
// this.addBonusCards(new TurboCard(), AMOUNT_OF_TURBO_CARDS);
|
||||
this.addBonusCards(new SwapCard(), AMOUNT_OF_SWAP_CARDS);
|
||||
this.addBonusCards(new TurboCard(), AMOUNT_OF_TURBO_CARDS);
|
||||
// this.addBonusCards(new SwapCard(), AMOUNT_OF_SWAP_CARDS);
|
||||
// this.addBonusCards(new ShieldCard(), AMOUNT_OF_SHIELD_CARDS);
|
||||
Collections.shuffle(this.drawPile);
|
||||
}
|
||||
@@ -107,9 +107,13 @@ private void initializeDrawPile() {
|
||||
*/
|
||||
public PowerCard draw() {
|
||||
if (!this.drawPile.isEmpty()) {
|
||||
if (drawPile.size() == 1){
|
||||
Collections.shuffle(this.discardPile);
|
||||
this.drawPile.addAll(this.discardPile);
|
||||
discardPile.clear();
|
||||
}
|
||||
return this.drawPile.remove(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -210,6 +214,15 @@ public Player getPlayerByColor(Color color) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to the get the active player
|
||||
*
|
||||
* @return the active player
|
||||
*/
|
||||
public Player getActivePlayer(){
|
||||
return getPlayerByColor(activeColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return all connected players as a list.
|
||||
*
|
||||
|
||||
@@ -43,9 +43,6 @@ public Piece getOccupant() {
|
||||
* @param occupant the new occupant of the node
|
||||
*/
|
||||
public void setOccupant(Piece occupant) {
|
||||
if (occupant.isSuppressed()) {
|
||||
occupant.setShield(ShieldState.NONE);
|
||||
}
|
||||
this.occupant = occupant;
|
||||
}
|
||||
|
||||
@@ -99,4 +96,8 @@ public boolean isOccupied() {
|
||||
public boolean isOccupied(Color color) {
|
||||
return isOccupied() && this.occupant.getColor() == color;
|
||||
}
|
||||
|
||||
public boolean isStart() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ public PowerCard getPowerCardByType(BonusCard bonusCard) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// throw new RuntimeException("bonusCard is not in handCards");
|
||||
}
|
||||
|
||||
public Piece getWaitingPiece(){
|
||||
@@ -205,6 +206,22 @@ public boolean isHomeFinished(Piece piece) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method will be used to determine the highest index in the home
|
||||
*
|
||||
* @return the index
|
||||
*/
|
||||
public int getHighestHomeIdx(){
|
||||
for (int i =3; i>=0;i--){
|
||||
if(!homeNodes[i].isOccupied()) {
|
||||
System.out.println("Player: highestHomeIndex:"+i);
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the give name of the Player
|
||||
*
|
||||
|
||||
@@ -47,4 +47,9 @@ public Color getColor() {
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStart() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate that the client is now a spectator.
|
||||
*/
|
||||
@Serializable
|
||||
public class SpectatorMessage extends ServerMessage {
|
||||
/**
|
||||
* Constructor
|
||||
|
||||
@@ -37,7 +37,6 @@ public GameState(ServerGameLogic logic) {
|
||||
this.determineStartPlayerState = new DetermineStartPlayerState(this, logic);
|
||||
this.animationState = new AnimationState(this, logic);
|
||||
this.turnState = new TurnState(this, logic);
|
||||
this.setCurrentState(this.determineStartPlayerState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +45,7 @@ public GameState(ServerGameLogic logic) {
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered GameState state.");
|
||||
this.setCurrentState(this.determineStartPlayerState);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.game.card.ShieldCard;
|
||||
import pp.mdga.game.card.SwapCard;
|
||||
import pp.mdga.game.card.TurboCard;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
@@ -52,6 +56,39 @@ public void initializeGame() {
|
||||
for (var player : this.logic.getGame().getPlayers().values()) {
|
||||
player.initialize();
|
||||
player.addHandCard(this.logic.getGame().draw());
|
||||
//TODO
|
||||
player.addHandCard(new ShieldCard());
|
||||
player.addHandCard(new ShieldCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
player.addHandCard(new TurboCard());
|
||||
|
||||
player.addHandCard(new SwapCard());
|
||||
player.addHandCard(new SwapCard());
|
||||
|
||||
|
||||
Piece piece = player.getPieces()[0];
|
||||
player.getWaitingArea()[0] = null;
|
||||
piece.setState(PieceState.ACTIVE);
|
||||
|
||||
@@ -30,8 +30,10 @@ public class DetermineStartPlayerState extends GameAutomatonState {
|
||||
* Create DetermineStartPlayerState attributes.
|
||||
*/
|
||||
private final Map<Integer, Integer> diceResults = new HashMap<>();
|
||||
private final Map<Integer, Integer> finalDiceResults = new HashMap<>();
|
||||
private final List<Integer> playersHaveToRoll = new ArrayList<>();
|
||||
private final Set<Integer> messageReceived = new HashSet<>();;
|
||||
private int playerToStart;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -45,12 +47,13 @@ public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic)
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered DetermineStartPlayerState state.");
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entered DetermineStartPlayerState state.");
|
||||
playerToStart = this.logic.getGame().getPlayers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited DetermineStartPlayerState state.");
|
||||
LOGGER.log(Level.INFO, "Exited DetermineStartPlayerState state.");
|
||||
this.diceResults.clear();
|
||||
this.messageReceived.clear();
|
||||
}
|
||||
@@ -67,23 +70,21 @@ public void received(RequestDieMessage msg, int from) {
|
||||
int roll = this.logic.getGame().getDie().shuffle();
|
||||
this.logic.getServerSender().send(from, new DieMessage(roll));
|
||||
this.diceResults.put(from, roll);
|
||||
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
|
||||
if (this.diceResults.size() == playerToStart) {
|
||||
int maximumRoll = 0;
|
||||
|
||||
for (Map.Entry<Integer, Integer> entry : this.diceResults.entrySet()) {
|
||||
if (maximumRoll == entry.getValue()) {
|
||||
this.playersHaveToRoll.add(entry.getKey());
|
||||
LOGGER.log(Level.INFO, "Players have to roll(RD same as maximum): {0}", this.playersHaveToRoll.size());
|
||||
}
|
||||
else if (maximumRoll < entry.getValue()) {
|
||||
maximumRoll = entry.getValue();
|
||||
this.playersHaveToRoll.clear();
|
||||
this.playersHaveToRoll.add(entry.getKey());
|
||||
LOGGER.log(Level.INFO, "Players have to roll(RD higher as maximum): {0}", this.playersHaveToRoll.size());
|
||||
}
|
||||
}
|
||||
|
||||
for (int id: this.playersHaveToRoll) {
|
||||
this.diceResults.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,18 +98,24 @@ else if (maximumRoll < entry.getValue()) {
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
this.messageReceived.add(from);
|
||||
if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
|
||||
if (this.messageReceived.size() == playerToStart) {
|
||||
this.messageReceived.clear();
|
||||
LOGGER.log(Level.INFO, "Players have to roll(Animation End): {0}", this.playersHaveToRoll.size());
|
||||
if (this.playersHaveToRoll.size() > 1) {
|
||||
playerToStart = this.playersHaveToRoll.size();
|
||||
for (Integer id : this.playersHaveToRoll) {
|
||||
diceResults.remove(id);
|
||||
this.logic.getServerSender().send(id, new DiceNowMessage());
|
||||
}
|
||||
finalDiceResults.putAll(this.diceResults);
|
||||
diceResults.clear();
|
||||
}
|
||||
else {
|
||||
finalDiceResults.putAll(this.diceResults);
|
||||
LOGGER.log(Level.INFO, "Players have to roll: %s".formatted(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0))));
|
||||
Color color = this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor();
|
||||
this.logic.getGame().setActiveColor(color);
|
||||
this.logic.getServerSender().broadcast(new RankingResponseMessage(this.diceResults));
|
||||
this.logic.getServerSender().broadcast(new RankingResponseMessage(this.finalDiceResults));
|
||||
this.logic.getServerSender().broadcast(new ActivePlayerMessage(color));
|
||||
this.gameAutomaton.setCurrentState(this.gameAutomaton.getAnimationState());
|
||||
}
|
||||
|
||||
@@ -195,6 +195,7 @@ public void setCurrentState(TurnAutomatonState state) {
|
||||
if (this.currentState != null) {
|
||||
this.currentState.exit();
|
||||
}
|
||||
System.out.println("Server: the server entered:"+state);
|
||||
this.currentState = state;
|
||||
this.currentState.enter();
|
||||
}
|
||||
|
||||
@@ -17,86 +17,181 @@ public abstract class ChoosePieceAutomatonState extends ServerState {
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param choosePieceAutomaton as the automaton of the choose piece state as a ChoosePieceState object.
|
||||
* @param logic the game logic
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public ChoosePieceAutomatonState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.choosePieceAutomaton = choosePieceAutomaton;
|
||||
}
|
||||
|
||||
protected boolean canMove(Piece piece){
|
||||
/**
|
||||
* returns true, if the piece can move inside the home or infield or move from the infield to the home
|
||||
*
|
||||
* @param piece the piece that will be checked
|
||||
* @return true, if the piece can move
|
||||
*/
|
||||
protected boolean canMove(Piece piece) {
|
||||
System.out.println("Server: reached canMove() for piece: " + piece);
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
if (piece.getState().equals(PieceState.HOME)){
|
||||
return canHomeMove(piece, steps);
|
||||
} else {
|
||||
int homeMoves = getHomeMoves(piece, steps);
|
||||
if (homeMoves > 0){
|
||||
return canHomeMove(piece, homeMoves);
|
||||
} else {
|
||||
return canInfieldMove(piece, steps);
|
||||
}
|
||||
}
|
||||
}
|
||||
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
|
||||
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
|
||||
int targetIdx = normPieceIdx + steps;
|
||||
|
||||
protected int getHomeMoves(Piece piece, int steps){
|
||||
int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Color color = piece.getColor();
|
||||
int startIndex = logic.getGame().getPlayerByColor(color).getStartNodeIndex();
|
||||
int moveIndex = pieceIndex + steps;
|
||||
if (moveIndex > logic.getGame().getBoard().getInfield().length){
|
||||
if (startIndex > pieceIndex){
|
||||
return steps - (startIndex - pieceIndex -1);
|
||||
//checks if the piece can move in the home
|
||||
if (piece.getState().equals(PieceState.HOME)) {
|
||||
if (canPieceMoveInHome(piece, steps)) {
|
||||
return true;
|
||||
}
|
||||
moveIndex %= logic.getGame().getBoard().getInfield().length;
|
||||
if (moveIndex >= startIndex){
|
||||
return moveIndex - startIndex + 1;
|
||||
}
|
||||
else {
|
||||
if (canPieceMoveInHome(piece, steps)) {
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (pieceIndex < startIndex && startIndex <= moveIndex){
|
||||
return moveIndex - startIndex + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean canInfieldMove(Piece piece, int steps){
|
||||
int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
int moveIndex = (pieceIndex + steps) % logic.getGame().getBoard().getInfield().length;
|
||||
Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
|
||||
if (occupant != null){
|
||||
if (occupant.isShielded()){
|
||||
return false;
|
||||
}
|
||||
return occupant.getColor() != piece.getColor();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canHomeMove(Piece piece, int moveIndex){
|
||||
Color color = piece.getColor();
|
||||
Player player = logic.getGame().getPlayerByColor(color);
|
||||
Node[] homeNodes = player.getHomeNodes();
|
||||
int index;
|
||||
if (player.pieceInsideOfHome(piece)){
|
||||
index = player.getHomeIndexOfPiece(piece);
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
if (index + moveIndex >= homeNodes.length){
|
||||
return false;
|
||||
} else {
|
||||
for (int i = index; i <= index + moveIndex; i++){
|
||||
if(homeNodes[i].isOccupied()){
|
||||
return false;
|
||||
//checks if the piece will not go over its home-field
|
||||
else if (40 > targetIdx && (!piece.getState().equals(PieceState.HOME) || !piece.getState().equals(PieceState.HOMEFINISHED))) {
|
||||
Color activeColor = logic.getGame().getActiveColor();
|
||||
Node tartgetNode = logic.getGame().getBoard().getInfield()[(pieceIdx + steps) % 40];
|
||||
//checks if the target-node is not occupied by an own color
|
||||
if (!tartgetNode.isOccupied(activeColor)) {
|
||||
//checks if the targetNode is not occupied or the occupant ha no shield
|
||||
if (!tartgetNode.isOccupied() || tartgetNode.getOccupant().getShield() != ShieldState.ACTIVE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
//returns false it the piece can't move
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* tests if the piece can move in the home or inside the home
|
||||
*
|
||||
* @param piece
|
||||
* @param steps
|
||||
* @return false, if the piece can't move in the home
|
||||
*/
|
||||
protected boolean canPieceMoveInHome(Piece piece, int steps) {
|
||||
//tests if the piece can move inside the home
|
||||
steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
System.out.println("Server: reached canPieceMoveInHome for piece: " + piece + " and the steps: " + steps);
|
||||
|
||||
if (piece.getState().equals(PieceState.HOME)) {
|
||||
int homeIdx = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
System.out.println("Server: reached canPieceMoveInHome for piece: " + piece + " and the steps: " + steps + " and the homeIndex: " + homeIdx + " and the if-clause ((3 - homeIdx) >= steps - 1): " + ((3 - homeIdx) >= steps - 1));
|
||||
//tests if the steps are less than the possible movement
|
||||
if ((3 - homeIdx) >= steps - 1) {
|
||||
return !jumpOver(steps, homeIdx, false);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//tests if the piece can move in the home
|
||||
else if (piece.getState() == PieceState.ACTIVE) {
|
||||
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
|
||||
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
|
||||
int targetIdx = normPieceIdx + steps;
|
||||
System.out.println("Server: canPieceHomeMove: else: Active: with pieceIndex: " + pieceIdx + " and the steps: " + steps + " and startIdx: " + startIdx + " and targetIdx: " + targetIdx + " and the if-statement (targetIdx >= 40): " + (targetIdx >= 40));
|
||||
if (targetIdx >= 40) {
|
||||
int stepsToHome = 39 - normPieceIdx;
|
||||
int restMovement = steps - stepsToHome - 1;
|
||||
System.out.println("Server: canPieceHomeMove:else: restMovement: " + restMovement + " and the if-clause(restMovement >= 3):" + (restMovement >= 3));
|
||||
if (restMovement >= 4) return false;
|
||||
return !jumpOver(restMovement, 0, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* tests if the piece, when moved in or inside a home, must jump over another piece
|
||||
*
|
||||
* @param stepsInHome the steps walked inside the home
|
||||
* @param homeIdx the index of the piece inside, or 0 if come from outside
|
||||
* @param outside a boolean, if the piece moves inside a house or in a house
|
||||
* @return false, if there is no piece to jump over
|
||||
*/
|
||||
private boolean jumpOver(int stepsInHome, int homeIdx, boolean outside) {
|
||||
//tests if the piece comes from the outside in the home
|
||||
if (outside) {
|
||||
System.out.println("Server: jumpOver: for the homeIndex: " + homeIdx + " ,stepsInHome: " + stepsInHome + " , outside: " + outside + " annd the targetIndex: " + stepsInHome);
|
||||
if (logic.getGame().getActivePlayer().getHomeNodes()[stepsInHome].isOccupied()) return true;
|
||||
for (int i = 0; i <= stepsInHome; i++) {
|
||||
if (logic.getGame().getActivePlayer().getHomeNodes()[i].isOccupied()) return true;
|
||||
}
|
||||
}
|
||||
//tests if the piece jumps over a piece from inside the home
|
||||
else {
|
||||
int targetIndex = stepsInHome + homeIdx;
|
||||
System.out.println("Server: jumpOver: for the homeIndex: " + homeIdx + " ,stepsInHome: " + stepsInHome + " , outside: " + outside + " and the targetIndex: " + targetIndex);
|
||||
if (logic.getGame().getActivePlayer().getHomeNodes()[targetIndex].isOccupied()) return true;
|
||||
for (int i = 1 + homeIdx; i <= targetIndex; i++) {
|
||||
if (logic.getGame().getActivePlayer().getHomeNodes()[i].isOccupied()) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the index in the home, where the piece will go in the home
|
||||
*
|
||||
* @param piece the give piece
|
||||
* @return the index in the home, where the piece will go
|
||||
*/
|
||||
protected int getHomeTargetIdx(Piece piece, int steps) {
|
||||
//tests if the piece is active and move in the house
|
||||
if (piece.getState() == PieceState.ACTIVE) {
|
||||
//gets the id's
|
||||
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
|
||||
//normalize the idx
|
||||
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
|
||||
//calculate the steps to the home
|
||||
int stepsToHome = 39 - normPieceIdx;
|
||||
//calculates the rest-movement inside a home
|
||||
int restMovement = steps - stepsToHome - 1;
|
||||
System.out.println("Server: getHomeTargetIndex for the piece: " + piece + " with the index: " + restMovement);
|
||||
return restMovement;
|
||||
}
|
||||
//the else handles the logic if the piece is in the home and moves inside the house
|
||||
else {
|
||||
int pieceHomeIdx = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
System.out.println("Server: getHomeTargetIndex for the piece: " + piece + " with the index: " + (pieceHomeIdx + steps));
|
||||
return pieceHomeIdx + steps;
|
||||
}
|
||||
}
|
||||
|
||||
protected int calculateTargetIndex(Piece piece){
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
/**
|
||||
* returns the target index inside the infield
|
||||
*
|
||||
* @param piece the piece given
|
||||
* @return the index in the infield
|
||||
*/
|
||||
protected int getInfieldTarget(Piece piece, int steps) {
|
||||
int index = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
System.out.println("Server: calculated the targetIndex in the Infield for:" + piece + "with the value" + ((steps + index) % 40));
|
||||
return (steps + index) % 40;
|
||||
}
|
||||
|
||||
return (logic.getGame().getBoard().getInfieldIndexOfPiece(piece) + steps) % logic.getGame().getBoard().getInfield().length;
|
||||
/**
|
||||
* this method is used for calculating the targetIndex
|
||||
*
|
||||
* @param piece the piece give
|
||||
* @return the index
|
||||
*/
|
||||
protected int calculateTargetIndex(Piece piece) {
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
if (canPieceMoveInHome(piece, steps)) {
|
||||
System.out.println("Server: ChoosePieceStateAutomaton: calculate index in home:" + getHomeTargetIdx(piece, steps));
|
||||
return getHomeTargetIdx(piece, steps);
|
||||
}
|
||||
return getInfieldTarget(piece, steps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,48 +24,52 @@ public NoPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic
|
||||
super(choosePieceAutomaton, logic);
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
private void initialize() {
|
||||
Player activePlayer = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor());
|
||||
if(logic.getGame().getDiceModifier() == 0){
|
||||
if (logic.getGame().getDiceModifier() == 0) {
|
||||
if (logic.getGame().getDiceEyes() == 6) {
|
||||
if (activePlayer.hasPieceInWaitingArea()){
|
||||
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
|
||||
} else {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||
if (activePlayer.hasPieceInWaitingArea()) {
|
||||
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())) {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||
}
|
||||
}
|
||||
} else if (activePlayer.hasPieceInWaitingArea()) {
|
||||
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||
}
|
||||
else if (activePlayer.hasPieceInWaitingArea()) {
|
||||
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())) {
|
||||
if (logic.getGame().getDiceEyes() == 6) {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
checkSelectPiece(activePlayer);
|
||||
}
|
||||
} else if (canMove(logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].getOccupant())){
|
||||
}
|
||||
else if (canMove(logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].getOccupant())) {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getStartPieceState());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
checkSelectPiece(activePlayer);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
checkSelectPiece(activePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSelectPiece(Player activePlayer){
|
||||
private void checkSelectPiece(Player activePlayer) {
|
||||
ArrayList<Piece> moveablePieces = new ArrayList<>();
|
||||
for (Piece piece : activePlayer.getPieces()){
|
||||
if (piece.getState().equals(PieceState.ACTIVE) || piece.getState().equals(PieceState.HOME)){
|
||||
for (Piece piece : activePlayer.getPieces()) {
|
||||
if (piece.getState().equals(PieceState.ACTIVE) || piece.getState().equals(PieceState.HOME)) {
|
||||
moveablePieces.add(piece);
|
||||
}
|
||||
}
|
||||
moveablePieces.removeIf(piece -> !canMove(piece));
|
||||
if (moveablePieces.isEmpty()) {
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.choosePieceAutomaton.getSelectPieceState().setMoveablePieces(moveablePieces);
|
||||
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getSelectPieceState());
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@ public NoTurnState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic)
|
||||
private void setActivePlayer(Color color) {
|
||||
if (!logic.getGame().getPlayerByColor(color.next(logic.getGame())).isFinished()) {
|
||||
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next(logic.getGame()));
|
||||
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next(logic.getGame())));
|
||||
logic.getServerSender().broadcast(new ActivePlayerMessage(logic.getGame().getActiveColor()));
|
||||
} else {
|
||||
setActivePlayer(color.next(logic.getGame()));
|
||||
}
|
||||
this.choosePieceAutomaton.getTurnAutomaton().getGameAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getGameAutomaton().getTurnState());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import pp.mdga.game.*;
|
||||
import pp.mdga.game.card.HiddenCard;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.server.DrawCardMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
@@ -40,65 +41,111 @@ public void setMoveablePieces(ArrayList<Piece> moveablePieces) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered SelectPieceState state.");
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
for (Piece piece : moveablePieces) {
|
||||
int homeMoves = getHomeMoves(piece, steps);
|
||||
if (homeMoves > 0) {
|
||||
|
||||
if (canPieceMoveInHome(piece, steps)) {
|
||||
int target = getHomeTargetIdx(piece, steps);
|
||||
targetIndex.add(target);
|
||||
isHomeMove.add(true);
|
||||
targetIndex.add(homeMoves);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int target = getInfieldTarget(piece, steps);
|
||||
targetIndex.add(target);
|
||||
isHomeMove.add(false);
|
||||
targetIndex.add(calculateTargetIndex(piece));
|
||||
}
|
||||
}
|
||||
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new SelectPieceMessage(moveablePieces, isHomeMove, targetIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
if(!moveablePieces.contains(msg.getPiece())){
|
||||
public void received(RequestMoveMessage msg, int from) {
|
||||
if (!moveablePieces.contains(msg.getPiece())) {
|
||||
throw new RuntimeException("invalid Piece");
|
||||
}
|
||||
|
||||
int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
|
||||
Piece movePiece = moveablePieces.get(indexOfPiece);
|
||||
boolean homeMove = isHomeMove.get(indexOfPiece);
|
||||
int targIdx = targetIndex.get(indexOfPiece);
|
||||
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||
Piece piece = moveablePieces.get(indexOfPiece);
|
||||
if (canPieceMoveInHome(piece, steps)) {
|
||||
if (piece.getState().equals(PieceState.HOME)) {
|
||||
//gets the oldNode
|
||||
int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getActivePlayer().getHomeNodes()[homeIndex];
|
||||
//gets the targetNode
|
||||
int targetHomeIdx = getHomeTargetIdx(piece, steps);
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[targetHomeIdx];
|
||||
if (targetHomeIdx == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
Node oldNode = logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(movePiece)];
|
||||
oldNode.clearOccupant();
|
||||
if (homeMove) {
|
||||
//setPieceInHome
|
||||
logic.getGame().getPlayerByColor(msg.getPiece().getColor()).setPieceInHome(targIdx, movePiece);
|
||||
|
||||
if (logic.getGame().getPlayerByColor(msg.getPiece().getColor()).isHomeFinished(logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()))) {
|
||||
movePiece.setState(PieceState.HOMEFINISHED);
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
}
|
||||
else {
|
||||
movePiece.setState(PieceState.HOME);
|
||||
}
|
||||
movePiece.setShield(ShieldState.NONE);
|
||||
} else {
|
||||
Node targetNode = logic.getGame().getBoard().getInfield()[targIdx];
|
||||
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
|
||||
|
||||
if(targetNode.isBonus()) {
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if(p.getColor() == logic.getGame().getActiveColor()) {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(logic.getGame().draw()));
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
//gets the targetNode
|
||||
int targetHomeIdx = getHomeTargetIdx(piece, steps);
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[targetHomeIdx];
|
||||
|
||||
if (targetHomeIdx == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
}
|
||||
LOGGER.log(System.Logger.Level.INFO, "Server : SelectPieceState: PieceState:" + piece.getState());
|
||||
}
|
||||
else {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Server : SelectPieceState: PieceState:" + piece.getState());
|
||||
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
|
||||
|
||||
int targetIndex = (oldNoteIdx + steps) % 40;
|
||||
Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex];
|
||||
|
||||
Piece occ = targetNode.getOccupant();
|
||||
if (occ != null) {
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
}
|
||||
targetNode.setOccupant(msg.getPiece());
|
||||
|
||||
if (targetNode.isStart()) {
|
||||
if (piece.getShield() == ShieldState.ACTIVE) piece.setShield(ShieldState.SUPPRESSED);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
}
|
||||
|
||||
boolean homeMove = isHomeMove.get(indexOfPiece);
|
||||
int targIdx = targetIndex.get(indexOfPiece);
|
||||
|
||||
Node targetNode = logic.getGame().getBoard().getInfield()[targIdx];
|
||||
|
||||
LOGGER.log(System.Logger.Level.INFO, "Server : SelectPieceState: PieceState: end:" + piece.getState());
|
||||
logic.getServerSender().broadcast(new MoveMessage(piece, homeMove, targIdx));
|
||||
|
||||
if (targetNode.isBonus()) {
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if (p.getColor() == logic.getGame().getActiveColor()) {
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
logic.getServerSender().broadcast(new MoveMessage(movePiece, homeMove, targIdx));
|
||||
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.game.card.HiddenCard;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.server.DrawCardMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
@@ -40,22 +41,12 @@ public void enter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
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())) {
|
||||
int targetIndex = calculateTargetIndex(piece);
|
||||
Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex];
|
||||
|
||||
if(targetNode.isBonus()) {
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if(p.getColor() == logic.getGame().getActiveColor()) {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(logic.getGame().draw()));
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//send MoveMessage
|
||||
logic.getServerSender().broadcast(new MoveMessage(piece, false, targetIndex));
|
||||
|
||||
@@ -63,13 +54,26 @@ public void received(RequestMoveMessage msg, int from){
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
|
||||
Piece occ = targetNode.getOccupant();
|
||||
if (occ != null){
|
||||
if (occ != null) {
|
||||
//move occ to waiting
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
}
|
||||
//move piece to targetNode
|
||||
targetNode.setOccupant(piece);
|
||||
|
||||
if (targetNode.isBonus()) {
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if (p.getColor() == logic.getGame().getActiveColor()) {
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package pp.mdga.server.automaton.game.turn.powercard;
|
||||
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.card.HiddenCard;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.game.card.ShieldCard;
|
||||
import pp.mdga.game.card.SwapCard;
|
||||
import pp.mdga.game.card.TurboCard;
|
||||
@@ -12,6 +14,8 @@
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
import pp.mdga.visitor.Visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChoosePowerCardState extends PowerCardAutomatonState implements Visitor {
|
||||
|
||||
private static final System.Logger LOGGER = System.getLogger(ChoosePowerCardState.class.getName());
|
||||
@@ -44,7 +48,10 @@ public void exit() {
|
||||
|
||||
@Override
|
||||
public void received(SelectCardMessage msg, int from) {
|
||||
if (this.powerCardAutomaton.getVisitor().getCards().contains(msg.getCard())) {
|
||||
BonusCard receivedCard = msg.getCard().getCard();
|
||||
List<BonusCard> acceptedCards = powerCardAutomaton.getVisitor().getCards().stream().map(PowerCard::getCard).toList();
|
||||
|
||||
if (acceptedCards.contains(receivedCard)) {
|
||||
this.powerCardAutomaton.setSelectedCard(msg.getCard());
|
||||
msg.getCard().accept(this);
|
||||
} else {
|
||||
|
||||
@@ -22,6 +22,7 @@ public class FirstRollState extends RollDiceAutomatonState {
|
||||
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
|
||||
private List<Piece> moveablePieces;
|
||||
private int roll;
|
||||
private boolean isDied = false;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -37,6 +38,7 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
|
||||
roll = 0;
|
||||
isDied = false;
|
||||
moveablePieces = new ArrayList<>();
|
||||
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
||||
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
|
||||
@@ -62,14 +64,16 @@ public void received(RequestDieMessage msg, int from) {
|
||||
roll = this.logic.getGame().getDie().shuffle();
|
||||
this.logic.getGame().setDiceEyes(roll);
|
||||
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||
isDied = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
if (from != this.logic.getGame().getActivePlayerId()) {
|
||||
return;
|
||||
}
|
||||
if (!moveablePieces.isEmpty()) {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage from wrong player.");
|
||||
} else if (!isDied){
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage without the active player rolling a die.");
|
||||
} else if (!moveablePieces.isEmpty()) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
|
||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
|
||||
@@ -41,7 +41,13 @@ public ServerCardVisitor(ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void visit(TurboCard card) {
|
||||
this.cards.add(card);
|
||||
for (Piece piece : this.logic.getGame().getActivePlayer().getPieces()) {
|
||||
if (piece.getState() == PieceState.ACTIVE) {
|
||||
if (!this.cards.stream().map(PowerCard::getCard).toList().contains(card.getCard())) {
|
||||
this.cards.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +58,7 @@ public void visit(TurboCard card) {
|
||||
@Override
|
||||
public void visit(SwapCard card) {
|
||||
List<Piece> possibleOwnPieces = new ArrayList<>();
|
||||
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
||||
for (Piece piece : this.logic.getGame().getActivePlayer().getPieces()) {
|
||||
if (piece.getState() == PieceState.ACTIVE) {
|
||||
if (!possibleOwnPieces.contains(piece)) {
|
||||
possibleOwnPieces.add(piece);
|
||||
@@ -62,7 +68,7 @@ public void visit(SwapCard card) {
|
||||
|
||||
List<Piece> possibleOtherPieces = new ArrayList<>();
|
||||
for (var player : this.logic.getGame().getPlayers().values()) {
|
||||
if (player != this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor())) {
|
||||
if (player != this.logic.getGame().getActivePlayer()) {
|
||||
for (Piece piece : player.getPieces()) {
|
||||
if (piece.getState() == PieceState.ACTIVE) {
|
||||
if (!possibleOtherPieces.contains(piece)) {
|
||||
@@ -76,7 +82,9 @@ public void visit(SwapCard card) {
|
||||
if (!possibleOtherPieces.isEmpty() && !possibleOwnPieces.isEmpty()) {
|
||||
this.swapOwnPieces.addAll(possibleOwnPieces);
|
||||
this.swapOtherPieces.addAll(possibleOtherPieces);
|
||||
this.cards.add(card);
|
||||
if (!this.cards.stream().map(PowerCard::getCard).toList().contains(card.getCard())) {
|
||||
this.cards.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +100,7 @@ public void visit(ShieldCard card) {
|
||||
if (!this.shieldPieces.contains(piece)) {
|
||||
this.shieldPieces.add(piece);
|
||||
}
|
||||
if (!this.cards.contains(card)) {
|
||||
if (!this.cards.stream().map(PowerCard::getCard).toList().contains(card.getCard())) {
|
||||
this.cards.add(card);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ lobby.deny.join=The lobby is already full.
|
||||
server.shutdown=The server has shut down.
|
||||
incorrect.request.0=The selected TSK is already occupied.
|
||||
incorrect.request.1=No TSK is available for selection.
|
||||
incorrect.request.2=Test
|
||||
incorrect.request.3=Test
|
||||
incorrect.request.4=Test
|
||||
incorrect.request.5=Test
|
||||
incorrect.request.2=Chosen PowerCard cannot be played.
|
||||
incorrect.request.3=Selected to many or wrong pieces.
|
||||
incorrect.request.4=Did not select exactly 2 pieces or selected wrong pieces.
|
||||
incorrect.request.5=Cannot start game because not everyone is ready.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ lobby.deny.join=Die Lobby ist bereits voll.
|
||||
server.shutdown=Der Server wurde heruntergefahren.
|
||||
incorrect.request.0=Die ausgewählte TSK ist bereits belegt.
|
||||
incorrect.request.1=Es gibt keine freie TSK mehr, welche ausgewählt werden kann.
|
||||
incorrect.request.2=Test
|
||||
incorrect.request.3=Test
|
||||
incorrect.request.4=Test
|
||||
incorrect.request.5=Test
|
||||
incorrect.request.2=Die ausgewälte Powerkarte kann nicht eingesetzt werden.
|
||||
incorrect.request.3=Du hast zuviele, oder eine falsche Figur ausgewählt.
|
||||
incorrect.request.4=Du hast nicht genau zwei Figuren, oder falsche Figuren ausgewählt.
|
||||
incorrect.request.5=Du kannst das Spiel nicht starten, da nicht alle Spieler bereit sind.
|
||||
|
||||
Reference in New Issue
Block a user