removed unused imports and reformatted the code for code style

This commit is contained in:
Daniel Grigencha
2024-12-11 05:34:34 +01:00
parent d8816be811
commit aa44b84648
155 changed files with 1662 additions and 3882 deletions

View File

@@ -15,7 +15,7 @@ public class CeremonyState extends ClientState {
* Creates a new CeremonyState
*
* @param parent the parent state
* @param logic the game logic
* @param logic the game logic
*/
public CeremonyState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -42,8 +42,8 @@ public void exit() {
*
* @param state the state to be set
*/
public void setState(CeremonyStates state){
if(this.currentState != null){
public void setState(CeremonyStates state) {
if (this.currentState != null) {
this.currentState.exit();
}
state.enter();
@@ -55,7 +55,7 @@ public void setState(CeremonyStates state){
*
* @return the PodiumState
*/
public PodiumState getPodiumState(){
public PodiumState getPodiumState() {
return podiumState;
}
@@ -64,7 +64,7 @@ public PodiumState getPodiumState(){
*
* @return the StatisticsState
*/
public StatisticsState getStatisticsState(){
public StatisticsState getStatisticsState() {
return statisticsState;
}
@@ -73,16 +73,15 @@ public StatisticsState getStatisticsState(){
*
* @return the current State
*/
public CeremonyStates getState(){
public CeremonyStates getState() {
return currentState;
}
/**
* this method is used to parse the selectNext from the clientGameLogic
*
*/
@Override
public void selectNext(){
public void selectNext() {
currentState.selectNext();
}
}

View File

@@ -4,7 +4,6 @@
import pp.mdga.game.Color;
import pp.mdga.game.Piece;
import pp.mdga.message.server.*;
import pp.mdga.notification.CeremonyNotification;
import java.lang.System.Logger.Level;
@@ -15,7 +14,7 @@ public abstract class ClientState implements Observer, ServerInterpreter {
protected ClientGameLogic logic;
protected ClientState(ClientState parent, ClientGameLogic logic){
protected ClientState(ClientState parent, ClientGameLogic logic) {
this.parent = parent;
this.logic = logic;
}
@@ -24,14 +23,14 @@ protected ClientState(ClientState parent, ClientGameLogic logic){
public abstract void exit();
public ClientState getParent(){
public ClientState getParent() {
return parent;
}
public void update() {/* do nothing */}
@Override
public String toString(){
public String toString() {
return getClass().getSimpleName();
}
@@ -101,7 +100,7 @@ public void received(ChoosePieceStateMessage msg) {
}
@Override
public void received(DrawCardMessage msg){
public void received(DrawCardMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
@@ -161,7 +160,9 @@ public void received(ServerStartGameMessage msg) {
}
@Override
public void received(ShutdownMessage msg) {LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());}
public void received(ShutdownMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
@Override
public void received(StartPieceMessage msg) {
@@ -195,7 +196,7 @@ public void received(WaitPieceMessage msg) {
@Override
public void received(IncorrectRequestMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
public void selectPiece(Piece piece) {
@@ -238,23 +239,23 @@ public void deselectTSK(Color color) {
LOGGER.log(Level.DEBUG, "Deselecting TSK not allowed.");
}
public void selectUnready(){
public void selectUnready() {
LOGGER.log(Level.DEBUG, "Selecting unready not allowed.");
}
public void selectStart(){
public void selectStart() {
LOGGER.log(Level.DEBUG, "Starting not allowed");
}
public void selectAnimationEnd(){
public void selectAnimationEnd() {
LOGGER.log(Level.DEBUG, "Animation end not allowed");
}
public void selectNext(){
public void selectNext() {
LOGGER.log(Level.DEBUG, "Next not allowed");
}
public void selectResume(){
public void selectResume() {
LOGGER.log(Level.DEBUG, "Resume not allowed");
}
}

View File

@@ -19,7 +19,7 @@ public class DialogsState extends ClientState {
* Creates a new DialogsState
*
* @param parent the parent state
* @param logic the game logic
* @param logic the game logic
*/
public DialogsState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -29,7 +29,7 @@ public DialogsState(ClientState parent, ClientGameLogic logic) {
* exits this state
*/
@Override
public void exit(){
public void exit() {
currentState.exit();
}
@@ -37,7 +37,7 @@ public void exit(){
* Enters the new state machine
*/
@Override
public void enter(){
public void enter() {
setState(startDialogState);
}
@@ -46,8 +46,8 @@ public void enter(){
*
* @param newState the state to be set
*/
public void setState(DialogStates newState){
if(currentState != null){
public void setState(DialogStates newState) {
if (currentState != null) {
currentState.exit();
}
newState.enter();
@@ -85,7 +85,7 @@ public StartDialogState getStartDialog() {
* This method is used to call the selectLeave method of the current state
*/
@Override
public void selectLeave(){
public void selectLeave() {
currentState.selectLeave();
}
@@ -95,7 +95,7 @@ public void selectLeave(){
* @param name the name to be set
*/
@Override
public void setName(String name){
public void setName(String name) {
currentState.setName(name);
}
@@ -105,7 +105,7 @@ public void setName(String name){
* @param color the color to be set
*/
@Override
public void selectTSK(Color color){
public void selectTSK(Color color) {
currentState.selectTSK(color);
}
@@ -115,7 +115,7 @@ public void selectTSK(Color color){
* @param color the color to be deselected
*/
@Override
public void deselectTSK(Color color){
public void deselectTSK(Color color) {
currentState.deselectTSK(color);
}
@@ -123,7 +123,7 @@ public void deselectTSK(Color color){
* This method is used to call the selectReady method of the current state
*/
@Override
public void selectReady(){
public void selectReady() {
currentState.selectReady();
}
@@ -131,7 +131,7 @@ public void selectReady(){
* This method is used to call the selectUnready method of the current state
*/
@Override
public void selectUnready(){
public void selectUnready() {
currentState.selectUnready();
}
@@ -139,7 +139,7 @@ public void selectUnready(){
* This method is used to call the selectStart method of the current state
*/
@Override
public void selectStart(){
public void selectStart() {
currentState.selectStart();
}
@@ -149,7 +149,7 @@ public void selectStart(){
* @param string the string to be set
*/
@Override
public void selectJoin(String string){
public void selectJoin(String string) {
currentState.selectJoin(string);
}
@@ -159,7 +159,7 @@ public void selectJoin(String string){
* @param name the name to be set
*/
@Override
public void selectHost(String name){
public void selectHost(String name) {
currentState.selectHost(name);
}
@@ -169,7 +169,7 @@ public void selectHost(String name){
* @param msg the LobbyPlayerJoin message received
*/
@Override
public void received(LobbyPlayerJoinedMessage msg){
public void received(LobbyPlayerJoinedMessage msg) {
currentState.received(msg);
}
@@ -179,7 +179,7 @@ public void received(LobbyPlayerJoinedMessage msg){
* @param msg the LobbyPlayerLeave message received
*/
@Override
public void received(LobbyPlayerLeaveMessage msg){
public void received(LobbyPlayerLeaveMessage msg) {
currentState.received(msg);
}
@@ -189,7 +189,7 @@ public void received(LobbyPlayerLeaveMessage msg){
* @param msg the UpdateTSKMessage message received
*/
@Override
public void received(UpdateTSKMessage msg){
public void received(UpdateTSKMessage msg) {
currentState.received(msg);
}
@@ -199,7 +199,7 @@ public void received(UpdateTSKMessage msg){
* @param msg the UpdateReady message received
*/
@Override
public void received(UpdateReadyMessage msg){
public void received(UpdateReadyMessage msg) {
currentState.received(msg);
}
@@ -209,7 +209,7 @@ public void received(UpdateReadyMessage msg){
* @param msg the ServerStartGame message received
*/
@Override
public void received(ServerStartGameMessage msg){
public void received(ServerStartGameMessage msg) {
currentState.received(msg);
}
@@ -219,7 +219,7 @@ public void received(ServerStartGameMessage msg){
* @param msg the LobbyAccept message received
*/
@Override
public void received(LobbyAcceptMessage msg){
public void received(LobbyAcceptMessage msg) {
currentState.received(msg);
}
@@ -229,7 +229,7 @@ public void received(LobbyAcceptMessage msg){
* @param msg the LobbyDeny message received
*/
@Override
public void received(LobbyDenyMessage msg){
public void received(LobbyDenyMessage msg) {
currentState.received(msg);
}

View File

@@ -4,16 +4,9 @@
import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.game.card.ShieldCard;
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.server.*;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.CeremonyNotification;
import pp.mdga.notification.DrawCardNotification;
import pp.mdga.notification.InterruptNotification;
import pp.mdga.notification.StartDialogNotification;
import pp.mdga.notification.*;
public class GameState extends ClientState {
@@ -32,7 +25,7 @@ public class GameState extends ClientState {
* Constructor for GameState
*
* @param parent the parent of this state
* @param logic the ClientGameLogic
* @param logic the ClientGameLogic
*/
public GameState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -59,8 +52,8 @@ public void exit() {
*
* @param newState the state to be set
*/
public void setState(GameStates newState){
if(this.state != null){
public void setState(GameStates newState) {
if (this.state != null) {
this.state.exit();
}
System.out.println("CLIENT STATE old: " + this.state + " new: " + newState);
@@ -72,7 +65,7 @@ public void setState(GameStates newState){
* This method is used to call the selectAnimationEnd method of the current state
*/
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
state.selectAnimationEnd();
}
@@ -80,7 +73,7 @@ public void selectAnimationEnd(){
* This method is used to call the selectDice method of the current state
*/
@Override
public void selectDice(){
public void selectDice() {
state.selectDice();
}
@@ -90,7 +83,7 @@ public void selectDice(){
* @param piece the piece to be selected
*/
@Override
public void selectPiece(Piece piece){
public void selectPiece(Piece piece) {
state.selectPiece(piece);
}
@@ -100,7 +93,7 @@ public void selectPiece(Piece piece){
* @param card the card to be selected
*/
@Override
public void selectCard(BonusCard card){
public void selectCard(BonusCard card) {
state.selectCard(card);
}
@@ -110,13 +103,13 @@ public void selectCard(BonusCard card){
* @param msg the message to be received
*/
@Override
public void received(PauseGameMessage msg){
public void received(PauseGameMessage msg) {
logic.enterInterrupt();
logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor()));
}
@Override
public void selectLeave(){
public void selectLeave() {
logic.send(new LeaveGameMessage());
logic.addNotification(new StartDialogNotification());
logic.setState(logic.getDialogs());
@@ -128,7 +121,7 @@ public void selectLeave(){
* @param msg the message to be received
*/
@Override
public void received(DieMessage msg){
public void received(DieMessage msg) {
state.received(msg);
}
@@ -138,7 +131,7 @@ public void received(DieMessage msg){
* @param msg the message to be received
*/
@Override
public void received(RankingRollAgainMessage msg){
public void received(RankingRollAgainMessage msg) {
state.received(msg);
}
@@ -148,7 +141,7 @@ public void received(RankingRollAgainMessage msg){
* @param msg the message to be received
*/
@Override
public void received(RankingResponseMessage msg){
public void received(RankingResponseMessage msg) {
state.received(msg);
}
@@ -158,7 +151,7 @@ public void received(RankingResponseMessage msg){
* @param msg the message to be received
*/
@Override
public void received(SelectPieceMessage msg){
public void received(SelectPieceMessage msg) {
state.received(msg);
}
@@ -168,7 +161,7 @@ public void received(SelectPieceMessage msg){
* @param msg the message to be received
*/
@Override
public void received(WaitPieceMessage msg){
public void received(WaitPieceMessage msg) {
state.received(msg);
}
@@ -178,7 +171,7 @@ public void received(WaitPieceMessage msg){
* @param msg the message to be received
*/
@Override
public void received(StartPieceMessage msg){
public void received(StartPieceMessage msg) {
state.received(msg);
}
@@ -188,7 +181,7 @@ public void received(StartPieceMessage msg){
* @param msg the message to be received
*/
@Override
public void received(NoTurnMessage msg){
public void received(NoTurnMessage msg) {
state.received(msg);
}
@@ -198,7 +191,7 @@ public void received(NoTurnMessage msg){
* @param msg the message to be received
*/
@Override
public void received(MoveMessage msg){
public void received(MoveMessage msg) {
state.received(msg);
}
@@ -208,7 +201,7 @@ public void received(MoveMessage msg){
* @param msg the message to be received
*/
@Override
public void received(CeremonyMessage msg){
public void received(CeremonyMessage msg) {
CeremonyNotification notification = new CeremonyNotification();
notification.setColors(msg.getColors());
notification.setNames(msg.getNames());
@@ -228,7 +221,7 @@ public void received(CeremonyMessage msg){
* @param msg the message to be received
*/
@Override
public void received(EndOfTurnMessage msg){
public void received(EndOfTurnMessage msg) {
state.received(msg);
}
@@ -238,7 +231,7 @@ public void received(EndOfTurnMessage msg){
* @param msg the message to be received
*/
@Override
public void received(SpectatorMessage msg){
public void received(SpectatorMessage msg) {
state.received(msg);
}
@@ -248,7 +241,7 @@ public void received(SpectatorMessage msg){
* @param msg the message to be received
*/
@Override
public void received(DiceAgainMessage msg){
public void received(DiceAgainMessage msg) {
state.received(msg);
}
@@ -258,7 +251,7 @@ public void received(DiceAgainMessage msg){
* @param msg the message to be received
*/
@Override
public void received(PossibleCardsMessage msg){
public void received(PossibleCardsMessage msg) {
state.received(msg);
}
@@ -268,7 +261,7 @@ public void received(PossibleCardsMessage msg){
* @param msg the message to be received
*/
@Override
public void received(PlayCardMessage msg){
public void received(PlayCardMessage msg) {
state.received(msg);
}
@@ -278,7 +271,7 @@ public void received(PlayCardMessage msg){
* @param msg the message to be received
*/
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
state.received(msg);
}
@@ -288,27 +281,26 @@ public void received(DiceNowMessage msg){
* @param msg the message to be received
*/
@Override
public void received(ActivePlayerMessage msg){
public void received(ActivePlayerMessage msg) {
state.received(msg);
}
@Override
public void received(PossiblePieceMessage msg){
public void received(PossiblePieceMessage msg) {
state.received(msg);
}
@Override
public void received(ChoosePieceStateMessage msg){
public void received(ChoosePieceStateMessage msg) {
state.received(msg);
}
@Override
public void received(DrawCardMessage msg){
public void received(DrawCardMessage msg) {
logic.getGame().getActivePlayer().addHandCard(msg.getCard());
if (msg.getCard() instanceof HiddenCard) {
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
}
else{
} else {
logic.addNotification(new AcquireCardNotification(msg.getCard().getCard()));
}
@@ -319,7 +311,7 @@ public void received(DrawCardMessage msg){
*
* @return the current state
*/
public GameStates getState(){
public GameStates getState() {
return state;
}

View File

@@ -2,7 +2,6 @@
import pp.mdga.message.client.ForceContinueGameMessage;
import pp.mdga.message.server.ResumeGameMessage;
import pp.mdga.notification.ResumeNotification;
public class InterruptState extends ClientState {
@@ -12,7 +11,7 @@ public class InterruptState extends ClientState {
* Creates a new InterruptState
*
* @param parent the parent state
* @param logic the game logic
* @param logic the game logic
*/
public InterruptState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -56,8 +55,8 @@ public ClientState getPreviousState() {
* The host resumes the game
*/
@Override
public void selectResume(){
if(logic.isHost()){
public void selectResume() {
if (logic.isHost()) {
logic.send(new ForceContinueGameMessage());
}
}

View File

@@ -20,7 +20,7 @@ public class SettingsState extends ClientState {
* Creates a new SettingsState
*
* @param parent the parent state
* @param logic the game logic
* @param logic the game logic
*/
public SettingsState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -45,28 +45,28 @@ public void exit() {
/**
* Changes the current state
*/
public SettingStates getState(){
public SettingStates getState() {
return currentState;
}
/**
* Returns the main settings state
*/
public MainSettingsState getMainSettingsState(){
public MainSettingsState getMainSettingsState() {
return mainSettingsState;
}
/**
* Returns the audio settings state
*/
public AudioSettingsState getAudioSettingsState(){
public AudioSettingsState getAudioSettingsState() {
return audioSettingsState;
}
/**
* Returns the video settings state
*/
public VideoSettingsState getVideoSettingsState(){
public VideoSettingsState getVideoSettingsState() {
return videoSettingsState;
}
}

View File

@@ -24,7 +24,7 @@ public void exit() {
}
@Override
public void selectNext(){
public void selectNext() {
parent.setState(parent.getStatisticsState());
}
}

View File

@@ -19,7 +19,7 @@ public void exit() {
}
@Override
public void selectNext(){
public void selectNext() {
logic.setState(logic.getDialogs());
}
}

View File

@@ -5,7 +5,7 @@
public abstract class DialogStates extends ClientState {
public DialogStates(ClientState parent, ClientGameLogic logic){
public DialogStates(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
}
}

View File

@@ -72,8 +72,8 @@ public void selectStart() {
@Override
public void received(ServerStartGameMessage msg) {
for (Player player: msg.getPlayers()) {
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
for (Player player : msg.getPlayers()) {
for (Map.Entry<Integer, Player> entry : this.logic.getGame().getPlayers().entrySet()) {
if (entry.getValue().getColor() == player.getColor()) {
this.logic.getGame().getPlayers().put(entry.getKey(), player);
}

View File

@@ -15,8 +15,9 @@ public class NetworkDialogState extends DialogStates {
/**
* Constructor for the NetworkDialogState
*
* @param parent the parent state
* @param logic the logic
* @param logic the logic
*/
public NetworkDialogState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);

View File

@@ -10,8 +10,9 @@ public class StartDialogState extends DialogStates {
/**
* Constructor for the StartDialogState
*
* @param parent the parent state
* @param logic the logic
* @param logic the logic
*/
public StartDialogState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);

View File

@@ -26,7 +26,7 @@ public void exit() {
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
logic.send(new AnimationEndMessage());
parent.setState(parent.getWaiting());
}

View File

@@ -7,7 +7,6 @@
import pp.mdga.client.gamestate.determinestartplayerstate.Intro;
import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState;
import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.*;
public class DetermineStartPlayerState extends GameStates {
@@ -32,11 +31,11 @@ public WaitRankingState getWaitRanking() {
return waitRankingState;
}
public DetermineStartPlayerStates getState(){
public DetermineStartPlayerStates getState() {
return state;
}
public Intro getIntro(){
public Intro getIntro() {
return intro;
}
@@ -56,7 +55,7 @@ public void exit() {
public void setState(DetermineStartPlayerStates state) {
System.out.println("CLIENT STATE old: " + this.state + " new: " + state);
if(this.state != null){
if (this.state != null) {
this.state.exit();
}
this.state = state;
@@ -69,32 +68,32 @@ public void selectDice() {
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
state.selectAnimationEnd();
}
@Override
public void received(DieMessage msg){
public void received(DieMessage msg) {
state.received(msg);
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
state.received(msg);
}
@Override
public void received(RankingRollAgainMessage msg){
public void received(RankingRollAgainMessage msg) {
state.received(msg);
}
@Override
public void received(RankingResponseMessage msg){
public void received(RankingResponseMessage msg) {
state.received(msg);
}
@Override
public void received(ActivePlayerMessage msg){
public void received(ActivePlayerMessage msg) {
state.received(msg);
}
}

View File

@@ -2,19 +2,12 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.game.Board;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Node;
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState;
import pp.mdga.game.*;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.ShieldActiveNotification;
import pp.mdga.notification.ShieldSuppressedNotification;
import pp.mdga.notification.SwapPieceNotification;
import pp.mdga.notification.ThrowPieceNotification;
import java.util.List;
import java.util.UUID;
public abstract class GameStates extends ClientState {
@@ -40,7 +33,7 @@ protected void handlePowerCard(PlayCardMessage msg) {
private void handleShield(UUID uuid) {
Board board = logic.getGame().getBoard();
Piece piece = logic.getGame().getPieceThroughUUID(uuid);
Node node = board.getInfield()[board.getInfieldIndexOfPiece(piece)];
Node node = board.getInfield()[board.getInfieldIndexOfPiece(piece)];
if (node.isStart()) {
logic.getGame().getPieceThroughUUID(uuid).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldActiveNotification(uuid));
@@ -68,13 +61,13 @@ private void swapPieces(Piece messageOwn, Piece messageEnemy) {
}
private void checkShieldAfterSwap(Node node, Piece piece){
if (node.isStart()){
if (piece.isShielded()){
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()){
} else if (piece.isSuppressed()) {
piece.setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
}

View File

@@ -35,7 +35,7 @@ public void received(CeremonyMessage msg) {
}
@Override
public void received(DrawCardMessage msg){
public void received(DrawCardMessage msg) {
logic.getGame().getActivePlayer().addHandCard(msg.getCard());
if (msg.getCard() instanceof HiddenCard) {
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
@@ -87,14 +87,14 @@ public void received(MoveMessage msg) {
if (occ != null) {
//TODO: MoveThrowNotification
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
if (occ.isSuppressed()){
if (occ.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(occ.getUuid()));
occ.setShield(ShieldState.NONE);
}
//set occ to waiting
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
}
if(msg.getPiece().getState().equals(PieceState.WAITING)){
if (msg.getPiece().getState().equals(PieceState.WAITING)) {
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
piece.setState(PieceState.ACTIVE);

View File

@@ -3,23 +3,12 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.GameState;
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
import pp.mdga.client.gamestate.turnstate.MovePieceState;
import pp.mdga.client.gamestate.turnstate.PlayPowerCardState;
import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.client.gamestate.turnstate.RollDiceState;
import pp.mdga.client.gamestate.turnstate.TurnStates;
import pp.mdga.client.gamestate.turnstate.*;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece;
import pp.mdga.game.ShieldState;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.game.card.ShieldCard;
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import pp.mdga.message.server.*;
import pp.mdga.notification.RemoveShieldNotification;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.DrawCardNotification;
public class TurnState extends GameStates {
@@ -42,7 +31,7 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
public void enter() {
logic = logic;
for (Piece piece : logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPieces()) {
if (piece.isShielded() || piece.isSuppressed()){
if (piece.isShielded() || piece.isSuppressed()) {
piece.setShield(ShieldState.NONE);
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
}
@@ -56,9 +45,9 @@ public void exit() {
state = null;
}
public void setState(TurnStates state){
public void setState(TurnStates state) {
System.out.println("CLIENT STATE old: " + this.state + " new: " + state);
if(this.state != null){
if (this.state != null) {
this.state.exit();
}
state.enter();
@@ -66,97 +55,97 @@ public void setState(TurnStates state){
}
@Override
public void selectDice(){
public void selectDice() {
state.selectDice();
}
@Override
public void selectPiece(Piece piece){
public void selectPiece(Piece piece) {
state.selectPiece(piece);
}
@Override
public void selectCard(BonusCard card){
public void selectCard(BonusCard card) {
state.selectCard(card);
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
state.selectAnimationEnd();
}
@Override
public void received(SelectPieceMessage msg){
public void received(SelectPieceMessage msg) {
state.received(msg);
}
@Override
public void received(WaitPieceMessage msg){
public void received(WaitPieceMessage msg) {
state.received(msg);
}
@Override
public void received(StartPieceMessage msg){
public void received(StartPieceMessage msg) {
state.received(msg);
}
@Override
public void received(NoTurnMessage msg){
public void received(NoTurnMessage msg) {
state.received(msg);
}
@Override
public void received(MoveMessage msg){
public void received(MoveMessage msg) {
state.received(msg);
}
@Override
public void received(CeremonyMessage msg){
public void received(CeremonyMessage msg) {
state.received(msg);
}
@Override
public void received(EndOfTurnMessage msg){
public void received(EndOfTurnMessage msg) {
state.received(msg);
}
@Override
public void received(SpectatorMessage msg){
public void received(SpectatorMessage msg) {
state.received(msg);
}
@Override
public void received(DiceAgainMessage msg){
public void received(DiceAgainMessage msg) {
state.received(msg);
}
@Override
public void received(PossibleCardsMessage msg){
public void received(PossibleCardsMessage msg) {
state.received(msg);
}
@Override
public void received(PlayCardMessage msg){
public void received(PlayCardMessage msg) {
state.received(msg);
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
state.received(msg);
}
@Override
public void received(DieMessage msg){
public void received(DieMessage msg) {
state.received(msg);
}
@Override
public void received(PossiblePieceMessage msg){
public void received(PossiblePieceMessage msg) {
state.received(msg);
}
@Override
public void received(ChoosePieceStateMessage msg){
public void received(ChoosePieceStateMessage msg) {
state.received(msg);
}
@@ -180,11 +169,11 @@ public RollDiceState getRollDice() {
return rollDiceState;
}
public GameState getParent(){
public GameState getParent() {
return parent;
}
public TurnStates getState(){
public TurnStates getState() {
return state;
}

View File

@@ -38,10 +38,9 @@ public void received(CeremonyMessage msg) {
@Override
public void received(DieMessage msg) {
logic.getGame().setDiceEyes(msg.getDiceEye());
if(logic.getGame().getTurboFlag()){
if (logic.getGame().getTurboFlag()) {
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
}
else {
} else {
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
}
@@ -65,11 +64,11 @@ public void received(PlayCardMessage msg) {
public void received(ActivePlayerMessage msg) {
logic.addNotification(new ActivePlayerNotification(msg.getColor()));
logic.getGame().setActiveColor(msg.getColor());
if(msg.getColor() == logic.getGame().getPlayers().get(logic.getOwnPlayerId()).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()){
for (Piece piece : logic.getGame().getActivePlayer().getPieces()) {
if (piece.isShielded() || piece.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
piece.setShield(ShieldState.NONE);
}
@@ -81,7 +80,7 @@ public void received(ActivePlayerMessage msg) {
public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
if (msg.isHomeMove()) {
if(piece.getState().equals(PieceState.HOME)){
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];
@@ -91,18 +90,16 @@ public void received(MoveMessage msg) {
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()) {
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else{
} else {
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
}
else{
} else {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
@@ -110,31 +107,29 @@ public void received(MoveMessage msg) {
//gets the targetNode
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
if (msg.getTargetIndex() ==logic.getGame().getActivePlayer().getHighestHomeIdx()) {
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else{
} else {
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
}
}
else {
} else {
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
if (occ != null) {
//TODO: MoveThrowNotification
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
if (occ.isSuppressed()){
if (occ.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(occ.getUuid()));
occ.setShield(ShieldState.NONE);
}
//set occ to waiting
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
}
if(oldIndex == -1){
if (oldIndex == -1) {
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
piece.setState(PieceState.ACTIVE);
@@ -145,12 +140,12 @@ 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()){
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()){
} else if (piece.isSuppressed()) {
piece.setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
}

View File

@@ -13,7 +13,7 @@
import java.util.Map;
public class Intro extends DetermineStartPlayerStates{
public class Intro extends DetermineStartPlayerStates {
private final DetermineStartPlayerState parent;
@@ -23,7 +23,7 @@ public class Intro extends DetermineStartPlayerStates{
* Constructor for Intro
*
* @param parent the parent state
* @param logic the client game logic
* @param logic the client game logic
*/
public Intro(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -35,7 +35,7 @@ public Intro(ClientState parent, ClientGameLogic logic) {
*
* @return the parent state
*/
public DetermineStartPlayerState getParent(){
public DetermineStartPlayerState getParent() {
return parent;
}
@@ -44,13 +44,13 @@ public DetermineStartPlayerState getParent(){
*/
@Override
public void enter() {
for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
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++;
for (PowerCard card : entry.getValue().getHandCards()){
if(entry.getKey() == logic.getOwnPlayerId()){
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()));
@@ -71,13 +71,13 @@ public void exit() {
* This method is used when the view has completed the animation.
*/
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
animationCounter--;
if(animationCounter != 0){
if (animationCounter != 0) {
return;
}
logic.send(new AnimationEndMessage());
if (logic.getGame().getActivePlayerId() == logic.getOwnPlayerId()){
if (logic.getGame().getActivePlayerId() == logic.getOwnPlayerId()) {
parent.getParent().setState(parent.getParent().getTurn());
logic.addNotification(new ActivePlayerNotification(logic.getGame().getActiveColor()));
} else {

View File

@@ -13,7 +13,7 @@ public class RollRankingDiceState extends DetermineStartPlayerStates {
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
private final DetermineStartPlayerState parent;
private boolean isRolled =false;
private boolean isRolled = false;
public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -29,20 +29,20 @@ public void enter() {
@Override
public void exit() {
LOGGER.log(System.Logger.Level.INFO, "Exiting RollRankingDiceState");
isRolled=false;
isRolled = false;
}
@Override
public void selectDice(){
if(!isRolled){
public void selectDice() {
if (!isRolled) {
isRolled = true;
logic.send(new RequestDieMessage());
}
}
@Override
public void received(DieMessage msg){
public void received(DieMessage msg) {
parent.setState(parent.getWaitRanking());
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(), true));
}
}

View File

@@ -5,8 +5,9 @@
import pp.mdga.client.gamestate.DetermineStartPlayerState;
import pp.mdga.game.Color;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.*;
import pp.mdga.notification.ActivePlayerNotification;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.RankingResponseMessage;
import pp.mdga.notification.RankingResponceNotification;
import java.util.HashMap;
@@ -24,8 +25,8 @@ public WaitRankingState(ClientState parent, ClientGameLogic logic) {
this.parent = (DetermineStartPlayerState) parent;
}
private void changeToIntro(){
if(!canChange){
private void changeToIntro() {
if (!canChange) {
canChange = true;
return;
}
@@ -44,12 +45,12 @@ public void exit() {
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
parent.setState(parent.getRollRankingDice());
}
@Override
public void received(RankingResponseMessage msg){
public void received(RankingResponseMessage msg) {
Map<Color, Integer> rankingResults = new HashMap<>();
for (var entry : msg.getRankingResults().entrySet()) {
rankingResults.put(logic.getGame().getPlayerById(entry.getKey()).getColor(), entry.getValue());
@@ -58,13 +59,13 @@ public void received(RankingResponseMessage msg){
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
changeToIntro();
logic.send(new AnimationEndMessage());
}
@Override
public void received(ActivePlayerMessage msg){
public void received(ActivePlayerMessage msg) {
logic.getGame().setActiveColor(msg.getColor());
changeToIntro();
}

View File

@@ -30,12 +30,12 @@ public void enter() {
@Override
public void exit() {
currentState.exit();
currentState= null;
currentState = null;
}
public void setState(ChoosePieceStates state){
public void setState(ChoosePieceStates state) {
System.out.println("CLIENT STATE old: " + this.currentState + " new: " + state);
if(currentState != null){
if (currentState != null) {
currentState.exit();
}
state.enter();
@@ -43,56 +43,56 @@ public void setState(ChoosePieceStates state){
}
@Override
public void selectPiece(Piece piece){
public void selectPiece(Piece piece) {
currentState.selectPiece(piece);
}
@Override
public void received(SelectPieceMessage msg){
public void received(SelectPieceMessage msg) {
currentState.received(msg);
}
@Override
public void received(WaitPieceMessage msg){
public void received(WaitPieceMessage msg) {
currentState.received(msg);
}
@Override
public void received(StartPieceMessage msg){
public void received(StartPieceMessage msg) {
currentState.received(msg);
}
@Override
public void received(EndOfTurnMessage msg){
public void received(EndOfTurnMessage msg) {
currentState.received(msg);
}
@Override
public void received(MoveMessage msg){
public void received(MoveMessage msg) {
currentState.received(msg);
}
public NoPieceState getNoPiece(){
public NoPieceState getNoPiece() {
return noPieceState;
}
public SelectPieceState getSelectPiece(){
public SelectPieceState getSelectPiece() {
return selectPieceState;
}
public StartPieceState getStartPiece(){
public StartPieceState getStartPiece() {
return startPieceState;
}
public WaitingPieceState getWaitingPiece(){
public WaitingPieceState getWaitingPiece() {
return waitingPieceState;
}
public ChoosePieceStates getState(){
public ChoosePieceStates getState() {
return currentState;
}
public TurnState getParent(){
public TurnState getParent() {
return parent;
}
}

View File

@@ -4,7 +4,10 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.TurnState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.*;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.message.server.SpectatorMessage;
public class MovePieceState extends TurnStates {
@@ -26,27 +29,27 @@ public void exit() {
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
logic.send(new AnimationEndMessage());
}
@Override
public void received(CeremonyMessage msg){
public void received(CeremonyMessage msg) {
logic.setState(logic.getCeremony());
}
@Override
public void received(EndOfTurnMessage msg){
public void received(EndOfTurnMessage msg) {
parent.getParent().setState(parent.getParent().getWaiting());
}
@Override
public void received(SpectatorMessage msg){
public void received(SpectatorMessage msg) {
parent.getParent().setState(parent.getParent().getSpectator());
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
parent.setState(parent.getRollDice());
}

View File

@@ -4,8 +4,6 @@
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;
@@ -24,7 +22,7 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
if(playCardMessage.getCard().getCard().equals(BonusCard.SWAP)) {
if (playCardMessage.getCard().getCard().equals(BonusCard.SWAP)) {
extraAnimationCounter++;
}
@@ -43,8 +41,8 @@ public void setPlayCard(PlayCardMessage playCardMessage) {
}
@Override
public void selectAnimationEnd(){
if(extraAnimationCounter > 0) {
public void selectAnimationEnd() {
if (extraAnimationCounter > 0) {
extraAnimationCounter--;
return;
}

View File

@@ -42,7 +42,7 @@ public void exit() {
public void setState(PowerCardStates state) {
System.out.println("CLIENT STATE old: " + this.state + " new: " + state);
if(this.state != null){
if (this.state != null) {
this.state.exit();
}
state.enter();
@@ -50,22 +50,22 @@ public void setState(PowerCardStates state) {
}
@Override
public void received(PossibleCardsMessage msg){
public void received(PossibleCardsMessage msg) {
state.received(msg);
}
@Override
public void received(PlayCardMessage msg){
public void received(PlayCardMessage msg) {
state.received(msg);
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
state.received(msg);
}
@Override
public void received(PossiblePieceMessage msg){
public void received(PossiblePieceMessage msg) {
state.received(msg);
}

View File

@@ -39,43 +39,42 @@ public TurnState getParent() {
}
@Override
public void selectDice(){
if (!isRolled){
public void selectDice() {
if (!isRolled) {
isRolled = true;
logic.send(new RequestDieMessage());
}
}
@Override
public void received(DieMessage msg){
public void received(DieMessage msg) {
logic.getGame().setDiceEyes(msg.getDiceEye());
if(logic.getGame().getTurboFlag()){
if (logic.getGame().getTurboFlag()) {
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
}
else {
} else {
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye()));
}
}
@Override
public void selectAnimationEnd(){
public void selectAnimationEnd() {
logic.send(new AnimationEndMessage());
}
@Override
public void received(ChoosePieceStateMessage msg){
public void received(ChoosePieceStateMessage msg) {
parent.setState(parent.getChoosePiece());
}
@Override
public void received(NoTurnMessage msg){
public void received(NoTurnMessage msg) {
parent.getParent().setState(parent.getParent().getWaiting());
}
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
isRolled = false;
logic.addNotification(new DiceNowNotification());
}

View File

@@ -4,7 +4,7 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.GameStates;
public abstract class TurnStates extends GameStates {
public abstract class TurnStates extends GameStates {
public TurnStates(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
}

View File

@@ -4,11 +4,11 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
import pp.mdga.game.Piece;
import pp.mdga.message.server.*;
import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.message.server.SelectPieceMessage;
import pp.mdga.message.server.StartPieceMessage;
import pp.mdga.notification.MovePieceNotification;
import pp.mdga.message.server.WaitPieceMessage;
import pp.mdga.notification.SelectableMoveNotification;
import pp.mdga.notification.WaitMoveNotification;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +47,7 @@ public void received(SelectPieceMessage msg) {
}
@Override
public void received(WaitPieceMessage msg){
public void received(WaitPieceMessage msg) {
LOGGER.log(System.Logger.Level.INFO, "Received WaitPieceMessage");
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPieceID());
logic.addNotification(new SelectableMoveNotification(new ArrayList<>(List.of(msg.getPieceID())), new ArrayList<>(List.of(logic.getGame().getPlayerByColor(piece.getColor()).getStartNodeIndex())), new ArrayList<>(List.of(false))));
@@ -55,7 +55,7 @@ public void received(WaitPieceMessage msg){
}
@Override
public void received(StartPieceMessage msg){
public void received(StartPieceMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier());
List<UUID> listPiece = new ArrayList<>();
List<Integer> listIndex = new ArrayList<>();
@@ -70,7 +70,7 @@ public void received(StartPieceMessage msg){
}
@Override
public void received(EndOfTurnMessage msg){
public void received(EndOfTurnMessage msg) {
logic.getGame().setTurboFlag(false);
parent.getParent().getParent().setState(parent.getParent().getParent().getWaiting());
}

View File

@@ -4,17 +4,11 @@
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.game.ShieldState;
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.RemoveShieldNotification;
import pp.mdga.notification.ShieldActiveNotification;
import pp.mdga.notification.ShieldSuppressedNotification;
import pp.mdga.notification.ThrowPieceNotification;
import pp.mdga.notification.*;
import java.util.ArrayList;
@@ -63,29 +57,25 @@ public void received(MoveMessage msg) {
System.out.println("Client: SelectState: activePiece in Home: infieldIndex" + infieldIndex);
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else {
} else {
piece.setState(PieceState.HOME);
}
logic.getGame().getBoard().getInfield()[infieldIndex].clearOccupant();
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
}
else {
} 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 {
} else {
piece.setState(PieceState.HOME);
}
logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex].clearOccupant();
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
}
}
else {
} else {
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
@@ -93,7 +83,7 @@ public void received(MoveMessage msg) {
if (occ != null) {
//TODO: MoveThrowNotification
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
if (occ.isSuppressed()){
if (occ.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(occ.getUuid()));
occ.setShield(ShieldState.NONE);
}
@@ -111,8 +101,7 @@ public void received(MoveMessage msg) {
piece.setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
}
}
else if (piece.isSuppressed()) {
} else if (piece.isSuppressed()) {
piece.setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
}

View File

@@ -7,15 +7,8 @@
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;
import pp.mdga.notification.*;
public class StartPieceState extends ChoosePieceStates {
@@ -45,14 +38,14 @@ public void setMoveablePiece(Piece moveablePiece) {
}
@Override
public void selectPiece(Piece piece){
if(moveablePiece.equals(piece)){
public void selectPiece(Piece piece) {
if (moveablePiece.equals(piece)) {
logic.send(new RequestMoveMessage(piece));
}
}
@Override
public void received(MoveMessage msg){
public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
int targetIndex = msg.getTargetIndex();
@@ -62,21 +55,21 @@ public void received(MoveMessage msg){
//get Occupant
Piece occ = targetNode.getOccupant();
if (occ != null){
if (occ != null) {
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
if (occ.isSuppressed()){
if (occ.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(occ.getUuid()));
occ.setShield(ShieldState.NONE);
}
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
}
if (targetNode.isStart()){
if (piece.isShielded()){
if (targetNode.isStart()) {
if (piece.isShielded()) {
piece.setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
}
} else if (piece.isSuppressed()){
} else if (piece.isSuppressed()) {
piece.setShield(ShieldState.ACTIVE);
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));

View File

@@ -7,15 +7,11 @@
import pp.mdga.game.PieceState;
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.ThrowPieceNotification;
import java.util.ArrayList;
import java.util.List;
public class WaitingPieceState extends ChoosePieceStates {
private final ChoosePieceState parent;
@@ -36,17 +32,17 @@ public void exit() {
}
@Override
public void selectPiece(Piece piece){
public void selectPiece(Piece piece) {
logic.send(new RequestMoveMessage(piece));
}
@Override
public void received(MoveMessage msg){
public void received(MoveMessage msg) {
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
if (occ != null){
if (occ != null) {
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
if (occ.isSuppressed()){
if (occ.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(occ.getUuid()));
occ.setShield(ShieldState.NONE);
}

View File

@@ -4,9 +4,8 @@
import pp.mdga.client.ClientState;
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.game.card.PowerCard;
import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.server.DiceNowMessage;
@@ -14,7 +13,6 @@
import pp.mdga.message.server.PossibleCardsMessage;
import pp.mdga.message.server.PossiblePieceMessage;
import pp.mdga.notification.SelectableCardsNotification;
import pp.mdga.notification.SelectableShieldNotification;
import java.util.ArrayList;
import java.util.stream.Collectors;
@@ -29,8 +27,9 @@ public class ChoosePowerCardState extends PowerCardStates {
/**
* Constructor
*
* @param parent parent state
* @param logic game logic
* @param logic game logic
*/
public ChoosePowerCardState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -54,11 +53,12 @@ public void exit() {
/**
* Set the possible cards
*
* @param msg possible cards message
*/
@Override
public void received(PossibleCardsMessage msg){
possibleCards = (ArrayList<PowerCard>)msg.getPossibleCards();
public void received(PossibleCardsMessage msg) {
possibleCards = (ArrayList<PowerCard>) msg.getPossibleCards();
ArrayList<BonusCard> possibleBonusCards = new ArrayList<>();
for (PowerCard card : possibleCards) {
if (!possibleBonusCards.contains(card.getCard())) {
@@ -70,15 +70,16 @@ public void received(PossibleCardsMessage msg){
/**
* Select a card
*
* @param card card to select
*/
@Override
public void selectCard(BonusCard card){
public void selectCard(BonusCard card) {
Player player = logic.getGame().getPlayers().get(logic.getOwnPlayerId());
ArrayList<PowerCard> handCards = player.getHandCards();
if(card != null){
if (card != null) {
PowerCard select = player.getPowerCardByType(card);
if(select == null){
if (select == null) {
select = select;
}
logic.send(new SelectCardMessage(select));
@@ -89,11 +90,12 @@ public void selectCard(BonusCard card){
/**
* Receive a card
*
* @param msg card message
*/
@Override
public void received(PlayCardMessage msg){
if(msg.getCard().getCard().equals(BonusCard.TURBO)){
public void received(PlayCardMessage msg) {
if (msg.getCard().getCard().equals(BonusCard.TURBO)) {
logic.getGame().setDiceModifier(msg.getDiceModifier());
parent.getParent().getPlayPowerCard().setPlayCard(msg);
logic.getGame().setTurboFlag(true);
@@ -103,20 +105,22 @@ public void received(PlayCardMessage msg){
/**
* Receive a die now message
*
* @param msg dice now message
*/
@Override
public void received(DiceNowMessage msg){
public void received(DiceNowMessage msg) {
parent.getParent().setState(parent.getParent().getRollDice());
}
/**
* Receive a possible piece message and decide if the player can swap or shield
*
* @param msg possible piece message
*/
@Override
public void received(PossiblePieceMessage msg){
if (msg.getEnemyPossiblePieces().isEmpty()){
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());
} else {

View File

@@ -4,14 +4,12 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.game.Piece;
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;
import java.util.List;
public class ShieldState extends PowerCardStates {

View File

@@ -4,14 +4,12 @@
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.game.Piece;
import pp.mdga.message.client.RequestPlayCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.SelectableSwapNotification;
import java.util.UUID;
import java.util.ArrayList;
import java.util.UUID;
public class SwapState extends PowerCardStates {
@@ -59,17 +57,17 @@ public void setPossibleEnemyPieces(ArrayList<Piece> possibleEnemyPieces) {
}
@Override
public void selectPiece(Piece piece){
if (possibleOwnPieces.contains(piece)){
public void selectPiece(Piece piece) {
if (possibleOwnPieces.contains(piece)) {
selectedOwnPiece = piece;
} else if (possibleEnemyPieces.contains(piece)){
} else if (possibleEnemyPieces.contains(piece)) {
selectedEnemyPiece = piece;
}
if (selectedOwnPiece != null && selectedEnemyPiece != null){
if (selectedOwnPiece != null && selectedEnemyPiece != null) {
ArrayList<Piece> temp = new ArrayList<>();
temp.add(selectedOwnPiece);
temp.add(selectedEnemyPiece);
System.out.println("Client : Swap: temp: "+temp.get(0)+temp.get(1));
System.out.println("Client : Swap: temp: " + temp.get(0) + temp.get(1));
logic.send(new SelectedPiecesMessage(temp));
selectedEnemyPiece = null;
selectedOwnPiece = null;

View File

@@ -79,7 +79,7 @@ private StartNode createStartNode(int i) {
*/
public int getInfieldIndexOfPiece(Piece piece) {
for (int i = 0; i < infield.length; i++) {
if(infield[i].isOccupied()) {
if (infield[i].isOccupied()) {
if (infield[i].getOccupant().equals(piece)) {
return i;
}

View File

@@ -53,8 +53,8 @@ public static Color getColorByIndex(int index) {
public Color next(Game game) {
ArrayList<Color> colorsInGame = new ArrayList<>();
for(Player p : game.getPlayers().values()) {
if(p.isFinished()) {
for (Player p : game.getPlayers().values()) {
if (p.isFinished()) {
continue;
}
colorsInGame.add(p.getColor());

View File

@@ -109,7 +109,7 @@ private void initializeDrawPile() {
*/
public PowerCard draw() {
if (!this.drawPile.isEmpty()) {
if (drawPile.size() == 1){
if (drawPile.size() == 1) {
Collections.shuffle(this.discardPile);
this.drawPile.addAll(this.discardPile);
discardPile.clear();
@@ -221,7 +221,7 @@ public Player getPlayerByColor(Color color) {
*
* @return the active player
*/
public Player getActivePlayer(){
public Player getActivePlayer() {
return getPlayerByColor(activeColor);
}

View File

@@ -46,7 +46,7 @@ public void setOccupant(Piece occupant) {
this.occupant = occupant;
}
public boolean isBonus(){
public boolean isBonus() {
return false;
}

View File

@@ -2,7 +2,6 @@
import com.jme3.network.serializing.Serializable;
import java.util.Objects;
import java.util.UUID;
/**

View File

@@ -147,7 +147,7 @@ public boolean isFinished() {
*/
public PowerCard getPowerCardByType(BonusCard bonusCard) {
for (PowerCard card : this.handCards) {
if(card.getCard().equals(bonusCard)) {
if (card.getCard().equals(bonusCard)) {
return card;
}
}
@@ -155,9 +155,9 @@ public PowerCard getPowerCardByType(BonusCard bonusCard) {
// throw new RuntimeException("bonusCard is not in handCards");
}
public Piece getWaitingPiece(){
public Piece getWaitingPiece() {
for (Piece piece : this.waitingArea) {
if (piece != null){
if (piece != null) {
return piece;
}
}
@@ -170,9 +170,9 @@ public Piece getWaitingPiece(){
*
* @return the boolean if the waiting area contains a piece
*/
public boolean hasPieceInWaitingArea(){
public boolean hasPieceInWaitingArea() {
for (Piece piece : this.waitingArea) {
if (piece != null){
if (piece != null) {
return true;
}
}
@@ -211,10 +211,10 @@ public boolean isHomeFinished(Piece piece) {
*
* @return the index
*/
public int getHighestHomeIdx(){
for (int i =3; i>=0;i--){
if(!homeNodes[i].isOccupied()) {
System.out.println("Player: highestHomeIndex:"+i);
public int getHighestHomeIdx() {
for (int i = 3; i >= 0; i--) {
if (!homeNodes[i].isOccupied()) {
System.out.println("Player: highestHomeIndex:" + i);
return i;
}

View File

@@ -15,6 +15,7 @@ public class ShieldCard extends PowerCard {
public ShieldCard() {
this.card = BonusCard.SHIELD;
}
/**
* This method will be used to call the visit method of the given visitor parameter and pass a PowerCard object.
*

View File

@@ -33,7 +33,7 @@ public JoinedLobbyMessage() {
*
* @return the name of the player that is joining the server
*/
public String getName(){
public String getName() {
return name;
}

View File

@@ -19,6 +19,7 @@ public class CeremonyMessage extends ServerMessage {
private ArrayList<Integer> sixes;
private ArrayList<Integer> nodesMoved;
private ArrayList<Integer> bonusNodes;
/**
* Constructs a new Ceremony instance.
*/

View File

@@ -8,6 +8,7 @@ public class ChoosePieceStateMessage extends ServerMessage {
public ChoosePieceStateMessage() {
super();
}
/**
* Accepts a visitor to process this message.
*

View File

@@ -2,8 +2,6 @@
import com.jme3.network.serializing.Serializable;
import java.util.List;
/**
* A message sent by the server to the client to inform about the dice roll.
*/

View File

@@ -4,16 +4,16 @@
import pp.mdga.game.card.PowerCard;
@Serializable
public class DrawCardMessage extends ServerMessage{
public class DrawCardMessage extends ServerMessage {
private final PowerCard card;
public DrawCardMessage(PowerCard card){
public DrawCardMessage(PowerCard card) {
super();
this.card = card;
}
private DrawCardMessage(){
private DrawCardMessage() {
super();
card = null;
}
@@ -28,12 +28,12 @@ public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
public PowerCard getCard(){
public PowerCard getCard() {
return card;
}
@Override
public String toString() {
return "DrawCardMessage{" + "PowerCard=" + card +'}';
return "DrawCardMessage{" + "PowerCard=" + card + '}';
}
}

View File

@@ -32,7 +32,7 @@ public IncorrectRequestMessage() {
*
* @return the id of the error message
*/
public int getId(){
public int getId() {
return id;
}

View File

@@ -1,7 +1,6 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Color;
/**
* A message sent by the server to indicate that a player has left the lobby.

View File

@@ -3,8 +3,6 @@
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Piece;
import java.util.UUID;
/**
* A message sent by the server to the client to move a piece on the board.
*/
@@ -28,8 +26,8 @@ public class MoveMessage extends ServerMessage {
/**
* Constructs a new MoveMessage instance.
*
* @param piece the identifier of the piece that should be moved
* @param isHomeMove boolean flag declaring home move or not
* @param piece the identifier of the piece that should be moved
* @param isHomeMove boolean flag declaring home move or not
* @param targetIndex the targetIndex
*/
public MoveMessage(Piece piece, boolean isHomeMove, int targetIndex) {

View File

@@ -3,10 +3,8 @@
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Piece;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* A message sent by the server to the active player to give all possible pieces to choose from.

View File

@@ -1,9 +1,9 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Piece;
import java.util.List;
import pp.mdga.game.Piece;
/**
* A message sent by the server to the active player to select a piece to move.

View File

@@ -2,12 +2,10 @@
import pp.mdga.game.BonusCard;
import java.util.UUID;
/**
* Notification that is sent when a card is acquired.
*/
public class AcquireCardNotification extends Notification{
public class AcquireCardNotification extends Notification {
private BonusCard bonusCard;

View File

@@ -2,10 +2,10 @@
import pp.mdga.game.Color;
public class FinishNotification extends Notification{
public class FinishNotification extends Notification {
private Color colorFinished;
public FinishNotification(Color colorFinished){
public FinishNotification(Color colorFinished) {
this.colorFinished = colorFinished;
}

View File

@@ -5,7 +5,7 @@
/**
* GameNotification class
*/
public class GameNotification extends Notification{
public class GameNotification extends Notification {
private final Color ownColor;

View File

@@ -3,7 +3,7 @@
/**
* Notification that is to give information to the player.
*/
public class InfoNotification extends Notification{
public class InfoNotification extends Notification {
private final String message;
@@ -28,5 +28,7 @@ public String getMessage() {
return message;
}
public boolean isError() { return isError; }
public boolean isError() {
return isError;
}
}

View File

@@ -2,7 +2,7 @@
import pp.mdga.game.Color;
public class LobbyReadyNotification extends Notification{
public class LobbyReadyNotification extends Notification {
/**
* The color of the player.

View File

@@ -31,9 +31,9 @@ public class MovePieceNotification extends Notification {
/**
* Constructs a notification for a piece start movement.
*
* @param piece the unique identifier of the piece
* @param moveIndex the destination node index
* @param moveStart whether to ignore {@code startIndex} and use {@code moveIndex} as the start node
* @param piece the unique identifier of the piece
* @param moveIndex the destination node index
* @param moveStart whether to ignore {@code startIndex} and use {@code moveIndex} as the start node
*/
public MovePieceNotification(UUID piece, int moveIndex, boolean moveStart) {
this.piece = piece;

View File

@@ -1,13 +1,12 @@
package pp.mdga.notification;
import pp.mdga.game.Color;
import pp.mdga.message.server.ServerMessage;
import java.util.HashMap;
import java.util.Map;
public class RankingResponceNotification extends Notification {
private final Map<Color, Integer> rankingResults;
/**
* Constructor.
*

View File

@@ -5,7 +5,7 @@
/**
* Notification that a die has been rolled.
*/
public class RollDiceNotification extends Notification{
public class RollDiceNotification extends Notification {
private Color color;
private int eyes;
@@ -14,10 +14,12 @@ public class RollDiceNotification extends Notification{
private boolean isRanking;
//normal
/**
* Constructor.
*
* @param color the color of the player that rolled the die.
* @param eyes the number of eyes that were rolled.
* @param eyes the number of eyes that were rolled.
*/
public RollDiceNotification(Color color, int eyes) {
this.color = color;
@@ -47,6 +49,7 @@ public RollDiceNotification(Color color, int eyes, int multiplier) {
/**
* Get the color of the player that rolled the die.
*
* @return the color of the player that rolled the die.
*/
public Color getColor() {
@@ -55,6 +58,7 @@ public Color getColor() {
/**
* Get the number of eyes that were rolled.
*
* @return the number of eyes that were rolled.
*/
public int getEyes() {
@@ -69,5 +73,7 @@ public boolean isTurbo() {
return turbo;
}
public boolean isRanking() { return isRanking; }
public boolean isRanking() {
return isRanking;
}
}

View File

@@ -1,6 +1,7 @@
package pp.mdga.notification;
import pp.mdga.game.BonusCard;
import java.util.List;
/**
@@ -14,6 +15,7 @@ public class SelectableCardsNotification extends Notification {
/**
* Constructor.
*
* @param cards The list of cards that the player can choose from.
*/
public SelectableCardsNotification(List<BonusCard> cards) {
@@ -22,6 +24,7 @@ public SelectableCardsNotification(List<BonusCard> cards) {
/**
* Get the list of cards that the player can choose from.
*
* @return The list of cards that the player can choose from.
*/
public List<BonusCard> getCards() {

View File

@@ -26,9 +26,9 @@ public class SelectableMoveNotification extends Notification {
/**
* Constructs a notification for selectable piece moves.
*
* @param pieces the list of pieces that can be moved
* @param pieces the list of pieces that can be moved
* @param moveIndices the list of target nodes for the moves
* @param homeMoves the list indicating if the target nodes are in the home area
* @param homeMoves the list indicating if the target nodes are in the home area
*/
public SelectableMoveNotification(List<UUID> pieces, List<Integer> moveIndices, List<Boolean> homeMoves) {
this.pieces = pieces;

View File

@@ -3,10 +3,10 @@
import java.util.List;
import java.util.UUID;
public class SelectableShieldNotification extends Notification{
public class SelectableShieldNotification extends Notification {
private List<UUID> pieces;
public SelectableShieldNotification(List<UUID> pieces){
public SelectableShieldNotification(List<UUID> pieces) {
this.pieces = pieces;
}

View File

@@ -1,4 +1,4 @@
package pp.mdga.notification;
public class TurboActiveNotification extends Notification{
public class TurboActiveNotification extends Notification {
}

View File

@@ -9,7 +9,7 @@
/**
*
*/
public class ServerGameLogic implements ClientInterpreter {
public class ServerGameLogic implements ClientInterpreter {
/**
* Constants.
*/

View File

@@ -2,7 +2,6 @@
import pp.mdga.game.Color;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.notification.CeremonyNotification;
import pp.mdga.server.ServerGameLogic;
/**
@@ -28,9 +27,9 @@ public CeremonyState(ServerGameLogic logic) {
*
* @return the created CeremonyNotification
*/
private CeremonyMessage createCeremonyMessage(){
private CeremonyMessage createCeremonyMessage() {
CeremonyMessage message = new CeremonyMessage();
for (var player : logic.getGame().getPlayerRanking().entrySet()){
for (var player : logic.getGame().getPlayerRanking().entrySet()) {
message.getColors().add(player.getValue().getColor());
message.getNames().add(player.getValue().getName());
message.getSixes().add(player.getValue().getPlayerStatistic().getDiced6());

View File

@@ -3,9 +3,9 @@
import pp.mdga.message.client.*;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.message.server.PauseGameMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.AnimationState;
import pp.mdga.server.automaton.game.DetermineStartPlayerState;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.GameAutomatonState;
import pp.mdga.server.automaton.game.TurnState;
@@ -86,15 +86,15 @@ public void received(LeaveGameMessage msg, int from) {
}
@Override
public void received(NoPowerCardMessage msg, int from){
public void received(NoPowerCardMessage msg, int from) {
this.currentState.received(msg, from);
}
public void received(SelectCardMessage msg, int from){
public void received(SelectCardMessage msg, int from) {
currentState.received(msg, from);
}
public void received(RequestMoveMessage msg, int from){
public void received(RequestMoveMessage msg, int from) {
this.currentState.received(msg, from);
}

View File

@@ -4,10 +4,6 @@
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;
@@ -98,8 +94,7 @@ public void received(SelectTSKMessage msg, int from) {
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE, false));
this.logic.getGame().getPlayerById(from).setColor(msg.getColor());
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor(), true));
}
else {
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(0));
}
}
@@ -132,8 +127,7 @@ public void received(LobbyReadyMessage msg, int from) {
if (color != Color.NONE) {
this.logic.getGame().getPlayerById(from).setColor(color);
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, color, true));
}
else {
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(1));
}
}
@@ -171,8 +165,7 @@ public void received(StartGameMessage msg, int from) {
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(6));
}
}
else {
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(5));
}
}

View File

@@ -41,7 +41,8 @@ public ServerState(ServerGameLogic logic) {
* @param msg as the message which was sent by the player as a AnimationEndMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(AnimationEndMessage msg, int from) {}
public void received(AnimationEndMessage msg, int from) {
}
/**
* This method will be called whenever the server received a DeselectTSKMessage message.
@@ -50,7 +51,8 @@ public void received(AnimationEndMessage msg, int from) {}
* @param msg as the message which was sent by the player as a DeselectTSKMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(DeselectTSKMessage msg, int from) {}
public void received(DeselectTSKMessage msg, int from) {
}
/**
* This method will be called whenever the server received a StartGame message.
@@ -59,7 +61,8 @@ public void received(DeselectTSKMessage msg, int from) {}
* @param msg as the message which was sent by the player as a StartGame object.
* @param from as the client id of the player as an Integer.
*/
public void received(StartGameMessage msg, int from) {}
public void received(StartGameMessage msg, int from) {
}
/**
* This method will be called whenever the server received a JoinedLobbyMessage message.
@@ -68,7 +71,8 @@ public void received(StartGameMessage msg, int from) {}
* @param msg as the message which was sent by the player as a JoinedLobbyMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(JoinedLobbyMessage msg, int from) {}
public void received(JoinedLobbyMessage msg, int from) {
}
/**
* This method will be called whenever the server received an LeaveGameMessage message.
@@ -94,7 +98,8 @@ public void received(LeaveGameMessage msg, int from) {
* @param msg as the message which was sent by the player as a LobbyReadyMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(LobbyReadyMessage msg, int from) {}
public void received(LobbyReadyMessage msg, int from) {
}
/**
* This method will be called whenever the server received a LobbyNotReadyMessage message.
@@ -103,7 +108,8 @@ public void received(LobbyReadyMessage msg, int from) {}
* @param msg as the message which was sent by the player as a LobbyNotReadyMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(LobbyNotReadyMessage msg, int from) {}
public void received(LobbyNotReadyMessage msg, int from) {
}
/**
* This method will be called whenever the server received a DisconnectedMessage message.
@@ -112,7 +118,8 @@ public void received(LobbyNotReadyMessage msg, int from) {}
* @param msg as the message which was sent by the player as a DisconnectedMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(DisconnectedMessage msg, int from) {}
public void received(DisconnectedMessage msg, int from) {
}
/**
* This method will be called whenever the server received a RequestBriefingMessage message.
@@ -121,7 +128,8 @@ public void received(DisconnectedMessage msg, int from) {}
* @param msg as the message which was sent by the player as a RequestBriefingMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(RequestBriefingMessage msg, int from) {}
public void received(RequestBriefingMessage msg, int from) {
}
/**
* This method will be called whenever the server received a RequestDieMessage message.
@@ -130,7 +138,8 @@ public void received(RequestBriefingMessage msg, int from) {}
* @param msg as the message which was sent by the player as a RequestDieMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(RequestDieMessage msg, int from) {}
public void received(RequestDieMessage msg, int from) {
}
/**
* This method will be called whenever the server received a RequestMoveMessage message.
@@ -139,7 +148,8 @@ public void received(RequestDieMessage msg, int from) {}
* @param msg as the message which was sent by the player as a RequestMoveMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(RequestMoveMessage msg, int from) {}
public void received(RequestMoveMessage msg, int from) {
}
/**
* This method will be called whenever the server received a RequestPlayCardMessage message.
@@ -148,7 +158,8 @@ public void received(RequestMoveMessage msg, int from) {}
* @param msg as the message which was sent by the player as a RequestPlayCardMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(RequestPlayCardMessage msg, int from) {}
public void received(RequestPlayCardMessage msg, int from) {
}
/**
* This method will be called whenever the server received a SelectCardMessage message.
@@ -157,7 +168,8 @@ public void received(RequestPlayCardMessage msg, int from) {}
* @param msg as the message which was sent by the player as a SelectCardMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(SelectCardMessage msg, int from) {}
public void received(SelectCardMessage msg, int from) {
}
/**
* This method will be called whenever the server received a SelectTSKMessage message.
@@ -166,7 +178,8 @@ public void received(SelectCardMessage msg, int from) {}
* @param msg as the message which was sent by the player as a SelectTSKMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(SelectTSKMessage msg, int from) {}
public void received(SelectTSKMessage msg, int from) {
}
/**
* This method will be called whenever the server received a ForceContinueGameMessage message.
@@ -175,7 +188,8 @@ public void received(SelectTSKMessage msg, int from) {}
* @param msg as the message which was sent by the player as a ForceContinueGameMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(ForceContinueGameMessage msg, int from) {}
public void received(ForceContinueGameMessage msg, int from) {
}
/**
* This method will be called whenever the server received a ClientStartGameMessage message.
@@ -184,7 +198,8 @@ public void received(ForceContinueGameMessage msg, int from) {}
* @param msg as the message which was sent by the player as a ClientStartGameMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(ClientStartGameMessage msg, int from) {}
public void received(ClientStartGameMessage msg, int from) {
}
/**
* This method will be called whenever the server received a NoPowerCardMessage message.
@@ -193,7 +208,8 @@ public void received(ClientStartGameMessage msg, int from) {}
* @param msg as the message which was sent by the player as a NoPowerCardMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(NoPowerCardMessage msg, int from) {}
public void received(NoPowerCardMessage msg, int from) {
}
/**
* This method will be called whenever the server received a SelectedPiecesMessage message.
@@ -202,5 +218,6 @@ public void received(NoPowerCardMessage msg, int from) {}
* @param msg as the message which was sent by the player as a SelectedPiecesMessage object.
* @param from as the client id of the player as an Integer.
*/
public void received(SelectedPiecesMessage msg, int from) {}
public void received(SelectedPiecesMessage msg, int from) {
}
}

View File

@@ -6,19 +6,12 @@
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.message.server.RankingResponseMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.GameState;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.*;
public class DetermineStartPlayerState extends GameAutomatonState {
/**
@@ -32,7 +25,7 @@ public class DetermineStartPlayerState extends GameAutomatonState {
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 final Set<Integer> messageReceived = new HashSet<>();
private int playerToStart;
/**
@@ -77,8 +70,7 @@ public void received(RequestDieMessage msg, int from) {
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()) {
} else if (maximumRoll < entry.getValue()) {
maximumRoll = entry.getValue();
this.playersHaveToRoll.clear();
this.playersHaveToRoll.add(entry.getKey());
@@ -109,8 +101,7 @@ public void received(AnimationEndMessage msg, int from) {
}
finalDiceResults.putAll(this.diceResults);
diceResults.clear();
}
else {
} 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();

View File

@@ -6,12 +6,7 @@
import pp.mdga.message.client.*;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.GameState;
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
import pp.mdga.server.automaton.game.turn.MovePieceState;
import pp.mdga.server.automaton.game.turn.PlayPowerCardState;
import pp.mdga.server.automaton.game.turn.PowerCardState;
import pp.mdga.server.automaton.game.turn.RollDiceState;
import pp.mdga.server.automaton.game.turn.TurnAutomatonState;
import pp.mdga.server.automaton.game.turn.*;
import java.lang.System.Logger.Level;
@@ -118,7 +113,7 @@ public void received(AnimationEndMessage msg, int from) {
this.currentState.received(msg, from);
}
public void received(SelectCardMessage msg, int from){
public void received(SelectCardMessage msg, int from) {
currentState.received(msg, from);
}
@@ -195,7 +190,7 @@ public void setCurrentState(TurnAutomatonState state) {
if (this.currentState != null) {
this.currentState.exit();
}
System.out.println("Server: the server entered:"+state);
System.out.println("Server: the server entered:" + state);
this.currentState = state;
this.currentState.enter();
}

View File

@@ -4,7 +4,6 @@
import pp.mdga.game.Player;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.message.server.SpectatorMessage;
@@ -43,20 +42,20 @@ private void setActivePlayer(Color activePlayer) {
}
@Override
public void received(AnimationEndMessage msg, int from){
public void received(AnimationEndMessage msg, int from) {
finishedAnimations.add(logic.getGame().getPlayerById(from));
if (finishedAnimations.size() == logic.getGame().getPlayers().size()) {
if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()){
if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()) {
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
setActivePlayer(logic.getGame().getActiveColor());
if (logic.getGame().getPlayerRanking().size() == logic.getGame().getPlayers().size() - 1){
if (logic.getGame().getPlayerRanking().size() == logic.getGame().getPlayers().size() - 1) {
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.setCurrentState(logic.getCeremonyState());
return;
}
this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState());
} else if (logic.getGame().getDiceEyes() == 6){
} else if (logic.getGame().getDiceEyes() == 6) {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage());
this.turnAutomaton.setCurrentState(this.turnAutomaton.getRollDiceState());
} else {

View File

@@ -3,7 +3,6 @@
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.AnimationState;
import pp.mdga.server.automaton.game.TurnState;
import java.util.HashSet;

View File

@@ -10,11 +10,7 @@
import pp.mdga.message.server.PossibleCardsMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.TurnState;
import pp.mdga.server.automaton.game.turn.powercard.ChoosePowerCardState;
import pp.mdga.server.automaton.game.turn.powercard.PowerCardAutomatonState;
import pp.mdga.server.automaton.game.turn.powercard.ShieldCardState;
import pp.mdga.server.automaton.game.turn.powercard.SwapCardState;
import pp.mdga.server.automaton.game.turn.powercard.TurboCardState;
import pp.mdga.server.automaton.game.turn.powercard.*;
import pp.mdga.visitor.ServerCardVisitor;
import java.util.HashSet;
@@ -41,7 +37,7 @@ public class PowerCardState extends TurnAutomatonState {
private ServerCardVisitor visitor;
private PowerCard selectedCard;
private final Set<Piece> selectedPieces = new HashSet<>();
private final Set<BonusCard> chekedCards = new HashSet<>();
private final Set<BonusCard> chekedCards = new HashSet<>();
/**
* Constructs a server state of the specified game logic.
@@ -74,8 +70,7 @@ public void enter() {
if (this.visitor.getCards().isEmpty()) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
this.turnAutomaton.setCurrentState(this.turnAutomaton.getRollDiceState());
}
else {
} else {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PossibleCardsMessage(this.visitor.getCards()));
}
}
@@ -86,7 +81,7 @@ public void exit() {
}
@Override
public void received(NoPowerCardMessage msg, int form){
public void received(NoPowerCardMessage msg, int form) {
currentState.received(msg, form);
}
@@ -100,7 +95,7 @@ public void addSelectedPiece(Piece piece) {
this.selectedPieces.add(piece);
}
public void received(SelectCardMessage msg, int from){
public void received(SelectCardMessage msg, int from) {
currentState.received(msg, from);
}

View File

@@ -40,7 +40,7 @@ public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) {
@Override
public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state.");
if (resetModifier){
if (resetModifier) {
logic.getGame().setDiceModifier(1);
}
this.setCurrentState(this.firstRollState);
@@ -65,7 +65,7 @@ public void received(RequestDieMessage msg, int from) {
}
@Override
public void received(AnimationEndMessage msg, int from){
public void received(AnimationEndMessage msg, int from) {
this.currentState.received(msg, from);
}

View File

@@ -1,7 +1,6 @@
package pp.mdga.server.automaton.game.turn.choosepiece;
import pp.mdga.game.*;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.ServerState;
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
@@ -43,8 +42,7 @@ protected boolean canMove(Piece piece) {
if (canPieceMoveInHome(piece, steps)) {
return true;
}
}
else {
} else {
if (canPieceMoveInHome(piece, steps)) {
return true;
}
@@ -55,8 +53,8 @@ else if (40 > targetIdx && (!piece.getState().equals(PieceState.HOME) || !piece.
//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()) {
if(tartgetNode.getOccupant().getShield().equals(ShieldState.ACTIVE)) {
if (tartgetNode.isOccupied()) {
if (tartgetNode.getOccupant().getShield().equals(ShieldState.ACTIVE)) {
System.out.println("Server: targetNode.getOccupant().getShield().equals(ShieldState.ACTIVE" + tartgetNode.getOccupant().getShield().equals(ShieldState.ACTIVE));
return false;
}
@@ -88,8 +86,7 @@ protected boolean canPieceMoveInHome(Piece piece, int steps) {
//tests if the steps are less than the possible movement
if ((3 - homeIdx) >= steps - 1) {
return !jumpOver(steps, homeIdx, false);
}
else {
} else {
return false;
}
}
@@ -107,8 +104,7 @@ else if (piece.getState() == PieceState.ACTIVE) {
if (restMovement >= 4) return false;
return !jumpOver(restMovement, 0, true);
}
}
else {
} else {
return false;
}
return false;
@@ -126,7 +122,7 @@ 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(stepsInHome>3) return true;
if (stepsInHome > 3) return true;
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;
@@ -136,7 +132,7 @@ private boolean jumpOver(int stepsInHome, int homeIdx, boolean outside) {
else {
int targetIndex = stepsInHome + homeIdx;
System.out.println("Server: jumpOver: for the homeIndex: " + homeIdx + " ,stepsInHome: " + stepsInHome + " , outside: " + outside + " and the targetIndex: " + targetIndex);
if(targetIndex>3) return true;
if (targetIndex > 3) return true;
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;

View File

@@ -1,8 +1,8 @@
package pp.mdga.server.automaton.game.turn.choosepiece;
import pp.mdga.Resources;
import pp.mdga.game.*;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.Player;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
@@ -36,24 +36,19 @@ private void initialize() {
}
}
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
}
else if (activePlayer.hasPieceInWaitingArea()) {
} 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);
}
}
@@ -68,8 +63,7 @@ private void checkSelectPiece(Player activePlayer) {
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());
}

View File

@@ -48,8 +48,7 @@ public void enter() {
int target = getHomeTargetIdx(piece, steps);
targetIndex.add(target);
isHomeMove.add(true);
}
else {
} else {
int target = getInfieldTarget(piece, steps);
targetIndex.add(target);
isHomeMove.add(false);
@@ -78,15 +77,13 @@ public void received(RequestMoveMessage msg, int from) {
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[targetHomeIdx];
if (targetHomeIdx == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else {
} else {
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
}
else {
} else {
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
@@ -96,8 +93,7 @@ public void received(RequestMoveMessage msg, int from) {
if (targetHomeIdx == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else {
} else {
piece.setState(PieceState.HOME);
}
@@ -105,8 +101,7 @@ public void received(RequestMoveMessage msg, int from) {
targetNode.setOccupant(piece);
}
LOGGER.log(System.Logger.Level.INFO, "Server : SelectPieceState: PieceState:" + piece.getState());
}
else {
} 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];
@@ -147,8 +142,7 @@ public void received(RequestMoveMessage msg, int from) {
PowerCard cardToDraw = logic.getGame().draw();
p.addHandCard(cardToDraw);
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
}
else {
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
}

View File

@@ -75,8 +75,7 @@ public void received(RequestMoveMessage msg, int from) {
PowerCard cardToDraw = logic.getGame().draw();
p.addHandCard(cardToDraw);
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
}
else {
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
}

View File

@@ -2,13 +2,11 @@
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState;
import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.server.MoveMessage;
import pp.mdga.message.server.WaitPieceMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
public class WaitingPieceState extends ChoosePieceAutomatonState {
/**
@@ -38,7 +36,7 @@ public void enter() {
}
@Override
public void received(RequestMoveMessage msg, int from){
public void received(RequestMoveMessage msg, int from) {
if (msg.getPiece().equals(this.piece)) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeWaitingPiece(this.piece);
piece.setState(PieceState.ACTIVE);

View File

@@ -1,11 +1,7 @@
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;
import pp.mdga.game.card.*;
import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.server.DiceNowMessage;

View File

@@ -14,7 +14,7 @@ public abstract class PowerCardAutomatonState extends ServerState {
* Constructs a server state of the specified game logic.
*
* @param powerCardAutomaton as the automaton of the turn state as a PowerCardState object.
* @param logic the game logic
* @param logic the game logic
*/
public PowerCardAutomatonState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
super(logic);

View File

@@ -1,9 +1,7 @@
package pp.mdga.server.automaton.game.turn.powercard;
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PlayCardMessage;
@@ -62,8 +60,7 @@ public void received(SelectedPiecesMessage msg, int from) {
this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).removeHandCard(this.powerCardAutomaton.getSelectedCard());
this.logic.getGame().getDiscardPile().add(this.powerCardAutomaton.getSelectedCard());
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
}
else {
} else {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(3));
}
}

View File

@@ -1,7 +1,6 @@
package pp.mdga.server.automaton.game.turn.powercard;
import pp.mdga.game.Board;
import pp.mdga.game.Color;
import pp.mdga.game.Node;
import pp.mdga.game.Piece;
import pp.mdga.game.card.SwapCard;
@@ -12,7 +11,6 @@
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.PowerCardState;
import java.util.ArrayList;
import java.util.List;
public class SwapCardState extends PowerCardAutomatonState {
@@ -58,12 +56,12 @@ public void received(SelectedPiecesMessage msg, int from) {
if (msg.getPieces().size() == 2) {
Piece selOwn = msg.getPieces().get(0);
Piece selEnemy = msg.getPieces().get(1);
System.out.println("Server: Swapcard: ownPiece: "+selOwn+ " enemyPiece: "+selEnemy);
System.out.println("Server: Swapcard: ownPiece: " + selOwn + " enemyPiece: " + selEnemy);
List<Piece> ownPieces = this.powerCardAutomaton.getVisitor().getSwapOwnPieces();
List<Piece> enemyPieces = this.powerCardAutomaton.getVisitor().getSwapOtherPieces();
//if selOwn and selEnemy is in wrong order
if(ownPieces.contains(selEnemy) && enemyPieces.contains(selOwn)){
if (ownPieces.contains(selEnemy) && enemyPieces.contains(selOwn)) {
Piece temp = selEnemy;
selEnemy = selOwn;
selOwn = temp;
@@ -73,7 +71,8 @@ public void received(SelectedPiecesMessage msg, int from) {
this.powerCardAutomaton.addSelectedPiece(selOwn);
this.powerCardAutomaton.addSelectedPiece(selEnemy);
if(!(powerCardAutomaton.getSelectedCard() instanceof SwapCard)) throw new RuntimeException("getSelectedCard is not swapCard");
if (!(powerCardAutomaton.getSelectedCard() instanceof SwapCard))
throw new RuntimeException("getSelectedCard is not swapCard");
swapPieces(selOwn, selEnemy);

View File

@@ -6,8 +6,6 @@
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ChoosePieceStateMessage;
import pp.mdga.message.server.DiceAgainMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.RollDiceState;
@@ -75,7 +73,7 @@ public void received(RequestDieMessage msg, int from) {
public void received(AnimationEndMessage msg, int from) {
if (from != this.logic.getGame().getActivePlayerId()) {
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage from wrong player.");
} else if (!isDied){
} 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());

View File

@@ -4,7 +4,6 @@
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ChoosePieceStateMessage;
import pp.mdga.message.server.DiceAgainMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.server.ServerGameLogic;

View File

@@ -2,11 +2,7 @@
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
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;
import pp.mdga.game.card.*;
import pp.mdga.server.ServerGameLogic;
import java.util.ArrayList;

View File

@@ -1,29 +1,28 @@
package pp.mdga.client.clientState;
import org.junit.*;
import org.junit.Before;
import org.junit.Test;
import pp.mdga.client.*;
import pp.mdga.client.ceremonystate.*;
import pp.mdga.client.dialogstate.*;
import pp.mdga.client.gamestate.AnimationState;
import pp.mdga.client.gamestate.DetermineStartPlayerState;
import pp.mdga.client.gamestate.SpectatorState;
import pp.mdga.client.gamestate.TurnState;
import pp.mdga.client.gamestate.WaitingState;
import pp.mdga.client.ceremonystate.PodiumState;
import pp.mdga.client.ceremonystate.StatisticsState;
import pp.mdga.client.dialogstate.LobbyState;
import pp.mdga.client.dialogstate.NetworkDialogState;
import pp.mdga.client.dialogstate.StartDialogState;
import pp.mdga.client.gamestate.*;
import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState;
import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState;
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
import pp.mdga.client.gamestate.turnstate.MovePieceState;
import pp.mdga.client.gamestate.turnstate.*;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.*;
import pp.mdga.client.gamestate.turnstate.powercardstate.*;
import pp.mdga.game.Game;
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.Player;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.NoPieceState;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.SelectPieceState;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.StartPieceState;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.WaitingPieceState;
import pp.mdga.client.gamestate.turnstate.powercardstate.ChoosePowerCardState;
import pp.mdga.client.gamestate.turnstate.powercardstate.ShieldState;
import pp.mdga.client.gamestate.turnstate.powercardstate.SwapState;
import pp.mdga.game.*;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.server.*;
import pp.mdga.game.Color;
import pp.mdga.message.client.ClientMessage;
import pp.mdga.message.server.*;
import pp.mdga.visitor.Visitor;
import java.util.ArrayList;
@@ -128,7 +127,7 @@ public class ClientStateTest {
private Piece ownPiece;
//declare enemy piece
private Piece enemyPiece ;
private Piece enemyPiece;
@Before
public void setUp() {
@@ -152,13 +151,13 @@ public void send(ClientMessage msg) {
player = new Player(name);
player.setColor(color);
player.initialize();
game.addPlayer(1234,player);
game.addPlayer(1234, player);
game.setActiveColor(color);
ownPiece = player.getWaitingPiece();
ownPiece.setState(PieceState.ACTIVE);
player.removeWaitingPiece(ownPiece);
game.getBoard().setPieceOnBoard(22,ownPiece);
game.getBoard().setPieceOnBoard(22, ownPiece);
//todo piece
@@ -174,7 +173,7 @@ public void accept(Visitor visitor) {
}
};
turboCard = new PowerCard() {
turboCard = new PowerCard() {
@Override
public void accept(Visitor visitor) {
@@ -184,23 +183,23 @@ public void accept(Visitor visitor) {
//declare ownPlayer
//declare other player
enemy= new Player(name);
enemy = new Player(name);
enemy.setColor(Color.CYBER);
enemyColor=Color.CYBER;
game.addPlayer(2345,enemy);
enemyColor = Color.CYBER;
game.addPlayer(2345, enemy);
enemy.initialize();
enemyPiece = enemy.getWaitingPiece();
enemyPiece.setState(PieceState.ACTIVE);
enemy.removeWaitingPiece(enemyPiece);
game.getBoard().setPieceOnBoard(33,enemyPiece);
game.getBoard().setPieceOnBoard(33, enemyPiece);
//sets the player in the game
clientGameLogic.getGame().addPlayer(0,player);
clientGameLogic.getGame().addPlayer(1,enemy);
clientGameLogic.getGame().getBoard().setPieceOnBoard(15,ownPiece);
clientGameLogic.getGame().getBoard().setPieceOnBoard(25,enemyPiece);
clientGameLogic.getGame().addPlayer(0, player);
clientGameLogic.getGame().addPlayer(1, enemy);
clientGameLogic.getGame().getBoard().setPieceOnBoard(15, ownPiece);
clientGameLogic.getGame().getBoard().setPieceOnBoard(25, enemyPiece);
//initialize the messages from the server
@@ -215,15 +214,15 @@ public void accept(Visitor visitor) {
endOfTurn = new EndOfTurnMessage();
lobbyAccept = new LobbyAcceptMessage();
lobbyDeny = new LobbyDenyMessage();
lobbyPlayerJoin = new LobbyPlayerJoinedMessage(from, player,true);
lobbyPlayerJoin = new LobbyPlayerJoinedMessage(from, player, true);
lobbyPlayerLeave = new LobbyPlayerLeaveMessage(from);
moveMessage = new MoveMessage(ownPiece, false, 25);
noTurn = new NoTurnMessage();
interruptMessage = new PauseGameMessage();
playCardSwap = new PlayCardMessage(swapCard, new ArrayList<>(List.of(ownPiece, enemyPiece)), 1); //TODO
playCardShield = new PlayCardMessage(shieldCard, new ArrayList<>(List.of(ownPiece)), 1);
playCardTurbo = new PlayCardMessage(turboCard, new ArrayList<>(List.of(ownPiece)),1);
possibleCard = new PossibleCardsMessage(new ArrayList<>(List.of(swapCard,shieldCard,turboCard)));
playCardTurbo = new PlayCardMessage(turboCard, new ArrayList<>(List.of(ownPiece)), 1);
possibleCard = new PossibleCardsMessage(new ArrayList<>(List.of(swapCard, shieldCard, turboCard)));
possiblePieceShield = PossiblePieceMessage.shieldPossiblePieces(new ArrayList<>(List.of(ownPiece))); //TODO
possiblePieceSwap = PossiblePieceMessage.swapPossiblePieces(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(enemyPiece))); //TODO
//todo possiblePieceSwap = new PossiblePieceMessage(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(enemyPiece)));
@@ -233,13 +232,13 @@ public void accept(Visitor visitor) {
reconnectBriefing = new ReconnectBriefingMessage(game);
resumeGame = new ResumeGameMessage();
startGame = new ServerStartGameMessage();
startPieceMessage = new StartPieceMessage(ownPiece.getUuid(),25);
startPieceMessage = new StartPieceMessage(ownPiece.getUuid(), 25);
updateReady = new UpdateReadyMessage(2345, true);
updateTSK = new UpdateTSKMessage(2345, Color.NAVY,false);
updateTSK = new UpdateTSKMessage(2345, Color.NAVY, false);
waitPiece = new WaitPieceMessage(ownPiece.getUuid());
interruptMessage = new PauseGameMessage();
spectatorMessage = new SpectatorMessage();
selectPieceMessage = new SelectPieceMessage(new ArrayList<>(List.of(ownPiece)),new ArrayList<>(List.of(false)), new ArrayList<>(List.of(25)));
selectPieceMessage = new SelectPieceMessage(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(false)), new ArrayList<>(List.of(25)));
//initialize the client-state
//sets the clientGameLogic-states
@@ -719,7 +718,7 @@ public void testNetworkDialogToLobby() {
//simulate connect to server with send lobby request
clientGameLogic.selectJoin("IP");
clientGameLogic.received(new LobbyAcceptMessage(1234) );
clientGameLogic.received(new LobbyAcceptMessage(1234));
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), lobby);
@@ -859,7 +858,7 @@ public void testDetermineStartPlayerToWait() {
//tests if the client is in the intro
assertEquals(clientGameLogic.getState(), gameState);
assertEquals(gameState.getState(), determineStartPlayer);
assertEquals(determineStartPlayer.getState(),determineStartPlayer.getIntro());
assertEquals(determineStartPlayer.getState(), determineStartPlayer.getIntro());
//todo

View File

@@ -3,11 +3,7 @@
import org.junit.Before;
import org.junit.Test;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.client.RequestPlayCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.client.*;
import pp.mdga.message.server.ServerMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.ServerSender;
@@ -172,7 +168,7 @@ public void shutdown() {
game.addPlayer(IDCyber, playerCyber);
//initialize the playerData
for(Map.Entry<Integer, Player> entry : game.getPlayers().entrySet()){
for (Map.Entry<Integer, Player> entry : game.getPlayers().entrySet()) {
game.addPlayer(entry.getKey(), entry.getValue());
}
@@ -225,26 +221,26 @@ public void shutdown() {
//set the pieces of cyber
game.getBoard().setPieceOnBoard(10,pieceCyber0); // for UC 6,7,8
game.getBoard().setPieceOnBoard(12,pieceCyber1); //
game.getBoard().setPieceOnBoard(10, pieceCyber0); // for UC 6,7,8
game.getBoard().setPieceOnBoard(12, pieceCyber1); //
game.getPlayerByColor(cyberColor).addWaitingPiece(pieceClient3); //for uc 7
//game..... todo
//initializes the states
gameState= serverGameLogic.getGameState();
turnState= gameState.getTurnState();
rollDiceState= turnState.getRollDiceState();
firstRollState= rollDiceState.getFirstRollState();
choosePieceState= turnState.getChoosePieceState();
selectPieceState= choosePieceState.getSelectPieceState();
gameState = serverGameLogic.getGameState();
turnState = gameState.getTurnState();
rollDiceState = turnState.getRollDiceState();
firstRollState = rollDiceState.getFirstRollState();
choosePieceState = turnState.getChoosePieceState();
selectPieceState = choosePieceState.getSelectPieceState();
powerCardState = turnState.getPowerCardState();
playPowerCardState = turnState.getPlayPowerCardState();
waitingPieceState =serverGameLogic.getGameState().getTurnState().getChoosePieceState().getWaitingPieceState();
waitingPieceState = serverGameLogic.getGameState().getTurnState().getChoosePieceState().getWaitingPieceState();
startPieceState = serverGameLogic.getGameState().getTurnState().getChoosePieceState().getStartPieceState();
//initialize dies
die1 = new Die(1);
die2= new Die(2);
die2 = new Die(2);
die3 = new Die(3);
die4 = new Die(4);
die5 = new Die(5);
@@ -267,10 +263,10 @@ public void testMove() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sets the active Player to host
game.setActiveColor(hostColor);
@@ -280,31 +276,31 @@ public void testMove() {
game.setDie(die4);
//sends the request-die-message
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//tests if the server is in selectPieceState
assertTrue(game.getBoard().getInfield()[12].isOccupied());
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//send wrong message
serverGameLogic.received(new RequestMoveMessage(pieceCyber1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceCyber1), IDHost);
//tests if there is no change
assertTrue(game.getBoard().getInfield()[12].isOccupied());
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//sends the move-message
serverGameLogic.received(new RequestMoveMessage(pieceHost2),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost2), IDHost);
//tests if the piece has moved in the right direction
assertTrue(game.getBoard().getInfield()[4].isOccupied());
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
assertEquals(game.getBoard().getInfield()[4].getOccupant(), pieceHost3);
}
/**
@@ -322,10 +318,10 @@ public void testCantMove() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set active player to army
game.setActiveColor(clientColor);
@@ -334,18 +330,18 @@ public void testCantMove() {
game.setDie(die2);
//send request Die-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//send requestMove-Message
serverGameLogic.received(new RequestMoveMessage(pieceClient2),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceClient2), IDClient);
//tests if the hostPiece2 is still at idx 19 and the server is still in selectable pieces
assertTrue(game.getBoard().getInfield()[19].isOccupied());
assertEquals(game.getBoard().getInfield()[19].getOccupant(),pieceClient2);
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(game.getBoard().getInfield()[19].getOccupant(), pieceClient2);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
}
/**
@@ -374,10 +370,10 @@ public void testThrow() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set active player to host
game.setActiveColor(hostColor);
@@ -386,10 +382,10 @@ public void testThrow() {
game.setDie(die1);
//send requestDice
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//send requestMove-message
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
//tests if the idx is unoccupied
assertFalse(game.getBoard().getInfield()[19].isOccupied());
@@ -398,7 +394,7 @@ public void testThrow() {
assertTrue(game.getBoard().getInfield()[20].isOccupied());
//tests if the piece on idx 20 is pieceHost1
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceHost1);
assertEquals(game.getBoard().getInfield()[20].getOccupant(), pieceHost1);
}
/**
@@ -419,23 +415,23 @@ public void testGetThrown() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set Dice to 1
game.setDie(die1);
//send requestDice
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//send requestMove-message
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
//tests if pieceClient2 is waitingArea
Piece[] wait = game.getPlayerByColor(clientColor).getWaitingArea();
assertTrue(wait[0]==pieceClient2 ||wait[1]==pieceClient2 ||wait[2]==pieceClient2 ||wait[3]==pieceClient2 );
assertTrue(wait[0] == pieceClient2 || wait[1] == pieceClient2 || wait[2] == pieceClient2 || wait[3] == pieceClient2);
}
/**
@@ -453,10 +449,10 @@ public void testLeaveWaitingArea() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set active player to host
game.setActiveColor(hostColor);
@@ -465,23 +461,23 @@ public void testLeaveWaitingArea() {
game.setDie(die6);
//send requestDice
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//tests if the sever is in selectPiece
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),waitingPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
//send requestMove-message
serverGameLogic.received(new RequestMoveMessage(pieceHost2),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost2), IDHost);
//tests if the waitingArea does not include the piece anymore
assertFalse(Arrays.stream(game.getPlayerByColor(hostColor).getWaitingArea()).toList().contains(pieceHost2));
//tests if the pieceHost3 is at idx 30
assertTrue(game.getBoard().getInfield()[30].isOccupied());
assertEquals(game.getBoard().getInfield()[30].getOccupant(),pieceHost2);
assertEquals(game.getBoard().getInfield()[30].getOccupant(), pieceHost2);
}
/**
@@ -499,10 +495,10 @@ public void testMustLeaveStartingField() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sets the activePlayer to cyber
game.setActiveColor(cyberColor);
@@ -511,7 +507,7 @@ public void testMustLeaveStartingField() {
game.setDie(die4);
//send requestDiceMessage
serverGameLogic.received(new RequestDieMessage(),IDCyber);
serverGameLogic.received(new RequestDieMessage(), IDCyber);
//tests if the sever is in startPiece
serverGameLogic.setCurrentState(gameState);
@@ -520,11 +516,11 @@ public void testMustLeaveStartingField() {
choosePieceState.setCurrentState(startPieceState);
//send requestMoveMessage
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDCyber);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDCyber);
//tests if the cyberPiece2 has moved
assertTrue(game.getBoard().getInfield()[12].isOccupied());
assertEquals(game.getBoard().getInfield()[12].getOccupant(),pieceCyber1);
assertEquals(game.getBoard().getInfield()[12].getOccupant(), pieceCyber1);
//tests if the sever is in startPiece
serverGameLogic.setCurrentState(gameState);
@@ -533,11 +529,11 @@ public void testMustLeaveStartingField() {
choosePieceState.setCurrentState(startPieceState);
//send requestMoveMessage
serverGameLogic.received(new RequestMoveMessage(pieceHost0),IDCyber);
serverGameLogic.received(new RequestMoveMessage(pieceHost0), IDCyber);
//tests if the piece is moved
assertTrue(game.getBoard().getInfield()[14].isOccupied());
assertEquals(game.getBoard().getInfield()[14].getOccupant(),pieceHost0);
assertEquals(game.getBoard().getInfield()[14].getOccupant(), pieceHost0);
assertFalse(game.getBoard().getInfield()[10].isOccupied());
}
@@ -556,10 +552,10 @@ public void testDontHaveToLeaveStartingField() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set the active player to cyberPlayer
game.setActiveColor(cyberColor);
@@ -571,16 +567,16 @@ public void testDontHaveToLeaveStartingField() {
game.setDie(die3);
//tests if the server is in selectPieceState
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//send requestDice-Message
serverGameLogic.received(new RequestDieMessage(),IDCyber);
serverGameLogic.received(new RequestDieMessage(), IDCyber);
//send requestMoveMessage for CyberPiece1
serverGameLogic.received(new RequestMoveMessage(pieceCyber1),IDCyber);
serverGameLogic.received(new RequestMoveMessage(pieceCyber1), IDCyber);
//tests if the cyberPiece1 is moved
assertTrue(game.getBoard().getInfield()[15].isOccupied());
@@ -603,10 +599,10 @@ public void testCantLeaveStartingField() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sets the activePlayer to cyber
game.setActiveColor(cyberColor);
@@ -615,36 +611,36 @@ public void testCantLeaveStartingField() {
game.setDie(die2);
//send requestDiceMessage
serverGameLogic.received(new RequestDieMessage(),IDCyber);
serverGameLogic.received(new RequestDieMessage(), IDCyber);
//tests if the sever is in selectPiece
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//send requestMoveMessage
serverGameLogic.received(new RequestMoveMessage(pieceCyber0),IDCyber);
serverGameLogic.received(new RequestMoveMessage(pieceCyber0), IDCyber);
//tests if the sever is in selectPiece
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//tests if the cyberPiece0 is still at its idx
assertTrue(game.getBoard().getInfield()[10].isOccupied());
assertEquals(game.getBoard().getInfield()[10].getOccupant(),pieceHost0);
assertEquals(game.getBoard().getInfield()[10].getOccupant(), pieceHost0);
//sets the dice to 2
game.setDie(die2);
//send the requestMove-Message
serverGameLogic.received(new RequestMoveMessage(pieceCyber1),IDCyber);
serverGameLogic.received(new RequestMoveMessage(pieceCyber1), IDCyber);
//tests if the pieceCyber
assertTrue(game.getBoard().getInfield()[14].isOccupied());
assertEquals(game.getBoard().getInfield()[14].getOccupant(),pieceHost1);
assertEquals(game.getBoard().getInfield()[14].getOccupant(), pieceHost1);
}
/**
@@ -662,10 +658,10 @@ public void testReachBonusField() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//gets the top bonusCard
PowerCard card = game.getDrawPile().get(0);
@@ -677,14 +673,14 @@ public void testReachBonusField() {
game.setDie(die4);
//sends the requestDice-Message
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//requestMove of hostPiece3
serverGameLogic.received(new RequestMoveMessage(pieceHost3),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost3), IDHost);
//tests the position of hostPiece3
assertTrue(game.getBoard().getInfield()[4].isOccupied());
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
assertEquals(game.getBoard().getInfield()[4].getOccupant(), pieceHost3);
//tests if the player has received a bonusCard
assertNotEquals(card, game.getDrawPile().get(0));
@@ -706,10 +702,10 @@ public void testNoPowerCards() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sets the active Player to Host
game.setActiveColor(hostColor);
@@ -726,13 +722,13 @@ public void testNoPowerCards() {
assertTrue(game.getDiscardPile().isEmpty());
//sends the requestDice-Message
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
// requestMOve of hostPiece3
serverGameLogic.received(new RequestMoveMessage(pieceHost3),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost3), IDHost);
assertTrue(game.getBoard().getInfield()[4].isOccupied());
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
assertEquals(game.getBoard().getInfield()[4].getOccupant(), pieceHost3);
//tests if the player has received a bonusCard
assertTrue(game.getDrawPile().isEmpty());
@@ -754,10 +750,10 @@ public void testShufflePile() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sets the active Player to Host
game.setActiveColor(hostColor);
@@ -774,13 +770,13 @@ public void testShufflePile() {
assertTrue(game.getDrawPile().isEmpty());
//sends the requestDice-Message
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
// requestMOve of hostPiece3
serverGameLogic.received(new RequestMoveMessage(pieceHost3),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost3), IDHost);
assertTrue(game.getBoard().getInfield()[4].isOccupied());
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
assertEquals(game.getBoard().getInfield()[4].getOccupant(), pieceHost3);
//tests if the player has received a bonusCard
assertFalse(game.getDrawPile().isEmpty());
@@ -810,20 +806,20 @@ public void testEnterHouse() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set the die in Game to 1
game.setDie(die1);
//sends the request-Dice-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//sends the requestMove-message for pieceClient1
System.out.println(game.getBoard().getInfieldIndexOfPiece(pieceClient2));
serverGameLogic.received(new RequestMoveMessage(pieceClient2),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceClient2), IDClient);
System.out.println(game.getBoard().getInfieldIndexOfPiece(pieceClient2));
//tests, if the piece is in the first slot of the home
@@ -850,24 +846,24 @@ public void testOnlyEnterOwnHouse() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set the die in Game to 3
game.setDie(die3);
//sends the request-Dice-message
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//sends the requestMove-message for pieceClient1
System.out.println(game.getBoard().getInfieldIndexOfPiece(pieceHost1));
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
//tests if hostPiece1 is at idx 20 TODO false positive
assertTrue(game.getBoard().getInfield()[19].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceHost1);
assertEquals(game.getBoard().getInfield()[20].getOccupant(), pieceHost1);
}
/**
@@ -888,19 +884,19 @@ public void testActiveHomePiece() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set the die in Game to 2
game.setDie(die2);
//sends the request-Dice-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//sends the requestMove-message for pieceClient1
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDClient);
//tests if clientPiece1 is in the home at idx 3
assertTrue(game.getPlayerByColor(clientColor).getHomeNodes()[3].isOccupied());
@@ -922,10 +918,10 @@ public void testCantJumpOverFigureInHouse() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set activePlayer to client
game.setActiveColor(clientColor);
@@ -934,14 +930,14 @@ public void testCantJumpOverFigureInHouse() {
game.setDie(die4);
//send requestDice-Message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//sends requestMoveMessage with clientPiece 02
serverGameLogic.received(new RequestMoveMessage(pieceHost2),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost2), IDHost);
//tests, if the clientPiece02 is at idx 19
assertTrue(game.getBoard().getInfield()[19].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient2);
assertEquals(game.getBoard().getInfield()[20].getOccupant(), pieceClient2);
}
/**
@@ -959,10 +955,10 @@ public void testActiveHomePieceBlocked() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//set active player to client
game.setActiveColor(clientColor);
@@ -971,10 +967,10 @@ public void testActiveHomePieceBlocked() {
game.setDie(die3);
//sends the requestDice-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//sends the request MoveMessage
serverGameLogic.received(new RequestMoveMessage(pieceClient1),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceClient1), IDClient);
//tests if the piece is still at idx 2 in home
assertTrue(game.getPlayerByColor(clientColor).getHomeNodes()[1].isOccupied());
@@ -1005,22 +1001,22 @@ public void testOnStartingFieldWithShield() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//sends the requestDice-message
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//sends the moveMessage
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
//tests the position of the hostPiece1 and that shield is suppressed
assertTrue(game.getBoard().getInfield()[20].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient1);
assertEquals(game.getBoard().getInfield()[20].getOccupant(), pieceClient1);
assertEquals(pieceHost1.getShield(),ShieldState.SUPPRESSED);
assertEquals(pieceHost1.getShield(), ShieldState.SUPPRESSED);
}
/**
@@ -1047,25 +1043,25 @@ public void testThrowFigureWithShield() {
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//send requestDice
serverGameLogic.received(new RequestDieMessage(),IDHost);
serverGameLogic.received(new RequestDieMessage(), IDHost);
//send requestMove of hostPiece1
serverGameLogic.received(new RequestMoveMessage(pieceHost1),IDHost);
serverGameLogic.received(new RequestMoveMessage(pieceHost1), IDHost);
//tests if the clientPiece2 is still at idx 19 and hostPiece1 at idx 18 and clientPiece2 shield is still active
assertTrue(game.getBoard().getInfield()[19].isOccupied());
assertTrue(game.getBoard().getInfield()[18].isOccupied());
assertEquals(game.getBoard().getInfield()[18].getOccupant(),pieceHost1);
assertEquals(game.getBoard().getInfield()[19].getOccupant(),pieceClient2);
assertEquals(game.getBoard().getInfield()[18].getOccupant(), pieceHost1);
assertEquals(game.getBoard().getInfield()[19].getOccupant(), pieceClient2);
assertEquals(pieceClient2.getShield(),ShieldState.ACTIVE);
assertEquals(pieceClient2.getShield(), ShieldState.ACTIVE);
}
/**
@@ -1082,31 +1078,31 @@ public void testUseSwap() {
serverGameLogic.getGameState().getTurnState().setCurrentState(powerCardState);
//tests if the server is in selectPieces
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),powerCardState);
assertEquals(turnState.getCurrentState(), powerCardState);
//set activePlayer to Host
game.setActiveColor(hostColor);
//sends the requestPlayCard
serverGameLogic.received(new SelectCardMessage(swapCard),IDHost);
serverGameLogic.received(new SelectCardMessage(swapCard), IDHost);
//sends the selectedPiece-message
serverGameLogic.received(RequestPlayCardMessage.requestPlaySwap(pieceHost0.getUuid(),pieceClient0.getUuid()),IDHost);
serverGameLogic.received(RequestPlayCardMessage.requestPlaySwap(pieceHost0.getUuid(), pieceClient0.getUuid()), IDHost);
//tests if the piece at idx 25 is pieceHost0 and at idx 28 is pieceClient0
assertTrue(game.getBoard().getInfield()[25].isOccupied());
assertEquals(game.getBoard().getInfield()[25].getOccupant(),pieceHost0);
assertEquals(game.getBoard().getInfield()[25].getOccupant(), pieceHost0);
assertTrue(game.getBoard().getInfield()[28].isOccupied());
assertEquals(game.getBoard().getInfield()[28].getOccupant(),pieceClient0);
assertEquals(game.getBoard().getInfield()[28].getOccupant(), pieceClient0);
//tests if the server is in playPowerCard
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),playPowerCardState);
assertEquals(turnState.getCurrentState(), playPowerCardState);
}
/**
@@ -1123,26 +1119,26 @@ public void testUseShield() {
serverGameLogic.getGameState().getTurnState().setCurrentState(powerCardState);
//tests if the server is in selectPieces
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),powerCardState);
assertEquals(turnState.getCurrentState(), powerCardState);
//set activePlayer to Host
game.setActiveColor(hostColor);
//sends the requestPlayCard
serverGameLogic.received(new SelectCardMessage(shieldCard),IDHost);
serverGameLogic.received(new SelectCardMessage(shieldCard), IDHost);
//sends the selectedPiece-message
serverGameLogic.received(RequestPlayCardMessage.requestPlayShield(pieceHost0.getUuid()),IDHost);
serverGameLogic.received(RequestPlayCardMessage.requestPlayShield(pieceHost0.getUuid()), IDHost);
//tests if the piece at idx 28 has a shield
assertEquals(pieceHost0.getShield(),ShieldState.ACTIVE);
assertEquals(pieceHost0.getShield(), ShieldState.ACTIVE);
//tests if the server is in playPowerCard
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),playPowerCardState);
assertEquals(turnState.getCurrentState(), playPowerCardState);
}
/**
@@ -1169,31 +1165,31 @@ public void testLoseShield() {
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
//tests if the server is in selectPieces
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//send requestDice-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//send requestMove-message for clientPiece0
serverGameLogic.received(new RequestMoveMessage(pieceClient0),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceClient0), IDClient);
//tests if the server is in animation-state
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), gameState.getAnimationState());
//send 3 animationEndMessage
serverGameLogic.received(new AnimationEndMessage(),IDClient);
serverGameLogic.received(new AnimationEndMessage(),IDHost);
serverGameLogic.received(new AnimationEndMessage(),IDCyber);
serverGameLogic.received(new AnimationEndMessage(), IDClient);
serverGameLogic.received(new AnimationEndMessage(), IDHost);
serverGameLogic.received(new AnimationEndMessage(), IDCyber);
//test for new Player
assertEquals(serverGameLogic.getGame().getActiveColor(),hostColor);
assertEquals(serverGameLogic.getGame().getActiveColor(), hostColor);
//tests, if the shieldState is NONE
assertEquals(pieceHost1.getShield(),ShieldState.NONE);
assertEquals(pieceHost1.getShield(), ShieldState.NONE);
}
/**
@@ -1211,10 +1207,10 @@ public void testFinishedPiece() {
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
//tests if the server is in selectPieces
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//sets the active color to client
game.setActiveColor(clientColor);
@@ -1222,14 +1218,14 @@ public void testFinishedPiece() {
//set the dice to 2
game.setDie(die2);
//sends the requestDie-Message
serverGameLogic.received(new RequestDieMessage(),IDClient);
serverGameLogic.received(new RequestDieMessage(), IDClient);
//sends the requestMove-Message
serverGameLogic.received(new RequestMoveMessage(pieceClient1),IDClient);
serverGameLogic.received(new RequestMoveMessage(pieceClient1), IDClient);
//tests if the Piece is in the final position and is marked as home-finished
assertTrue(game.getPlayerByColor(clientColor).getHomeNodes()[3].isOccupied());
assertEquals(game.getPlayerByColor(clientColor).getHomeNodes()[3].getOccupant(), pieceClient1);
assertEquals(pieceClient1.getState(),PieceState.HOMEFINISHED);
assertEquals(pieceClient1.getState(), PieceState.HOMEFINISHED);
}
}

View File

@@ -2,20 +2,29 @@
//TODO important: set activePlayer, setPlayers, setPieces, setBonusCards
import org.junit.*;
import org.junit.Before;
import org.junit.Test;
import pp.mdga.game.*;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.server.ServerMessage;
import pp.mdga.message.client.*;
import pp.mdga.server.*;
import pp.mdga.server.automaton.*;
import pp.mdga.server.automaton.game.*;
import pp.mdga.message.server.ServerMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.ServerSender;
import pp.mdga.server.automaton.CeremonyState;
import pp.mdga.server.automaton.GameState;
import pp.mdga.server.automaton.InterruptState;
import pp.mdga.server.automaton.LobbyState;
import pp.mdga.server.automaton.game.AnimationState;
import pp.mdga.server.automaton.game.DetermineStartPlayerState;
import pp.mdga.server.automaton.game.TurnState;
import pp.mdga.server.automaton.game.turn.*;
import pp.mdga.server.automaton.game.turn.choosepiece.*;
import pp.mdga.server.automaton.game.turn.rolldice.*;
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
import pp.mdga.server.automaton.game.turn.rolldice.SecondRollState;
import pp.mdga.server.automaton.game.turn.rolldice.ThirdRollState;
import pp.mdga.visitor.Visitor;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* this test-class tests the Testcases T132-T169
@@ -98,7 +107,6 @@ public class ServerStateTest {
private WaitingPieceState waitingPieceState;
/**
* this method is used to initialize the attributes of this test-class
*/
@@ -172,14 +180,14 @@ public void accept(Visitor visitor) {
}
};
lobbyState = serverGameLogic.getLobbyState();
gameState = serverGameLogic.getGameState();
ceremonyState = serverGameLogic.getCeremonyState();
interruptState = serverGameLogic.getInterruptState();
lobbyState = serverGameLogic.getLobbyState();
gameState = serverGameLogic.getGameState();
ceremonyState = serverGameLogic.getCeremonyState();
interruptState = serverGameLogic.getInterruptState();
determineStartPlayerState = gameState.getDetermineStartPlayerState();
turnState = gameState.getTurnState();
animationState = gameState.getAnimationState();
determineStartPlayerState = gameState.getDetermineStartPlayerState();
turnState = gameState.getTurnState();
animationState = gameState.getAnimationState();
animationEnd = new AnimationEndMessage();
@@ -428,7 +436,7 @@ public void testCeremonyToServerStateEndState() {
/**
* this method tests that the server stays in DetermineStartPlayer, when issued messages
*
* <p>
* serverStateTest 10
*/
@Test
@@ -467,7 +475,7 @@ public void testDetermineStartPlayerToDetermineStartPlayer1() {
/**
* this method tests that the server stays in DetermineStartPlayer, when all players are ranked and two of the highest are even
*
* <p>
* serverStateTest 11
*/
@Test
@@ -801,7 +809,7 @@ public void testMovePieceToFirstRoll() {
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//tests if the activeColor is still Host
assertEquals(game.getActiveColor(),playerHostColor);
assertEquals(game.getActiveColor(), playerHostColor);
}
/**