added more functionality to the client state machine and implemeted the first notifications
This commit is contained in:
@@ -89,13 +89,13 @@ private void handleGame(Notification notification) {
|
|||||||
} else if (notification instanceof MovePieceNotification) {
|
} else if (notification instanceof MovePieceNotification) {
|
||||||
MovePieceNotification n = (MovePieceNotification)notification;
|
MovePieceNotification n = (MovePieceNotification)notification;
|
||||||
//gameView.getBoardHandler().movePiece(n.get); //TODO
|
//gameView.getBoardHandler().movePiece(n.get); //TODO
|
||||||
} else if (notification instanceof MoveThrowPieceNotification) {
|
//TODO: } else if (notification instanceof MoveThrowPieceNotification) {
|
||||||
MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification;
|
//TODO: MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification;
|
||||||
//gameView.getBoardHandler().throwPiece(n.); //TODO
|
//gameView.getBoardHandler().throwPiece(n.); //TODO
|
||||||
} else if (notification instanceof NoShieldNotification) {
|
} else if (notification instanceof NoShieldNotification) {
|
||||||
NoShieldNotification n = (NoShieldNotification)notification;
|
NoShieldNotification n = (NoShieldNotification)notification;
|
||||||
gameView.getBoardHandler().unshieldPiece(n.getPieceId());
|
gameView.getBoardHandler().unshieldPiece(n.getPieceId());
|
||||||
} else if (notification instanceof PieceInGameNotification) {
|
//TODO:} else if (notification instanceof PieceInGameNotification) {
|
||||||
// Handle PieceInGameNotification
|
// Handle PieceInGameNotification
|
||||||
} else if (notification instanceof PlayCardNotification) {
|
} else if (notification instanceof PlayCardNotification) {
|
||||||
// Handle PlayCardNotification
|
// Handle PlayCardNotification
|
||||||
@@ -107,7 +107,7 @@ private void handleGame(Notification notification) {
|
|||||||
// Handle RollDiceNotification
|
// Handle RollDiceNotification
|
||||||
} else if (notification instanceof SelectableCardsNotification) {
|
} else if (notification instanceof SelectableCardsNotification) {
|
||||||
// Handle SelectableCardsNotification
|
// Handle SelectableCardsNotification
|
||||||
} else if (notification instanceof SelectablePiecesNotification) {
|
//TODO: } else if (notification instanceof SelectablePiecesNotification) {
|
||||||
// Handle SelectablePiecesNotification
|
// Handle SelectablePiecesNotification
|
||||||
} else if (notification instanceof ShieldActiveNotification) {
|
} else if (notification instanceof ShieldActiveNotification) {
|
||||||
ShieldActiveNotification n = (ShieldActiveNotification)notification;
|
ShieldActiveNotification n = (ShieldActiveNotification)notification;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
|
import pp.mdga.game.BonusCard;
|
||||||
import pp.mdga.game.Color;
|
import pp.mdga.game.Color;
|
||||||
import pp.mdga.game.Game;
|
import pp.mdga.game.Game;
|
||||||
import pp.mdga.game.Piece;
|
import pp.mdga.game.Piece;
|
||||||
@@ -19,6 +20,7 @@ public class ClientGameLogic implements ServerInterpreter {
|
|||||||
private final ClientSender clientSender;
|
private final ClientSender clientSender;
|
||||||
private ClientState state;
|
private ClientState state;
|
||||||
private final ArrayList<Notification> notifications = new ArrayList<>();
|
private final ArrayList<Notification> notifications = new ArrayList<>();
|
||||||
|
private boolean isHost;
|
||||||
|
|
||||||
private final DialogsState dialogsState = new DialogsState(null, this);
|
private final DialogsState dialogsState = new DialogsState(null, this);
|
||||||
private final GameState gameState = new GameState(null, this);
|
private final GameState gameState = new GameState(null, this);
|
||||||
@@ -59,6 +61,14 @@ public ClientState getState(){
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isHost(){
|
||||||
|
return isHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(boolean isHost){
|
||||||
|
this.isHost = isHost;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(ActivePlayerMessage msg) {
|
public void received(ActivePlayerMessage msg) {
|
||||||
state.received(msg);
|
state.received(msg);
|
||||||
@@ -201,16 +211,15 @@ public void received(SpectatorMessage msg) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(SelectPieceMessage msg) {
|
public void received(SelectPieceMessage msg) {
|
||||||
|
state.received(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectPiece(UUID pieceId){
|
public void selectPiece(UUID pieceId){
|
||||||
state.selectPiece(getPiece(pieceId));
|
state.selectPiece(getPiece(pieceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement
|
public void selectCard(BonusCard card){
|
||||||
public void selectCard(UUID cardId){
|
state.selectCard(card);
|
||||||
state.selectCard(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectTsk(Color color){
|
public void selectTsk(Color color){
|
||||||
@@ -226,7 +235,7 @@ public void selectName(String name){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void selectReady(boolean ready){
|
public void selectReady(boolean ready){
|
||||||
state.selectReady();
|
state.selectReady(ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectHost(String name){
|
public void selectHost(String name){
|
||||||
@@ -255,6 +264,12 @@ public void setState(ClientState state){
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enterInterrupt(){
|
||||||
|
interruptState.enter();
|
||||||
|
interruptState.setPreviousState(state);
|
||||||
|
this.state = interruptState;
|
||||||
|
}
|
||||||
|
|
||||||
public GameState getGameState(){
|
public GameState getGameState(){
|
||||||
return gameState;
|
return gameState;
|
||||||
}
|
}
|
||||||
@@ -275,4 +290,8 @@ public Notification getNotification(){
|
|||||||
return notifications.remove(0);
|
return notifications.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addNotification(Notification notification){
|
||||||
|
notifications.add(notification);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ public void setName(String name) {
|
|||||||
LOGGER.log(Level.DEBUG, "Setting name not allowed.");
|
LOGGER.log(Level.DEBUG, "Setting name not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectReady() {
|
public void selectReady(boolean ready) {
|
||||||
LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
|
LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,15 @@
|
|||||||
import pp.mdga.game.Player;
|
import pp.mdga.game.Player;
|
||||||
import pp.mdga.message.server.LobbyPlayerJoinMessage;
|
import pp.mdga.message.server.LobbyPlayerJoinMessage;
|
||||||
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
||||||
|
import pp.mdga.message.server.UpdateReadyMessage;
|
||||||
|
import pp.mdga.message.server.UpdateTSKMessage;
|
||||||
|
|
||||||
public class DialogsState extends ClientState {
|
public class DialogsState extends ClientState {
|
||||||
|
|
||||||
private DialogStates currentState;
|
private DialogStates currentState;
|
||||||
|
|
||||||
private Player ownPlayer;
|
private int ownPlayerID;
|
||||||
|
private String ownPlayerName;
|
||||||
|
|
||||||
private final LobbyState lobbyState = new LobbyState(this, logic);
|
private final LobbyState lobbyState = new LobbyState(this, logic);
|
||||||
private final NetworkDialogState networkDialogState = new NetworkDialogState(this, logic);
|
private final NetworkDialogState networkDialogState = new NetworkDialogState(this, logic);
|
||||||
@@ -31,6 +34,8 @@ public void exit(){
|
|||||||
@Override
|
@Override
|
||||||
public void enter(){
|
public void enter(){
|
||||||
currentState = startDialogState;
|
currentState = startDialogState;
|
||||||
|
ownPlayerID = 0;
|
||||||
|
ownPlayerName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(DialogStates newState){
|
public void setState(DialogStates newState){
|
||||||
@@ -39,8 +44,16 @@ public void setState(DialogStates newState){
|
|||||||
currentState = newState;
|
currentState = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getOwnPlayer() {
|
public int getOwnPlayerId() {
|
||||||
return ownPlayer;
|
return ownPlayerID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnPlayerName() {
|
||||||
|
return ownPlayerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnPlayerName(String ownPlayerName) {
|
||||||
|
this.ownPlayerName = ownPlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LobbyState getLobby() {
|
public LobbyState getLobby() {
|
||||||
@@ -69,4 +82,18 @@ public void received(LobbyPlayerJoinMessage msg){
|
|||||||
public void received(LobbyPlayerLeaveMessage msg){
|
public void received(LobbyPlayerLeaveMessage msg){
|
||||||
currentState.received(msg);
|
currentState.received(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(UpdateTSKMessage msg){
|
||||||
|
currentState.received(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(UpdateReadyMessage msg){
|
||||||
|
currentState.received(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DialogStates getState() {
|
||||||
|
return currentState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
import pp.mdga.client.gameState.*;
|
import pp.mdga.client.gameState.*;
|
||||||
|
import pp.mdga.message.server.PauseGameMessage;
|
||||||
|
import pp.mdga.notification.InterruptNotification;
|
||||||
|
|
||||||
public class GameState extends ClientState {
|
public class GameState extends ClientState {
|
||||||
|
|
||||||
@@ -38,6 +40,16 @@ public void selectAnimationEnd(){
|
|||||||
state.selectAnimationEnd();
|
state.selectAnimationEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(PauseGameMessage msg){
|
||||||
|
logic.enterInterrupt();
|
||||||
|
logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameStates getState(){
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
public AnimationState getAnimation() {
|
public AnimationState getAnimation() {
|
||||||
return animationState;
|
return animationState;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,36 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
|
import pp.mdga.message.server.ResumeGameMessage;
|
||||||
|
import pp.mdga.notification.ResumeNotification;
|
||||||
|
|
||||||
public class InterruptState extends ClientState {
|
public class InterruptState extends ClientState {
|
||||||
|
|
||||||
|
private ClientState previousState;
|
||||||
|
|
||||||
public InterruptState(ClientState parent, ClientGameLogic logic) {
|
public InterruptState(ClientState parent, ClientGameLogic logic) {
|
||||||
super(parent, logic);
|
super(parent, logic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
previousState = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
previousState = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousState(ClientState previousState) {
|
||||||
|
this.previousState = previousState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientState getPreviousState() {
|
||||||
|
return previousState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void received(ResumeGameMessage msg) {
|
||||||
|
//TODO: logic.addNotification(new ResumeNotification());
|
||||||
|
logic.setState(previousState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
import pp.mdga.message.server.LobbyPlayerJoinMessage;
|
import pp.mdga.message.server.LobbyPlayerJoinMessage;
|
||||||
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
import pp.mdga.message.server.LobbyPlayerLeaveMessage;
|
||||||
import pp.mdga.message.server.ServerStartGameMessage;
|
import pp.mdga.message.server.ServerStartGameMessage;
|
||||||
|
import pp.mdga.message.server.UpdateReadyMessage;
|
||||||
|
import pp.mdga.message.server.UpdateTSKMessage;
|
||||||
|
import pp.mdga.notification.TskSelectNotification;
|
||||||
|
import pp.mdga.notification.TskUnselectNotification;
|
||||||
|
|
||||||
public class LobbyState extends DialogStates {
|
public class LobbyState extends DialogStates {
|
||||||
|
|
||||||
@@ -21,12 +25,10 @@ public LobbyState(ClientState parent, ClientGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,7 +47,7 @@ public void deselectTSK(Color color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectReady() {
|
public void selectReady(boolean ready) {
|
||||||
logic.send(new LobbyReadyMessage());
|
logic.send(new LobbyReadyMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +71,21 @@ public void received(LobbyPlayerJoinMessage msg){
|
|||||||
logic.getGame().getPlayers().put(msg.getId(), new Player(msg.getName()));
|
logic.getGame().getPlayers().put(msg.getId(), new Player(msg.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(UpdateTSKMessage msg){
|
||||||
|
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
|
||||||
|
logic.getGame().getPlayers().get(msg.getId()).setColor(msg.getColor());
|
||||||
|
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(LobbyPlayerLeaveMessage msg){
|
public void received(LobbyPlayerLeaveMessage msg){
|
||||||
|
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
|
||||||
logic.getGame().getPlayers().remove(msg.getId());
|
logic.getGame().getPlayers().remove(msg.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(UpdateReadyMessage msg){
|
||||||
|
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,21 @@ public void exit() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void selectJoin(String name) {
|
public void selectJoin(String name) {
|
||||||
parent.getOwnPlayer().setName(name);
|
parent.setOwnPlayerName(name);
|
||||||
parent.setState(parent.getNetworkDialog());
|
parent.setState(parent.getNetworkDialog());
|
||||||
|
logic.setHost(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void selectHost(String name) {
|
public void selectHost(String name) {
|
||||||
parent.getOwnPlayer().setName(name);
|
parent.setOwnPlayerName(name);
|
||||||
parent.setState(parent.getLobby());
|
parent.setState(parent.getLobby());
|
||||||
|
logic.setHost(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void selectLeave() {
|
public void selectLeave() {
|
||||||
parent.exit();
|
parent.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public void enter() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
currentState= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(ChoosePieceStates state){
|
public void setState(ChoosePieceStates state){
|
||||||
@@ -52,6 +52,10 @@ public WaitingPieceState getWaitingPiece(){
|
|||||||
return waitingPieceState;
|
return waitingPieceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChoosePieceStates getState(){
|
||||||
|
return currentState;
|
||||||
|
}
|
||||||
|
|
||||||
public TurnState getParent(){
|
public TurnState getParent(){
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,4 +54,8 @@ public SwapState getSwap() {
|
|||||||
public TurnState getParent() {
|
public TurnState getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PowerCardStates getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class PauseGameMessage extends ServerMessage {
|
public class PauseGameMessage extends ServerMessage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the id of the player who has disconnected
|
||||||
|
*/
|
||||||
|
private int playerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new PauseGame instance.
|
* Constructs a new PauseGame instance.
|
||||||
*/
|
*/
|
||||||
@@ -14,6 +20,23 @@ public PauseGameMessage() {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new PauseGame instance.
|
||||||
|
*/
|
||||||
|
public PauseGameMessage(int playerId) {
|
||||||
|
super();
|
||||||
|
this.playerId = playerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the player id of the disconnected player
|
||||||
|
*
|
||||||
|
* @return the id of the disconnected player as an int
|
||||||
|
*/
|
||||||
|
public int getPlayerId() {
|
||||||
|
return playerId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts a visitor to process this message.
|
* Accepts a visitor to process this message.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class UpdateTSKMessage extends ServerMessage {
|
|||||||
private final Color color;
|
private final Color color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new UpdateTSK instance with the specified name and color.
|
* Constructs a new UpdateTSK instance with the specified id and color.
|
||||||
*
|
*
|
||||||
* @param id the name associated with the update
|
* @param id the name associated with the update
|
||||||
* @param color the color associated with the update
|
* @param color the color associated with the update
|
||||||
|
|||||||
@@ -7,17 +7,19 @@
|
|||||||
*/
|
*/
|
||||||
public class TskSelectNotification extends Notification{
|
public class TskSelectNotification extends Notification{
|
||||||
|
|
||||||
private Color color;
|
private final Color color;
|
||||||
private String name;
|
private final String name;
|
||||||
|
private final boolean isSelf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param color the color of the player that is in the game.
|
* @param color the color of the player that is in the game.
|
||||||
* @param name the name of the player that is in the game.
|
* @param name the name of the player that is in the game.
|
||||||
*/
|
*/
|
||||||
public TskSelectNotification(Color color, String name) {
|
public TskSelectNotification(Color color, String name, boolean isSelf) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.isSelf = isSelf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,4 +37,13 @@ public Color getColor() {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a boolean based of if the select notification affects the own user
|
||||||
|
*
|
||||||
|
* @return boolean isSelf
|
||||||
|
*/
|
||||||
|
public boolean isSelf() {
|
||||||
|
return isSelf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user