Merge remote-tracking branch 'origin/development2' into development2
# Conflicts: # Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollState.java # Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java # Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
|
||||
public abstract class CeremonyStates extends ClientState {
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
protected CeremonyStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@@ -8,23 +8,38 @@ public class PodiumState extends CeremonyStates {
|
||||
|
||||
private final CeremonyState parent;
|
||||
|
||||
/**
|
||||
* This constructs a new PodiumState.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public PodiumState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (CeremonyState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client enters the PodiumState.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client exits the PodiumState.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the next button.
|
||||
*/
|
||||
@Override
|
||||
public void selectNext(){
|
||||
public void selectNext() {
|
||||
parent.setState(parent.getStatisticsState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,42 @@
|
||||
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.notification.StartDialogNotification;
|
||||
|
||||
public class StatisticsState extends CeremonyStates {
|
||||
|
||||
/**
|
||||
* This constructs a new StatisticsState.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public StatisticsState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client enters the StatisticsState.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client exits the StatisticsState.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the next button.
|
||||
*/
|
||||
@Override
|
||||
public void selectNext(){
|
||||
public void selectNext() {
|
||||
logic.addNotification(new StartDialogNotification());
|
||||
logic.setState(logic.getDialogs());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
|
||||
public abstract class DialogStates extends ClientState {
|
||||
|
||||
public DialogStates(ClientState parent, ClientGameLogic logic){
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public DialogStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,35 @@ public class LobbyState extends DialogStates {
|
||||
|
||||
private final DialogsState parent;
|
||||
|
||||
/**
|
||||
* The constructor of the LobbyState.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public LobbyState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (DialogsState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client enters the LobbyState.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
logic.send(new JoinedLobbyMessage(logic.getOwnPlayerName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client exits the LobbyState.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the leave button.
|
||||
*/
|
||||
@Override
|
||||
public void selectLeave() {
|
||||
parent.setState(parent.getStartDialog());
|
||||
@@ -40,26 +55,45 @@ public void selectLeave() {
|
||||
logic.send(new LeaveGameMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the color of the player.
|
||||
*
|
||||
* @param color the color of the player
|
||||
*/
|
||||
@Override
|
||||
public void selectTSK(Color color) {
|
||||
logic.send(new SelectTSKMessage(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client deselects the color of the player.
|
||||
*
|
||||
* @param color the color of the player
|
||||
*/
|
||||
@Override
|
||||
public void deselectTSK(Color color) {
|
||||
logic.send(new DeselectTSKMessage(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the ready button.
|
||||
*/
|
||||
@Override
|
||||
public void selectReady() {
|
||||
logic.send(new LobbyReadyMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the unready button.
|
||||
*/
|
||||
@Override
|
||||
public void selectUnready() {
|
||||
logic.send(new LobbyNotReadyMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client selects the start button.
|
||||
*/
|
||||
@Override
|
||||
public void selectStart() {
|
||||
if (logic.isHost() && logic.getGame().areAllReady()) {
|
||||
@@ -70,10 +104,15 @@ public void selectStart() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client receives a message.
|
||||
*
|
||||
* @param msg the message which was received
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
@@ -91,6 +130,11 @@ public void received(ServerStartGameMessage msg) {
|
||||
logic.setState(logic.getGameState());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client receives a message.
|
||||
*
|
||||
* @param msg the message which was received
|
||||
*/
|
||||
@Override
|
||||
public void received(LobbyPlayerJoinedMessage msg) {
|
||||
if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
|
||||
@@ -105,6 +149,11 @@ public void received(LobbyPlayerJoinedMessage msg) {
|
||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client receives a message.
|
||||
*
|
||||
* @param msg the message which was received
|
||||
*/
|
||||
@Override
|
||||
public void received(UpdateTSKMessage msg) {
|
||||
if (msg.isTaken()) {
|
||||
@@ -116,15 +165,24 @@ public void received(UpdateTSKMessage msg) {
|
||||
logic.getGame().getPlayers().get(msg.getId()).setColor(msg.getColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client receives a message.
|
||||
*
|
||||
* @param msg the message which was received
|
||||
*/
|
||||
@Override
|
||||
public void received(LobbyPlayerLeaveMessage msg) {
|
||||
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
|
||||
logic.getGame().getPlayers().remove(msg.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the client receives a message.
|
||||
*
|
||||
* @param msg the message which was received
|
||||
*/
|
||||
@Override
|
||||
public void received(UpdateReadyMessage msg) {
|
||||
//TODO server sendet kein update on UNready
|
||||
logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady()));
|
||||
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -11,23 +11,53 @@ public class AnimationState extends GameStates {
|
||||
|
||||
private final GameState parent;
|
||||
|
||||
private boolean spectator = false;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public AnimationState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (GameState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
spectator = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the spectator.
|
||||
*
|
||||
* @param spectator the spectator
|
||||
*/
|
||||
public void setSpectator(boolean spectator) {
|
||||
this.spectator = spectator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the animation end.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
logic.send(new AnimationEndMessage());
|
||||
parent.setState(parent.getWaiting());
|
||||
if (spectator){
|
||||
parent.setState(parent.getSpectator());
|
||||
} else {
|
||||
parent.setState(parent.getWaiting());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -19,82 +18,155 @@ public class DetermineStartPlayerState extends GameStates {
|
||||
private final WaitRankingState waitRankingState = new WaitRankingState(this, logic);
|
||||
private final Intro intro = new Intro(this, logic);
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public DetermineStartPlayerState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (GameState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the roll ranking dice.
|
||||
*
|
||||
* @return the roll ranking dice
|
||||
*/
|
||||
public RollRankingDiceState getRollRankingDice() {
|
||||
return rollRankingDiceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the wait ranking.
|
||||
*
|
||||
* @return the wait ranking
|
||||
*/
|
||||
public WaitRankingState getWaitRanking() {
|
||||
return waitRankingState;
|
||||
}
|
||||
|
||||
public DetermineStartPlayerStates getState(){
|
||||
/**
|
||||
* Gets the state.
|
||||
*
|
||||
* @return the state
|
||||
*/
|
||||
public DetermineStartPlayerStates getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public Intro getIntro(){
|
||||
/**
|
||||
* Gets the intro.
|
||||
*
|
||||
* @return the intro
|
||||
*/
|
||||
public Intro getIntro() {
|
||||
return intro;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent state.
|
||||
*
|
||||
* @return the parent state
|
||||
*/
|
||||
public GameState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
this.setState(this.rollRankingDiceState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
state = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state.
|
||||
*
|
||||
* @param state the state
|
||||
*/
|
||||
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;
|
||||
this.state.enter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dice.
|
||||
*/
|
||||
@Override
|
||||
public void selectDice() {
|
||||
state.selectDice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the animation end.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
state.selectAnimationEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the die message.
|
||||
*
|
||||
* @param msg the die message
|
||||
*/
|
||||
@Override
|
||||
public void received(DieMessage msg){
|
||||
public void received(DieMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ceremony message.
|
||||
*
|
||||
* @param msg the ceremony message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ranking roll again message.
|
||||
*
|
||||
* @param msg the ranking roll again message
|
||||
*/
|
||||
@Override
|
||||
public void received(RankingRollAgainMessage msg){
|
||||
public void received(RankingRollAgainMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ranking response message.
|
||||
*
|
||||
* @param msg the ranking response message
|
||||
*/
|
||||
@Override
|
||||
public void received(RankingResponseMessage msg){
|
||||
public void received(RankingResponseMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ranking result message.
|
||||
*
|
||||
* @param msg the ranking result message
|
||||
*/
|
||||
@Override
|
||||
public void received(ActivePlayerMessage msg){
|
||||
public void received(ActivePlayerMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,33 @@
|
||||
|
||||
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 {
|
||||
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public GameStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the power card.
|
||||
*
|
||||
* @param msg the play card message
|
||||
*/
|
||||
protected void handlePowerCard(PlayCardMessage msg) {
|
||||
if (msg.getCard().getCard().equals(BonusCard.TURBO)) {
|
||||
logic.getGame().setTurboFlag(true);
|
||||
@@ -37,10 +41,15 @@ protected void handlePowerCard(PlayCardMessage msg) {
|
||||
logic.getGame().getDiscardPile().add(msg.getCard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the shield.
|
||||
*
|
||||
* @param uuid the uuid
|
||||
*/
|
||||
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));
|
||||
@@ -51,6 +60,12 @@ private void handleShield(UUID uuid) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps the pieces.
|
||||
*
|
||||
* @param messageOwn the own piece
|
||||
* @param messageEnemy the enemy piece
|
||||
*/
|
||||
private void swapPieces(Piece messageOwn, Piece messageEnemy) {
|
||||
//swap Pieces in Model
|
||||
Board board = logic.getGame().getBoard();
|
||||
@@ -68,13 +83,19 @@ private void swapPieces(Piece messageOwn, Piece messageEnemy) {
|
||||
|
||||
}
|
||||
|
||||
private void checkShieldAfterSwap(Node node, Piece piece){
|
||||
if (node.isStart()){
|
||||
if (piece.isShielded()){
|
||||
/**
|
||||
* Checks the shield after the swap.
|
||||
*
|
||||
* @param node the node
|
||||
* @param piece the piece
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.GameState;
|
||||
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;
|
||||
@@ -15,48 +16,69 @@ public class SpectatorState extends GameStates {
|
||||
|
||||
private final GameState parent;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public SpectatorState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (GameState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
parent.getAnimation().setSpectator(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a CeremonyMessage.
|
||||
*
|
||||
* @param msg the ceremony message
|
||||
*/
|
||||
@Override
|
||||
public void received(CeremonyMessage msg) {
|
||||
logic.setState(logic.getCeremony());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a DieMessage.
|
||||
*
|
||||
* @param msg the die message
|
||||
*/
|
||||
@Override
|
||||
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));
|
||||
public void received(DieMessage msg) {
|
||||
logic.getGame().setDiceEyes(msg.getDiceEye());
|
||||
if (logic.getGame().getTurboFlag()) {
|
||||
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
|
||||
} else {
|
||||
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
|
||||
}
|
||||
|
||||
//stats
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
|
||||
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DieMessage msg) {
|
||||
//logic.getGame().setDiceEyes(msg.getDiceEye());
|
||||
// logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier()));
|
||||
if (msg.getDiceEye() == 6) {
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
|
||||
logic.getGame().getGameStatistics().increaseDiced6();
|
||||
}
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a PlayCardMessage.
|
||||
*
|
||||
* @param msg the play card message
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg) {
|
||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
|
||||
@@ -66,35 +88,86 @@ public void received(PlayCardMessage msg) {
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of an ActivePlayerMessage.
|
||||
*
|
||||
* @param msg the active player message
|
||||
*/
|
||||
@Override
|
||||
public void received(ActivePlayerMessage msg) {
|
||||
logic.addNotification(new ActivePlayerNotification(msg.getColor()));
|
||||
logic.getGame().setActiveColor(msg.getColor());
|
||||
parent.setState(parent.getAnimation());
|
||||
if (msg.getColor() == logic.getGame().getPlayers().get(logic.getOwnPlayerId()).getColor()) {
|
||||
parent.setState(parent.getTurn());
|
||||
} else {
|
||||
for (Piece piece : logic.getGame().getActivePlayer().getPieces()) {
|
||||
if (piece.isShielded() || piece.isSuppressed()) {
|
||||
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
|
||||
piece.setShield(ShieldState.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a MoveMessage.
|
||||
*
|
||||
* @param msg the move message
|
||||
*/
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
if (piece.getState().equals(PieceState.HOME)) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
Node pieceNode = logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex];
|
||||
|
||||
//gets the oldNode
|
||||
int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getActivePlayer().getHomeNodes()[homeIndex];
|
||||
//gets the targetNode
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
|
||||
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
} else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
|
||||
} else {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
|
||||
|
||||
//gets the targetNode
|
||||
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
|
||||
|
||||
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
|
||||
piece.setState(PieceState.HOMEFINISHED);
|
||||
} else {
|
||||
piece.setState(PieceState.HOME);
|
||||
}
|
||||
|
||||
oldNode.clearOccupant();
|
||||
targetNode.setOccupant(piece);
|
||||
}
|
||||
} else {
|
||||
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
|
||||
if (occ != null) {
|
||||
//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 (oldIndex == -1) {
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
|
||||
piece.setState(PieceState.ACTIVE);
|
||||
@@ -105,7 +178,17 @@ public void received(MoveMessage msg) {
|
||||
}
|
||||
//set new node
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isStart()) {
|
||||
if (piece.isShielded()) {
|
||||
piece.setShield(ShieldState.SUPPRESSED);
|
||||
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
|
||||
}
|
||||
} else if (piece.isSuppressed()) {
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
|
||||
}
|
||||
}
|
||||
System.out.println("send AnimationEndMessage");
|
||||
logic.getGame().setTurboFlag(false);
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
@@ -12,14 +12,22 @@
|
||||
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.message.server.CeremonyMessage;
|
||||
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.message.server.EndOfTurnMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.message.server.NoTurnMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.message.server.PossibleCardsMessage;
|
||||
import pp.mdga.message.server.PossiblePieceMessage;
|
||||
import pp.mdga.message.server.SelectPieceMessage;
|
||||
import pp.mdga.message.server.SpectatorMessage;
|
||||
import pp.mdga.message.server.StartPieceMessage;
|
||||
import pp.mdga.message.server.WaitPieceMessage;
|
||||
import pp.mdga.notification.RemoveShieldNotification;
|
||||
import pp.mdga.notification.AcquireCardNotification;
|
||||
import pp.mdga.notification.DrawCardNotification;
|
||||
|
||||
public class TurnState extends GameStates {
|
||||
|
||||
@@ -33,16 +41,25 @@ public class TurnState extends GameStates {
|
||||
private final RollDiceState rollDiceState = new RollDiceState(this, logic);
|
||||
private boolean canChangeTurbo = false;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public TurnState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (GameState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
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()));
|
||||
}
|
||||
@@ -51,147 +68,291 @@ public void enter() {
|
||||
this.setState(this.powerCardState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
state = null;
|
||||
}
|
||||
|
||||
public void setState(TurnStates state){
|
||||
/**
|
||||
* Sets the state.
|
||||
*
|
||||
* @param state the 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();
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dice.
|
||||
*/
|
||||
@Override
|
||||
public void selectDice(){
|
||||
public void selectDice() {
|
||||
state.selectDice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
public void selectPiece(Piece piece) {
|
||||
state.selectPiece(piece);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the card.
|
||||
*
|
||||
* @param card the card
|
||||
*/
|
||||
@Override
|
||||
public void selectCard(BonusCard card){
|
||||
public void selectCard(BonusCard card) {
|
||||
state.selectCard(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the animation end.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
state.selectAnimationEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the select piece message.
|
||||
*
|
||||
* @param msg the select piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectPieceMessage msg){
|
||||
public void received(SelectPieceMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the wait piece message.
|
||||
*
|
||||
* @param msg the wait piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(WaitPieceMessage msg){
|
||||
public void received(WaitPieceMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the start piece message.
|
||||
*
|
||||
* @param msg the start piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(StartPieceMessage msg){
|
||||
public void received(StartPieceMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the NoTurnMessage message.
|
||||
*
|
||||
* @param msg the NoTurnMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(NoTurnMessage msg){
|
||||
public void received(NoTurnMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the MoveMessage message.
|
||||
*
|
||||
* @param msg the MoveMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(MoveMessage msg){
|
||||
public void received(MoveMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the CeremonyMessage message.
|
||||
*
|
||||
* @param msg the CeremonyMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(CeremonyMessage msg){
|
||||
public void received(CeremonyMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the EndOfTurnMessage message.
|
||||
*
|
||||
* @param msg the EndOfTurnMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(EndOfTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the SpectatorMessage message.
|
||||
*
|
||||
* @param msg the SpectatorMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(SpectatorMessage msg){
|
||||
public void received(SpectatorMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the DiceAgainMessage message.
|
||||
*
|
||||
* @param msg the DiceAgainMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceAgainMessage msg){
|
||||
public void received(DiceAgainMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the PossibleCardsMessage message.
|
||||
*
|
||||
* @param msg the PossibleCardsMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(PossibleCardsMessage msg){
|
||||
public void received(PossibleCardsMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the PlayCardMessage message.
|
||||
*
|
||||
* @param msg the PlayCardMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg){
|
||||
public void received(PlayCardMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the DiceNow message.
|
||||
*
|
||||
* @param msg the DiceNow message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the DieMessage message.
|
||||
*
|
||||
* @param msg the DieMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(DieMessage msg){
|
||||
public void received(DieMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the PossiblePieceMessage message.
|
||||
*
|
||||
* @param msg the PossiblePieceMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(PossiblePieceMessage msg){
|
||||
public void received(PossiblePieceMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ChoosePieceStateMessage message.
|
||||
*
|
||||
* @param msg the ChoosePieceStateMessage message
|
||||
*/
|
||||
@Override
|
||||
public void received(ChoosePieceStateMessage msg){
|
||||
public void received(ChoosePieceStateMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChoosePieceState.
|
||||
*
|
||||
* @return the ChoosePieceState
|
||||
*/
|
||||
public ChoosePieceState getChoosePiece() {
|
||||
return choosePieceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MovePieceState.
|
||||
*
|
||||
* @return the MovePieceState
|
||||
*/
|
||||
public MovePieceState getMovePiece() {
|
||||
return movePieceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PlayPowerCardState.
|
||||
*
|
||||
* @return the PlayPowerCardState
|
||||
*/
|
||||
public PlayPowerCardState getPlayPowerCard() {
|
||||
return playPowerCardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PowerCardState.
|
||||
*
|
||||
* @return the PowerCardState
|
||||
*/
|
||||
public PowerCardState getPowerCard() {
|
||||
return powerCardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RollDiceState.
|
||||
*
|
||||
* @return the RollDiceState
|
||||
*/
|
||||
public RollDiceState getRollDice() {
|
||||
return rollDiceState;
|
||||
}
|
||||
|
||||
public GameState getParent(){
|
||||
/**
|
||||
* Gets the parent GameState.
|
||||
*
|
||||
* @return the parent GameState
|
||||
*/
|
||||
public GameState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public TurnStates getState(){
|
||||
/**
|
||||
* Gets the current TurnStates.
|
||||
*
|
||||
* @return the current TurnStates
|
||||
*/
|
||||
public TurnStates getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if turbo can be changed.
|
||||
*
|
||||
* @return true if turbo can be changed, false otherwise
|
||||
*/
|
||||
public boolean isCanChangeTurbo() {
|
||||
return canChangeTurbo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the turbo change flag.
|
||||
*
|
||||
* @param canChangeTurbo the new value for the turbo change flag
|
||||
*/
|
||||
public void setCanChangeTurbo(boolean canChangeTurbo) {
|
||||
this.canChangeTurbo = canChangeTurbo;
|
||||
}
|
||||
|
||||
@@ -10,38 +10,62 @@
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
/**
|
||||
* Represents the waiting state in the game.
|
||||
*/
|
||||
public class WaitingState extends GameStates {
|
||||
|
||||
private final GameState parent;
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
/**
|
||||
* Constructs a new WaitingState.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public WaitingState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (GameState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when entering the waiting state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when exiting the waiting state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a CeremonyMessage.
|
||||
*
|
||||
* @param msg the ceremony message
|
||||
*/
|
||||
@Override
|
||||
public void received(CeremonyMessage msg) {
|
||||
logic.setState(logic.getCeremony());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a DieMessage.
|
||||
*
|
||||
* @param msg the die message
|
||||
*/
|
||||
@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()));
|
||||
}
|
||||
|
||||
@@ -52,6 +76,11 @@ public void received(DieMessage msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a PlayCardMessage.
|
||||
*
|
||||
* @param msg the play card message
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg) {
|
||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
|
||||
@@ -61,15 +90,20 @@ public void received(PlayCardMessage msg) {
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of an ActivePlayerMessage.
|
||||
*
|
||||
* @param msg the active player message
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
@@ -77,11 +111,16 @@ public void received(ActivePlayerMessage msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a MoveMessage.
|
||||
*
|
||||
* @param msg the move message
|
||||
*/
|
||||
@Override
|
||||
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 +130,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 +147,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 +180,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()));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
import pp.mdga.client.gamestate.GameStates;
|
||||
|
||||
public abstract class DetermineStartPlayerStates extends GameStates {
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public DetermineStartPlayerStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -13,36 +13,56 @@ 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;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (DetermineStartPlayerState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entering RollRankingDiceState");
|
||||
logic.addNotification(new DiceNowNotification());
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Exiting RollRankingDiceState");
|
||||
isRolled=false;
|
||||
isRolled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dice.
|
||||
*/
|
||||
@Override
|
||||
public void selectDice(){
|
||||
if(!isRolled){
|
||||
public void selectDice() {
|
||||
if (!isRolled) {
|
||||
isRolled = true;
|
||||
logic.send(new RequestDieMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a DieMessage.
|
||||
*
|
||||
* @param msg the DieMessage
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -19,37 +20,62 @@ public class WaitRankingState extends DetermineStartPlayerStates {
|
||||
private final DetermineStartPlayerState parent;
|
||||
private boolean canChange = false;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public WaitRankingState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (DetermineStartPlayerState) parent;
|
||||
}
|
||||
|
||||
private void changeToIntro(){
|
||||
if(!canChange){
|
||||
/**
|
||||
* Changes the state to the intro state.
|
||||
*/
|
||||
private void changeToIntro() {
|
||||
if (!canChange) {
|
||||
canChange = true;
|
||||
return;
|
||||
}
|
||||
parent.setState(parent.getIntro());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entering WaitRankingState");
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
canChange = false;
|
||||
LOGGER.log(System.Logger.Level.INFO, "Exiting WaitRankingState");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a DiceNowMessage.
|
||||
*
|
||||
* @param msg the DiceNowMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
parent.setState(parent.getRollRankingDice());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a RankingResponseMessage.
|
||||
*
|
||||
* @param msg the RankingResponseMessage
|
||||
*/
|
||||
@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());
|
||||
@@ -57,14 +83,22 @@ public void received(RankingResponseMessage msg){
|
||||
logic.addNotification(new RankingResponceNotification(rankingResults));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the view has completed the animation.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
changeToIntro();
|
||||
logic.send(new AnimationEndMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends an ActivePlayerMessage.
|
||||
*
|
||||
* @param msg the ActivePlayerMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(ActivePlayerMessage msg){
|
||||
public void received(ActivePlayerMessage msg) {
|
||||
logic.getGame().setActiveColor(msg.getColor());
|
||||
changeToIntro();
|
||||
}
|
||||
|
||||
@@ -17,82 +17,157 @@ public class ChoosePieceState extends TurnStates {
|
||||
private final StartPieceState startPieceState = new StartPieceState(this, logic);
|
||||
private final WaitingPieceState waitingPieceState = new WaitingPieceState(this, logic);
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public ChoosePieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (TurnState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
this.setState(this.noPieceState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
currentState.exit();
|
||||
currentState= null;
|
||||
currentState = null;
|
||||
}
|
||||
|
||||
public void setState(ChoosePieceStates state){
|
||||
/**
|
||||
* Sets the state.
|
||||
*
|
||||
* @param state the 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();
|
||||
currentState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
public void selectPiece(Piece piece) {
|
||||
currentState.selectPiece(piece);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the select piece message.
|
||||
*
|
||||
* @param msg the select piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectPieceMessage msg){
|
||||
public void received(SelectPieceMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the wait piece message.
|
||||
*
|
||||
* @param msg the wait piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(WaitPieceMessage msg){
|
||||
public void received(WaitPieceMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the start piece message.
|
||||
*
|
||||
* @param msg the start piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(StartPieceMessage msg){
|
||||
public void received(StartPieceMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the end of turn message.
|
||||
*
|
||||
* @param msg the end of turn message
|
||||
*/
|
||||
@Override
|
||||
public void received(EndOfTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the dice now message.
|
||||
*
|
||||
* @param msg the dice now message
|
||||
*/
|
||||
@Override
|
||||
public void received(MoveMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
public NoPieceState getNoPiece(){
|
||||
/**
|
||||
* Receives the move message.
|
||||
*
|
||||
* @param msg the move message
|
||||
*/
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
currentState.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the no piece state.
|
||||
*/
|
||||
public NoPieceState getNoPiece() {
|
||||
return noPieceState;
|
||||
}
|
||||
|
||||
public SelectPieceState getSelectPiece(){
|
||||
/**
|
||||
* Returns the select piece state.
|
||||
*/
|
||||
public SelectPieceState getSelectPiece() {
|
||||
return selectPieceState;
|
||||
}
|
||||
|
||||
public StartPieceState getStartPiece(){
|
||||
/**
|
||||
* Returns the start piece state.
|
||||
*/
|
||||
public StartPieceState getStartPiece() {
|
||||
return startPieceState;
|
||||
}
|
||||
|
||||
public WaitingPieceState getWaitingPiece(){
|
||||
/**
|
||||
* Returns the waiting piece state.
|
||||
*/
|
||||
public WaitingPieceState getWaitingPiece() {
|
||||
return waitingPieceState;
|
||||
}
|
||||
|
||||
public ChoosePieceStates getState(){
|
||||
/**
|
||||
* Returns the current state.
|
||||
*/
|
||||
public ChoosePieceStates getState() {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public TurnState getParent(){
|
||||
/**
|
||||
* Returns the parent state.
|
||||
*/
|
||||
public TurnState getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,52 +4,95 @@
|
||||
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 {
|
||||
|
||||
private final TurnState parent;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public MovePieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (TurnState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the animation end.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
logic.send(new AnimationEndMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the ceremony message.
|
||||
*
|
||||
* @param msg the ceremony message
|
||||
*/
|
||||
@Override
|
||||
public void received(CeremonyMessage msg){
|
||||
public void received(CeremonyMessage msg) {
|
||||
logic.setState(logic.getCeremony());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the end of turn message.
|
||||
*
|
||||
* @param msg the end of turn message
|
||||
*/
|
||||
@Override
|
||||
public void received(EndOfTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg) {
|
||||
parent.getParent().setState(parent.getParent().getWaiting());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the spectator message.
|
||||
*
|
||||
* @param msg the spectator message
|
||||
*/
|
||||
@Override
|
||||
public void received(SpectatorMessage msg){
|
||||
public void received(SpectatorMessage msg) {
|
||||
parent.getParent().setState(parent.getParent().getSpectator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the dice now message.
|
||||
*
|
||||
* @param msg the dice now message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
parent.setState(parent.getRollDice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent state.
|
||||
*
|
||||
* @return the parent state
|
||||
*/
|
||||
public TurnState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -17,14 +15,23 @@ public class PlayPowerCardState extends TurnStates {
|
||||
private PlayCardMessage playCardMessage;
|
||||
private int extraAnimationCounter = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param parent parent state
|
||||
* @param logic game logic
|
||||
*/
|
||||
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (TurnState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter the state
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
if(playCardMessage.getCard().getCard().equals(BonusCard.SWAP)) {
|
||||
if (playCardMessage.getCard().getCard().equals(BonusCard.SWAP)) {
|
||||
extraAnimationCounter++;
|
||||
}
|
||||
|
||||
@@ -33,18 +40,29 @@ public void enter() {
|
||||
handlePowerCard(playCardMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
playCardMessage = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the power card
|
||||
*
|
||||
* @param playCardMessage the play card message
|
||||
*/
|
||||
public void setPlayCard(PlayCardMessage playCardMessage) {
|
||||
this.playCardMessage = playCardMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* The view has finished its animation
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
if(extraAnimationCounter > 0) {
|
||||
public void selectAnimationEnd() {
|
||||
if (extraAnimationCounter > 0) {
|
||||
extraAnimationCounter--;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,78 +23,139 @@ public class PowerCardState extends TurnStates {
|
||||
private final ShieldState shieldState = new ShieldState(this, logic);
|
||||
private final SwapState swapState = new SwapState(this, logic);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public PowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (TurnState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
this.setState(this.choosePowerCardState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
public void exit() {
|
||||
state.exit();
|
||||
state = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state.
|
||||
*
|
||||
* @param state the state
|
||||
*/
|
||||
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();
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the possible cards message.
|
||||
*
|
||||
* @param msg the possible cards message
|
||||
*/
|
||||
@Override
|
||||
public void received(PossibleCardsMessage msg){
|
||||
public void received(PossibleCardsMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the play card message.
|
||||
*
|
||||
* @param msg the play card message
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg){
|
||||
public void received(PlayCardMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the dice now message.
|
||||
*
|
||||
* @param msg the dice now message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the possible piece message.
|
||||
*
|
||||
* @param msg the possible piece message
|
||||
*/
|
||||
@Override
|
||||
public void received(PossiblePieceMessage msg){
|
||||
public void received(PossiblePieceMessage msg) {
|
||||
state.received(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the card.
|
||||
*
|
||||
* @param card the card
|
||||
*/
|
||||
@Override
|
||||
public void selectCard(BonusCard card) {
|
||||
state.selectCard(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece) {
|
||||
state.selectPiece(piece);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the choose power card state.
|
||||
*/
|
||||
public ChoosePowerCardState getChoosePowerCard() {
|
||||
return choosePowerCardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shield state.
|
||||
*/
|
||||
public ShieldState getShield() {
|
||||
return shieldState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the swap state.
|
||||
*/
|
||||
public SwapState getSwap() {
|
||||
return swapState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent state.
|
||||
*/
|
||||
public TurnState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state.
|
||||
*/
|
||||
public PowerCardStates getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -17,65 +17,107 @@ public class RollDiceState extends TurnStates {
|
||||
private final TurnState parent;
|
||||
private boolean isRolled = false;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public RollDiceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (TurnState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
isRolled = false;
|
||||
logic.addNotification(new DiceNowNotification());
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
logic.getGame().setDiceModifier(1);
|
||||
isRolled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent state.
|
||||
*
|
||||
* @return the parent state
|
||||
*/
|
||||
public TurnState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dice.
|
||||
*/
|
||||
@Override
|
||||
public void selectDice(){
|
||||
if (!isRolled){
|
||||
public void selectDice() {
|
||||
if (!isRolled) {
|
||||
isRolled = true;
|
||||
logic.send(new RequestDieMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the die message.
|
||||
*
|
||||
* @param msg the die message
|
||||
*/
|
||||
@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()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the animation end.
|
||||
*/
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
public void selectAnimationEnd() {
|
||||
logic.send(new AnimationEndMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the choose piece state message.
|
||||
*
|
||||
* @param msg the choose piece state message
|
||||
*/
|
||||
@Override
|
||||
public void received(ChoosePieceStateMessage msg){
|
||||
public void received(ChoosePieceStateMessage msg) {
|
||||
parent.setState(parent.getChoosePiece());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the no turn message.
|
||||
*
|
||||
* @param msg the no turn message
|
||||
*/
|
||||
@Override
|
||||
public void received(NoTurnMessage msg){
|
||||
public void received(NoTurnMessage msg) {
|
||||
parent.getParent().setState(parent.getParent().getWaiting());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the dice now message.
|
||||
*
|
||||
* @param msg the dice now message
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
public void received(DiceNowMessage msg) {
|
||||
isRolled = false;
|
||||
logic.addNotification(new DiceNowNotification());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,14 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.GameStates;
|
||||
|
||||
public abstract class TurnStates extends GameStates {
|
||||
public abstract class TurnStates extends GameStates {
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public TurnStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
import pp.mdga.client.gamestate.turnstate.TurnStates;
|
||||
|
||||
public abstract class ChoosePieceStates extends TurnStates {
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public ChoosePieceStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
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.DiceNowMessage;
|
||||
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.DiceNowNotification;
|
||||
import pp.mdga.notification.SelectableMoveNotification;
|
||||
import pp.mdga.notification.WaitMoveNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,21 +23,36 @@ public class NoPieceState extends ChoosePieceStates {
|
||||
|
||||
private final ChoosePieceState parent;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public NoPieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (ChoosePieceState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entering NoPieceState");
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectPieceMessage msg) {
|
||||
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new));
|
||||
@@ -46,16 +63,24 @@ public void received(SelectPieceMessage msg) {
|
||||
parent.setState(parent.getSelectPiece());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dice.
|
||||
*/
|
||||
@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))));
|
||||
parent.setState(parent.getWaitingPiece());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a DiceNowMessage.
|
||||
*
|
||||
* @param msg the DiceNowMessage
|
||||
*/
|
||||
@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<>();
|
||||
@@ -69,9 +94,24 @@ public void received(StartPieceMessage msg){
|
||||
parent.setState(parent.getStartPiece());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a DiceNowMessage.
|
||||
*
|
||||
* @param msg the DiceNowMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(EndOfTurnMessage msg){
|
||||
public void received(EndOfTurnMessage msg) {
|
||||
logic.getGame().setTurboFlag(false);
|
||||
parent.getParent().getParent().setState(parent.getParent().getParent().getWaiting());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a DiceNowMessage.
|
||||
*
|
||||
* @param msg the DiceNowMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceNowMessage msg){
|
||||
parent.getParent().setState(parent.getParent().getRollDice());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,25 +18,47 @@ public class SelectPieceState extends ChoosePieceStates {
|
||||
private ArrayList<Piece> possiblePieces;
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public SelectPieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (ChoosePieceState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
possiblePieces = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the possible pieces.
|
||||
*
|
||||
* @param possiblePieces the possible pieces
|
||||
*/
|
||||
public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
|
||||
this.possiblePieces = possiblePieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece) {
|
||||
if (possiblePieces.contains(piece)) {
|
||||
@@ -50,6 +66,11 @@ public void selectPiece(Piece piece) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a MoveMessage.
|
||||
*
|
||||
* @param msg the MoveMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
@@ -63,29 +84,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 +110,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 +128,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()));
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -24,35 +17,61 @@ public class StartPieceState extends ChoosePieceStates {
|
||||
private final ChoosePieceState parent;
|
||||
private Piece moveablePiece;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public StartPieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (ChoosePieceState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
moveablePiece = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the moveable piece.
|
||||
*
|
||||
* @param moveablePiece the moveable piece
|
||||
*/
|
||||
public void setMoveablePiece(Piece moveablePiece) {
|
||||
this.moveablePiece = moveablePiece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
if(moveablePiece.equals(piece)){
|
||||
public void selectPiece(Piece piece) {
|
||||
if (moveablePiece.equals(piece)) {
|
||||
logic.send(new RequestMoveMessage(piece));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the move message.
|
||||
*
|
||||
* @param msg the move message
|
||||
*/
|
||||
@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 +81,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()));
|
||||
|
||||
@@ -7,46 +7,64 @@
|
||||
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;
|
||||
private Piece moveablePiece;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public WaitingPieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (ChoosePieceState) parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
moveablePiece = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the moveable piece.
|
||||
*
|
||||
* @param piece the moveable piece
|
||||
*/
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
public void selectPiece(Piece piece) {
|
||||
logic.send(new RequestMoveMessage(piece));
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the move message.
|
||||
*
|
||||
* @param msg the move message
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
import pp.mdga.client.gamestate.turnstate.TurnStates;
|
||||
|
||||
public abstract class PowerCardStates extends TurnStates {
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public PowerCardStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -20,26 +18,48 @@ public class ShieldState extends PowerCardStates {
|
||||
|
||||
private ArrayList<Piece> possiblePieces;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public ShieldState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (PowerCardState) parent;
|
||||
possiblePieces = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
logic.addNotification(new SelectableShieldNotification(possiblePieces.stream().map(Piece::getUuid).toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
possiblePieces = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the possible pieces.
|
||||
*
|
||||
* @param possiblePieces the possible pieces
|
||||
*/
|
||||
public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
|
||||
this.possiblePieces = possiblePieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
public void selectPiece(Piece piece) {
|
||||
if (possiblePieces.contains(piece)) {
|
||||
// logic.send(RequestPlayCardMessage.requestPlayShield(piece.getUuid()));
|
||||
@@ -51,7 +71,11 @@ public void selectPiece(Piece piece) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the server sends a PlayCardMessage.
|
||||
*
|
||||
* @param msg the PlayCardMessage
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg) {
|
||||
parent.getParent().getPlayPowerCard().setPlayCard(msg);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -24,6 +22,12 @@ public class SwapState extends PowerCardStates {
|
||||
private Piece selectedOwnPiece;
|
||||
private Piece selectedEnemyPiece;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the client game logic
|
||||
*/
|
||||
public SwapState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.parent = (PowerCardState) parent;
|
||||
@@ -33,6 +37,9 @@ public SwapState(ClientState parent, ClientGameLogic logic) {
|
||||
selectedEnemyPiece = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the state.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entering SwapState");
|
||||
@@ -43,6 +50,9 @@ public void enter() {
|
||||
selectedEnemyPiece = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the state.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Exiting SwapState");
|
||||
@@ -50,32 +60,52 @@ public void exit() {
|
||||
possibleEnemyPieces.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the possible own pieces.
|
||||
*
|
||||
* @param possibleOwnPieces the possible own pieces
|
||||
*/
|
||||
public void setPossibleOwnPieces(ArrayList<Piece> possibleOwnPieces) {
|
||||
this.possibleOwnPieces = possibleOwnPieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the possible enemy pieces.
|
||||
*
|
||||
* @param possibleEnemyPieces the possible enemy pieces
|
||||
*/
|
||||
public void setPossibleEnemyPieces(ArrayList<Piece> possibleEnemyPieces) {
|
||||
this.possibleEnemyPieces = possibleEnemyPieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the piece.
|
||||
*
|
||||
* @param piece the piece
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a card
|
||||
*
|
||||
* @param msg card message
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayCardMessage msg) {
|
||||
parent.getParent().getPlayPowerCard().setPlayCard(msg);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public void setOccupant(Piece occupant) {
|
||||
this.occupant = occupant;
|
||||
}
|
||||
|
||||
public boolean isBonus(){
|
||||
public boolean isBonus() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ public class ChoosePieceStateMessage extends ServerMessage {
|
||||
public ChoosePieceStateMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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 + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public IncorrectRequestMessage() {
|
||||
*
|
||||
* @return the id of the error message
|
||||
*/
|
||||
public int getId(){
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/**
|
||||
* GameNotification class
|
||||
*/
|
||||
public class GameNotification extends Notification{
|
||||
public class GameNotification extends Notification {
|
||||
|
||||
private final Color ownColor;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class LobbyReadyNotification extends Notification{
|
||||
public class LobbyReadyNotification extends Notification {
|
||||
|
||||
/**
|
||||
* The color of the player.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
public class TurboActiveNotification extends Notification{
|
||||
public class TurboActiveNotification extends Notification {
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ServerGameLogic implements ClientInterpreter {
|
||||
public class ServerGameLogic implements ClientInterpreter {
|
||||
/**
|
||||
* Constants.
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
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;
|
||||
@@ -55,7 +52,12 @@ public void exit() {
|
||||
public void initializeGame() {
|
||||
for (var player : this.logic.getGame().getPlayers().values()) {
|
||||
player.initialize();
|
||||
player.addHandCard(this.logic.getGame().draw());
|
||||
PowerCard card = this.logic.getGame().draw();
|
||||
if (card == null) {
|
||||
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
|
||||
} else {
|
||||
player.addHandCard(card);
|
||||
}
|
||||
|
||||
Piece piece = player.getPieces()[0];
|
||||
player.getWaitingArea()[0] = null;
|
||||
@@ -98,8 +100,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 +133,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 +171,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.Resources;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.message.server.ActivePlayerMessage;
|
||||
import pp.mdga.message.server.DiceNowMessage;
|
||||
import pp.mdga.message.server.EndOfTurnMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
@@ -22,6 +24,11 @@ public NoTurnState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic)
|
||||
super(choosePieceAutomaton, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to end the turn of the active player and determine a new active player
|
||||
*
|
||||
* @param color the color of the current active player
|
||||
*/
|
||||
private void setActivePlayer(Color color) {
|
||||
if (!logic.getGame().getPlayerByColor(color.next(logic.getGame())).isFinished()) {
|
||||
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next(logic.getGame()));
|
||||
@@ -38,8 +45,13 @@ private void setActivePlayer(Color color) {
|
||||
@Override
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered NoTurnState state.");
|
||||
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new EndOfTurnMessage());
|
||||
setActivePlayer(logic.getGame().getActiveColor());
|
||||
if (logic.getGame().getDiceEyes() == Resources.MAX_EYES){
|
||||
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new DiceNowMessage());
|
||||
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getRollDiceState());
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new EndOfTurnMessage());
|
||||
setActivePlayer(logic.getGame().getActiveColor());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.server.DrawCardMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.message.server.SelectPieceMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
@@ -48,8 +49,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 +78,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 +94,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 +102,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];
|
||||
@@ -142,14 +138,21 @@ public void received(RequestMoveMessage msg, int from) {
|
||||
if (targetNode.isBonus()) {
|
||||
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
|
||||
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if (p.getColor() == logic.getGame().getActiveColor()) {
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
if (cardToDraw == null) {
|
||||
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
|
||||
} else {
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
} else {
|
||||
if (cardToDraw == null) {
|
||||
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.server.DrawCardMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.message.server.StartPieceMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
@@ -70,14 +71,21 @@ public void received(RequestMoveMessage msg, int from) {
|
||||
if (targetNode.isBonus()) {
|
||||
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
|
||||
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
for (Player p : logic.getGame().getPlayersAsList()) {
|
||||
if (p.getColor() == logic.getGame().getActiveColor()) {
|
||||
PowerCard cardToDraw = logic.getGame().draw();
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
if (cardToDraw == null) {
|
||||
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
|
||||
} else {
|
||||
p.addHandCard(cardToDraw);
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
|
||||
}
|
||||
} else {
|
||||
if (cardToDraw == null) {
|
||||
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -91,6 +89,24 @@ public void received(AnimationEndMessage msg, int from) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the isDied boolean.
|
||||
*
|
||||
* @return the isDied boolean.
|
||||
*/
|
||||
public boolean isDied() {
|
||||
return isDied;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set the isDied boolean.
|
||||
*
|
||||
* @param isDied as a boolean.
|
||||
*/
|
||||
public void setIsDied(boolean isDied) {
|
||||
this.isDied = isDied;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the movabelPieces
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,6 +7,7 @@ incorrect.request.3=Selected to many or wrong pieces.
|
||||
incorrect.request.4=Did not select exactly 2 pieces or selected wrong pieces.
|
||||
incorrect.request.5=Cannot start game because not everyone is ready.
|
||||
incorrect.request.6=You are alone in this Lobby.
|
||||
incorrect.request.7=The draw pile is empty.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,3 +7,4 @@ incorrect.request.3=Du hast zuviele, oder eine falsche Figur ausgew
|
||||
incorrect.request.4=Du hast nicht genau zwei Figuren, oder falsche Figuren ausgewählt.
|
||||
incorrect.request.5=Du kannst das Spiel nicht starten, da nicht alle Spieler bereit sind.
|
||||
incorrect.request.6=Du bist alleine in dieser Lobby.
|
||||
incorrect.request.7=Der Nachziehstapel ist leer.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user