Merge branch 'development' into 'dev/test'
Testmerge See merge request progproj/gruppen-ht24/Gruppe-01!12
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Animation extends ClientState {
|
||||
protected Animation(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class AudioSettings extends ClientState {
|
||||
protected AudioSettings(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Ceremony extends ClientState {
|
||||
private final CeremonyStateMachine ceremonyStateMachine = new CeremonyStateMachine();
|
||||
private final CeremonyStateMachine ceremonyStateMachine;
|
||||
|
||||
protected Ceremony(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.ceremonyStateMachine = new CeremonyStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class CeremonyStateMachine extends ClientStateMachine {
|
||||
|
||||
protected CeremonyStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Podium initialState() {
|
||||
return new Podium(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class ChoosePiece extends ClientState {
|
||||
private final ChoosePieceStateMachine choosePieceStateMachine = new ChoosePieceStateMachine();
|
||||
private final ChoosePieceStateMachine choosePieceStateMachine;
|
||||
|
||||
protected ChoosePiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.choosePieceStateMachine = new ChoosePieceStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class ChoosePieceStateMachine extends ClientStateMachine{
|
||||
protected ChoosePieceStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoPiece initialState() {
|
||||
return new NoPiece(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class ChoosePowerCard extends ClientState {
|
||||
protected ChoosePowerCard(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class ClientAutomaton extends ClientStateMachine {
|
||||
|
||||
public ClientAutomaton(ClientGameLogic logic){
|
||||
super(null, logic);
|
||||
entry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialogs initialState(){
|
||||
return new Dialogs(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,36 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import pp.mdga.game.Game;
|
||||
import pp.mdga.message.client.ClientMessage;
|
||||
import pp.mdga.server.ServerSender;
|
||||
|
||||
public class ClientGameLogic {
|
||||
static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||
|
||||
private Game game;
|
||||
private final ClientSender clientSender;
|
||||
private ClientState state;
|
||||
|
||||
public ClientGameLogic(Game game, ClientSender clientSender) {
|
||||
this.game = game;
|
||||
this.clientSender = clientSender;
|
||||
state = new ClientAutomaton(this);
|
||||
}
|
||||
|
||||
public void send(ClientMessage msg){
|
||||
LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
|
||||
clientSender.send(msg);
|
||||
}
|
||||
|
||||
public ClientSender getClientSender(){
|
||||
return clientSender;
|
||||
}
|
||||
|
||||
public Game getGame(){
|
||||
return game;
|
||||
}
|
||||
|
||||
public ClientState getState(){
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import pp.mdga.message.client.ClientMessage;
|
||||
|
||||
public interface ClientSender {
|
||||
void send(ClientMessage msg);
|
||||
}
|
||||
@@ -1,4 +1,33 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public abstract class ClientState {
|
||||
public abstract class ClientState implements Observer {
|
||||
protected static final System.Logger LOGGER = System.getLogger(ClientState.class.getName());
|
||||
|
||||
protected ClientState parent;
|
||||
|
||||
protected ClientGameLogic logic;
|
||||
|
||||
protected ClientState(ClientState parent, ClientGameLogic logic){
|
||||
this.parent = parent;
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
public void entry(){/* do nothing */}
|
||||
|
||||
public void exit() {/* do nothing*/}
|
||||
|
||||
public void gotoState(ClientState newState){
|
||||
throw new IllegalStateException("not in a statemachine");
|
||||
}
|
||||
|
||||
public ClientState getParent(){
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void update() {/* do nothing */}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,46 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import pp.mdga.message.server.*;
|
||||
|
||||
public abstract class ClientStateMachine extends ClientState {
|
||||
|
||||
private ClientState state;
|
||||
|
||||
protected ClientStateMachine(ClientState parent, ClientGameLogic logic){
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
public abstract ClientState initialState();
|
||||
|
||||
@Override
|
||||
public void gotoState(ClientState newState){
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "{0}: {1} --> {2}", this, state, newState);
|
||||
enter(newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entry(){
|
||||
final ClientState newState = initialState();
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "{0}: initial state={1}", this, newState);
|
||||
enter(newState);
|
||||
}
|
||||
|
||||
private void enter(ClientState newState){
|
||||
if(newState.parent != this)
|
||||
throw new IllegalArgumentException("Wrong state: " + newState + " belongs to " + newState.parent + " instead of " + this);
|
||||
state = newState;
|
||||
state.entry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(){state.exit();}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return super.toString() + "(in " + state + ")";
|
||||
}
|
||||
|
||||
public ClientState getState(){
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class DetermineStartPlayer extends ClientState {
|
||||
private final DetermineStartPlayerStateMachine determineStartPlayerStateMachine = new DetermineStartPlayerStateMachine();
|
||||
private final DetermineStartPlayerStateMachine determineStartPlayerStateMachine;
|
||||
|
||||
protected DetermineStartPlayer(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.determineStartPlayerStateMachine = new DetermineStartPlayerStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class DetermineStartPlayerStateMachine extends ClientStateMachine{
|
||||
protected DetermineStartPlayerStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollRankingDice initialState() {
|
||||
return new RollRankingDice(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Dialogs extends ClientState {
|
||||
private final DialogsStateMachine dialogsStateMachine = new DialogsStateMachine();
|
||||
private final DialogsStateMachine dialogsStateMachine;
|
||||
|
||||
public Dialogs(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.dialogsStateMachine = new DialogsStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class DialogsStateMachine extends ClientStateMachine {
|
||||
protected DialogsStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartDialog initialState() {
|
||||
return new StartDialog(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class GameState extends ClientState {
|
||||
private final GameStateMachine gameStateMachine = new GameStateMachine();
|
||||
private final GameStateMachine gameStateMachine;
|
||||
|
||||
protected GameState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.gameStateMachine = new GameStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class GameStateMachine extends ClientStateMachine {
|
||||
protected GameStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientState initialState() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import pp.mdga.server.GameState;
|
||||
|
||||
public class Interrupt extends ClientState {
|
||||
|
||||
private final GameState lastState;
|
||||
|
||||
public Interrupt(ClientState parent, ClientGameLogic logic, GameState lastState) {
|
||||
super(parent, logic);
|
||||
this.lastState = lastState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Lobby extends ClientState {
|
||||
protected Lobby(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class MainSettings extends ClientState {
|
||||
protected MainSettings(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class MovePiece extends ClientState {
|
||||
protected MovePiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class NetworkDialog extends ClientState {
|
||||
protected NetworkDialog(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class NoPiece extends ClientState {
|
||||
protected NoPiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public interface Observer {
|
||||
void update();
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class PlayPowerCard extends ClientState {
|
||||
protected PlayPowerCard(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Podium extends ClientState {
|
||||
protected Podium(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class PowerCard extends ClientState {
|
||||
private final PowerCardStateMachine powerCardStateMachine = new PowerCardStateMachine();
|
||||
private final PowerCardStateMachine powerCardStateMachine;
|
||||
|
||||
protected PowerCard(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.powerCardStateMachine = new PowerCardStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class PowerCardStateMachine extends ClientStateMachine {
|
||||
protected PowerCardStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoosePowerCard initialState() {
|
||||
return new ChoosePowerCard(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class RollDice extends ClientState {
|
||||
protected RollDice(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class RollRankingDice extends ClientState {
|
||||
protected RollRankingDice(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class SelectPiece extends ClientState {
|
||||
protected SelectPiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Settings extends ClientState {
|
||||
private final SettingsStateMachine settingsStateMachine = new SettingsStateMachine();
|
||||
private final SettingsStateMachine settingsStateMachine;
|
||||
|
||||
protected Settings(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.settingsStateMachine = new SettingsStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class SettingsStateMachine extends ClientStateMachine {
|
||||
protected SettingsStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientState initialState() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Shield extends ClientState {
|
||||
protected Shield(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Spectator extends ClientState {
|
||||
protected Spectator(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class StartDialog extends ClientState {
|
||||
protected StartDialog(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class StartPiece extends ClientState {
|
||||
protected StartPiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Statistics extends ClientState {
|
||||
protected Statistics(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Swap extends ClientState {
|
||||
protected Swap(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Turn extends ClientState {
|
||||
private final TurnStateMachine turnStateMachine = new TurnStateMachine();
|
||||
private final TurnStateMachine turnStateMachine;
|
||||
|
||||
protected Turn(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
this.turnStateMachine = new TurnStateMachine(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class TurnStateMachine extends ClientStateMachine {
|
||||
protected TurnStateMachine(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerCard initialState() {
|
||||
return new PowerCard(this, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class VideoSettings extends ClientState {
|
||||
protected VideoSettings(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class WaitRanking extends ClientState {
|
||||
protected WaitRanking(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class Waiting extends ClientState {
|
||||
protected Waiting(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public class WaitingPiece extends ClientState {
|
||||
protected WaitingPiece(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum BonusCard {
|
||||
HIDDERN,
|
||||
HIDDEN,
|
||||
SHIELD,
|
||||
TURBO,
|
||||
SWAP
|
||||
|
||||
@@ -29,6 +29,8 @@ public class Game {
|
||||
private Boolean allRanked = false;
|
||||
private Boolean movablePieces = false;
|
||||
|
||||
private Boolean allReady = false;
|
||||
|
||||
private static final int AMOUNT_OF_TURBO_CARDS = 16;
|
||||
private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
|
||||
|
||||
@@ -397,6 +399,25 @@ public void setStartPlayer(Player startPlayer) {
|
||||
this.startPlayer = startPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the all ready state.
|
||||
*
|
||||
* @return the all ready state
|
||||
*/
|
||||
public Boolean allReady() {
|
||||
return allReady;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the all ready state.
|
||||
*
|
||||
* @param allReady the new all ready state
|
||||
*/
|
||||
public void setAllReady(Boolean allReady) {
|
||||
this.allReady = allReady;
|
||||
if (allReady) notifyObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method notifies the observers.
|
||||
*/
|
||||
@@ -405,4 +426,17 @@ public void notifyObservers() {
|
||||
observer.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the piece through its identifier.
|
||||
*
|
||||
* @param identifier the identifier of the piece
|
||||
* @return the piece
|
||||
*/
|
||||
public Piece getPieceThroughIdentifier(String identifier) {
|
||||
String[] parts = identifier.split("-");
|
||||
Color color = Color.valueOf(parts[0]);
|
||||
int index = Integer.parseInt(parts[1]);
|
||||
return board.getPlayerData().get(color).getPieces()[index];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ public class Piece {
|
||||
private ShieldState shield;
|
||||
private PieceState state;
|
||||
private final Color color;
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new Piece
|
||||
@@ -14,10 +15,11 @@ public class Piece {
|
||||
* @param color the color of the piece
|
||||
* @param state the state of the piece
|
||||
*/
|
||||
public Piece(Color color, PieceState state) {
|
||||
public Piece(Color color, PieceState state, int id) {
|
||||
this.color = color;
|
||||
this.state = state;
|
||||
shield = ShieldState.NONE;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,4 +84,13 @@ public boolean isSuppressed() {
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the color of the piece
|
||||
*
|
||||
* @return the color of the piece
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return color.toString() + "-" + id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public PlayerData(Color color) {
|
||||
waitingArea = new Piece[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
homeNodes[i] = new HomeNode();
|
||||
pieces[i] = new Piece(color, PieceState.WAITING);
|
||||
pieces[i] = new Piece(color, PieceState.WAITING, i);
|
||||
waitingArea[i] = pieces[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class DeselectTSK extends ClientMessage {
|
||||
private final Color color;
|
||||
|
||||
public DeselectTSK(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class RequestMove extends ClientMessage {
|
||||
|
||||
private final String pieceIdentifier;
|
||||
|
||||
/** Constructor for RequestMove
|
||||
* @param pieceIdentifier the piece identifier
|
||||
*/
|
||||
public RequestMove(String pieceIdentifier) {
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
}
|
||||
|
||||
/** Getter for the piece identifier
|
||||
* @return the piece identifier
|
||||
*/
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
public class RequestPlayCard extends ClientMessage {
|
||||
|
||||
private final BonusCard card;
|
||||
private final String pieceIdentifier;
|
||||
|
||||
public RequestPlayCard(BonusCard card, String pieceIdentifier) {
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
this.card = card;
|
||||
}
|
||||
|
||||
public BonusCard getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
return card.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
public class SelectCard extends ClientMessage {
|
||||
|
||||
private final BonusCard card;
|
||||
|
||||
public SelectCard(BonusCard card) {
|
||||
this.card = card;
|
||||
}
|
||||
|
||||
public BonusCard getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class SelectTSK extends ClientMessage {
|
||||
|
||||
private final Color color;
|
||||
|
||||
public SelectTSK(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
package pp.mdga.message.client;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class SelectedPieces extends ClientMessage {
|
||||
|
||||
private String pieceIdentifier;
|
||||
|
||||
/** Constructor for SelectedPieces
|
||||
* @param pieceIdentifier the piece identifier
|
||||
*/
|
||||
public SelectedPieces(String pieceIdentifier) {
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
}
|
||||
|
||||
/** Getter for the piece identifier
|
||||
* @return the piece identifier
|
||||
*/
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class ActivePlayer extends ServerMessage {
|
||||
|
||||
private Color color;
|
||||
|
||||
/** Constructor for ActivePlayer
|
||||
* @param color the color of the active player
|
||||
*/
|
||||
public ActivePlayer(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/** Getter for the color of the active player
|
||||
* @return the color of the active player
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AnyPiece extends ServerMessage {
|
||||
|
||||
private ArrayList<String> piece;
|
||||
|
||||
/** Constructor for AnyPiece
|
||||
*/
|
||||
public AnyPiece() {
|
||||
piece = new ArrayList<>();
|
||||
}
|
||||
|
||||
/** Add a piece to the list of pieces
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addPiece(String piece) {
|
||||
this.piece.add(piece);
|
||||
}
|
||||
|
||||
/** Getter for the list of pieces
|
||||
* @return the list of pieces
|
||||
*/
|
||||
public ArrayList<String> getPiece() {
|
||||
return piece;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,52 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Dice extends ServerMessage {
|
||||
|
||||
private final int diceEye;
|
||||
private final ArrayList<String> moveablePieces;
|
||||
|
||||
/** Constructor for Dice
|
||||
* @param diceEye the eye of the dice
|
||||
* @param moveablePieces the pieces that can be moved
|
||||
*/
|
||||
public Dice(int diceEye, ArrayList<String> moveablePieces) {
|
||||
this.diceEye = diceEye;
|
||||
this.moveablePieces = moveablePieces;
|
||||
}
|
||||
|
||||
/** Constructor for inactivePlayer
|
||||
* @param diceEye the eye of the dice
|
||||
* @return a new Dice object
|
||||
*/
|
||||
public static Dice inactivePlayer(int diceEye) {
|
||||
return new Dice(diceEye, null);
|
||||
}
|
||||
|
||||
/** Constructor for activePlayer
|
||||
* @param diceEye the eye of the dice
|
||||
* @param moveablePieces the pieces that can be moved
|
||||
* @return a new Dice object
|
||||
*/
|
||||
public static Dice activePlayer(int diceEye, ArrayList<String> moveablePieces) {
|
||||
return new Dice(diceEye, moveablePieces);
|
||||
}
|
||||
|
||||
/** Getter for the eye of the dice
|
||||
* @return the eye of the dice
|
||||
*/
|
||||
public int getDiceEye() {
|
||||
return diceEye;
|
||||
}
|
||||
|
||||
/** Getter for the pieces that can be moved
|
||||
* @return the pieces that can be moved
|
||||
*/
|
||||
public ArrayList<String> getMoveablePieces() {
|
||||
return moveablePieces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
public class LobbyPlayerJoin extends ServerMessage {
|
||||
|
||||
private final String name;
|
||||
|
||||
public LobbyPlayerJoin(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class LobbyPlayerLeave extends ServerMessage {
|
||||
|
||||
private final String name;
|
||||
private final Color color;
|
||||
|
||||
public LobbyPlayerLeave(String name, Color color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
public class MoveMessage extends ServerMessage {
|
||||
|
||||
private final String pieceIdentifier;
|
||||
|
||||
/**
|
||||
* @param identifier the identifier of the piece that should be moved
|
||||
*/
|
||||
public MoveMessage(String identifier) {
|
||||
this.pieceIdentifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the identifier of the piece that should be moved
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the identifier of the piece that should be moved
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,34 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
public class PlayCard extends ServerMessage {
|
||||
|
||||
private final BonusCard card;
|
||||
private final String pieceIdentifier;
|
||||
|
||||
/**
|
||||
* @param card the card that should be played
|
||||
* @param pieceIdentifier the identifier of the piece that should be moved
|
||||
*/
|
||||
public PlayCard(BonusCard card, String pieceIdentifier) {
|
||||
this.card = card;
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the card that should be played
|
||||
*/
|
||||
public BonusCard getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the identifier of the piece that should be moved
|
||||
*/
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PossibleCard extends ServerMessage {
|
||||
|
||||
private ArrayList<BonusCard> possibleCards;
|
||||
|
||||
/** Constructor for PossibleCard
|
||||
*/
|
||||
public PossibleCard() {
|
||||
possibleCards = new ArrayList<>();
|
||||
}
|
||||
|
||||
/** Add a possible card to the list of possible cards
|
||||
* @param card the possible card to add
|
||||
*/
|
||||
public void addPossibleCard(BonusCard card) {
|
||||
this.possibleCards.add(card);
|
||||
}
|
||||
|
||||
/** Getter for the list of possible cards
|
||||
* @return the list of possible cards
|
||||
*/
|
||||
public ArrayList<BonusCard> getPossibleCards() {
|
||||
return possibleCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PossiblePiece extends ServerMessage {
|
||||
|
||||
private final ArrayList<String> possibleOwnPieces;
|
||||
private final ArrayList<String> possibleEnemyPieces;
|
||||
|
||||
/** Constructor for PossiblePiece
|
||||
*/
|
||||
public PossiblePiece() {
|
||||
possibleOwnPieces = new ArrayList<>();
|
||||
possibleEnemyPieces = new ArrayList<>();
|
||||
}
|
||||
|
||||
/** Add a piece to the list of possible pieces
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addOwnPossiblePiece(String piece) {
|
||||
this.possibleOwnPieces.add(piece);
|
||||
}
|
||||
|
||||
/** Add a piece to the list of possible enemy pieces
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addEnemyPossiblePiece(String piece) {
|
||||
this.possibleEnemyPieces.add(piece);
|
||||
}
|
||||
|
||||
/** Getter for the list of possible pieces
|
||||
* @return the list of possible pieces
|
||||
*/
|
||||
public ArrayList<String> getPossiblePieces() {
|
||||
return possibleOwnPieces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.Game;
|
||||
|
||||
public class ReconnectBriefing extends ServerMessage {
|
||||
|
||||
private final Game game;
|
||||
|
||||
public ReconnectBriefing(Game game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
public class StartPiece extends ServerMessage {
|
||||
|
||||
private final String pieceIdentifier;
|
||||
|
||||
public StartPiece(String pieceIdentifier) {
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
}
|
||||
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class UpdateReady extends ServerMessage {
|
||||
|
||||
private final Color color;
|
||||
private final boolean ready;
|
||||
|
||||
public UpdateReady(Color color, boolean ready) {
|
||||
this.color = color;
|
||||
this.ready = ready;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class UpdateTSK extends ServerMessage {
|
||||
|
||||
private final String name;
|
||||
private final Color color;
|
||||
|
||||
public UpdateTSK(String name, Color color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
||||
|
||||
@@ -8,13 +8,19 @@
|
||||
public class TskSelectNotification extends Notification{
|
||||
|
||||
private Color color;
|
||||
private String name;
|
||||
private boolean self;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param self true if it was the local player selecting the tsk, false otherwise
|
||||
*/
|
||||
TskSelectNotification(Color color) {
|
||||
TskSelectNotification(Color color, String name, boolean self) {
|
||||
this.color = color;
|
||||
this.name = name;
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,4 +30,20 @@ public class TskSelectNotification extends Notification{
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the player that is in the game.
|
||||
* @return the name of the player that is in the game.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if it was the local player selecting this tsk.
|
||||
* @return ture if it was the local player selecting the tsk.
|
||||
*/
|
||||
public boolean isSelf() {
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class DetermineStartPlayer extends ServerState {
|
||||
private final List<Player> player = new ArrayList<>();
|
||||
@@ -17,9 +18,9 @@ public DetermineStartPlayer(ServerState parent, ServerGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
logic.send();
|
||||
|
||||
broadcastUpdate(new Dice());
|
||||
final Random random = new Random();
|
||||
final int dice = random.nextInt(6) + 1;
|
||||
broadcastUpdate(new Dice(dice, new ArrayList<>()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
import pp.mdga.message.server.ServerStartGame;
|
||||
import pp.mdga.message.server.UpdateReady;
|
||||
import pp.mdga.message.server.UpdateTSK;
|
||||
@@ -26,7 +29,7 @@ public Lobby(ServerState parent, ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void receivedDeselectTSK(DeselectTSK msg, int from) {
|
||||
broadcastUpdate(new UpdateTSK());
|
||||
broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +39,7 @@ public void receivedDeselectTSK(DeselectTSK msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void receivedNotReady(LobbyNotReady msg, int from) {
|
||||
broadcastUpdate(new UpdateReady());
|
||||
broadcastUpdate(new UpdateReady(getPlayerColor(from), false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +49,24 @@ public void receivedNotReady(LobbyNotReady msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void receivedReady(LobbyReady msg, int from) {
|
||||
broadcastUpdate(new UpdateReady());
|
||||
broadcastUpdate(new UpdateReady(getPlayerColor(from), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the color associated with a player ID.
|
||||
*
|
||||
* @param playerId The ID of the player.
|
||||
* @return The Color associated with the player, or null if not found.
|
||||
*/
|
||||
private Color getPlayerColor(int playerId) {
|
||||
Player player = logic.getPlayerById(playerId);
|
||||
|
||||
for (var entry : logic.getGame().getPlayers().entrySet()) {
|
||||
if (entry.getValue().equals(player)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +76,7 @@ public void receivedReady(LobbyReady msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void receivedSelectTSK(SelectTSK msg, int from) {
|
||||
broadcastUpdate(new UpdateTSK());
|
||||
broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +86,7 @@ public void receivedSelectTSK(SelectTSK msg, int from) {
|
||||
*/
|
||||
@Override
|
||||
public void receivedStartGame(ClientStartGame msg, int from) {
|
||||
if (Boolean.TRUE.equals(logic.getGame().allRanked())) {
|
||||
if (Boolean.TRUE.equals(logic.getGame().allReady())) {
|
||||
broadcastUpdate(new ServerStartGame());
|
||||
parent.gotoState(new GameState(parent, logic));
|
||||
}
|
||||
|
||||
@@ -125,6 +125,20 @@ public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player representing the client with the specified connection ID.
|
||||
*
|
||||
* @param id the ID of the client
|
||||
* @return the player associated with the client ID, or null if not found
|
||||
*/
|
||||
public Player getPlayerById(int id) {
|
||||
for (var entry : game.getPlayers().entrySet())
|
||||
if (entry.getValue().getId() == id)
|
||||
return entry.getValue();
|
||||
LOGGER.log(Logger.Level.ERROR, "no player found with connection {0}", id); //NON-NLS
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -204,9 +204,9 @@ public void sentPossibleCard(PossibleCard msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a RankingResponce message is sent.
|
||||
* This method is called when a RankingResponse message is sent.
|
||||
*
|
||||
* @param msg the RankingResponce message
|
||||
* @param msg the RankingResponse message
|
||||
*/
|
||||
@Override
|
||||
public void sentRankingResponse(RankingResponce msg, int from) {
|
||||
|
||||
@@ -29,7 +29,7 @@ public void exit() {
|
||||
this.getParent().getParent().exit();
|
||||
} else {
|
||||
// todo: next player
|
||||
broadcastUpdate(new ActivePlayer());
|
||||
broadcastUpdate(new ActivePlayer(null));
|
||||
parent.gotoState(new Animation(parent, logic));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user