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