Merge branch 'dev/model' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-01 into dev/model
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package pp.mdga.server.automaton.game.turn.powercard;
|
||||
|
||||
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.SelectCardMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
import pp.mdga.visitor.Visitor;
|
||||
|
||||
public class ChoosePowerCardState extends PowerCardAutomatonState implements Visitor {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public ChoosePowerCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
|
||||
super(powerCardAutomaton, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be entered.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be exited.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(SelectCardMessage msg, int from) {
|
||||
if (this.powerCardAutomaton.getVisitor().getCards().contains(msg.getCard())) {
|
||||
this.powerCardAutomaton.setSelectedCard(msg.getCard());
|
||||
msg.getCard().accept(this);
|
||||
} else {
|
||||
this.logic.getServerSender().send(from, new IncorrectRequestMessage(2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
||||
*
|
||||
* @param card as a ShieldCard object.
|
||||
*/
|
||||
private void changeState(ShieldCard card) {
|
||||
this.powerCardAutomaton.setCurrentState(this.powerCardAutomaton.getShieldCardState());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
||||
*
|
||||
* @param card as a SwapCard object.
|
||||
*/
|
||||
private void changeState(SwapCard card) {
|
||||
this.powerCardAutomaton.setCurrentState(this.powerCardAutomaton.getSwapCardState());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
||||
*
|
||||
* @param card as a TurboCard object.
|
||||
*/
|
||||
private void changeState(TurboCard card) {
|
||||
this.powerCardAutomaton.setCurrentState(this.powerCardAutomaton.getTurboCardState());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
||||
*
|
||||
* @param card as a TurboCard object.
|
||||
*/
|
||||
private void changeState(HiddenCard card) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new IncorrectRequestMessage(5));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to visit the given card parameter.
|
||||
*
|
||||
* @param card as a TurboCard object.
|
||||
*/
|
||||
@Override
|
||||
public void visit(TurboCard card) {
|
||||
this.changeState(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to visit the given card parameter.
|
||||
*
|
||||
* @param card as a SwapCard object.
|
||||
*/
|
||||
@Override
|
||||
public void visit(SwapCard card) {
|
||||
this.changeState(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to visit the given card parameter.
|
||||
*
|
||||
* @param card as a ShieldCard oblect
|
||||
*/
|
||||
@Override
|
||||
public void visit(ShieldCard card) {
|
||||
this.changeState(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to visit the given card parameter.
|
||||
*
|
||||
* @param card as a HiddenCard object.
|
||||
*/
|
||||
@Override
|
||||
public void visit(HiddenCard card) {
|
||||
this.changeState(card);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package pp.mdga.server.automaton.game.turn.powercard;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
|
||||
public abstract class PowerCardAutomatonState extends ServerState {
|
||||
/**
|
||||
* Create PowerCardAutomatonState attributes.
|
||||
*/
|
||||
protected final PowerCardState powerCardAutomaton;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public PowerCardAutomatonState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.powerCardAutomaton = powerCardAutomaton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ShieldCardState extends PowerCardAutomatonState {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public ShieldCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
|
||||
super(powerCardAutomaton, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be entered.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be exited.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a SelectedPiecesMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectedPiecesMessage msg, int from) {
|
||||
if (msg.getPieces().size() == 1 && this.powerCardAutomaton.getVisitor().getShieldPieces().contains(msg.getPieces().get(0))) {
|
||||
this.powerCardAutomaton.addSelectedPiece(msg.getPieces().get(0));
|
||||
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
||||
if (piece == msg.getPieces().get(0)) {
|
||||
piece.setShield(ShieldState.ACTIVE);
|
||||
}
|
||||
}
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), new ArrayList<>(), this.logic.getGame().getDiceModifier()));
|
||||
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
|
||||
}
|
||||
else {
|
||||
this.logic.getServerSender().send(from, new IncorrectRequestMessage(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package pp.mdga.server.automaton.game.turn.powercard;
|
||||
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
|
||||
public class SwapCardState extends PowerCardAutomatonState {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public SwapCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
|
||||
super(powerCardAutomaton, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be entered.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be exited.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a SelectedPiecesMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectedPiecesMessage msg, int from) {
|
||||
if (msg.getPieces().size() == 2) {
|
||||
Piece first = msg.getPieces().get(0);
|
||||
Piece second = msg.getPieces().get(1);
|
||||
if ((this.powerCardAutomaton.getVisitor().getSwapOwnPieces().contains(first)
|
||||
&& this.powerCardAutomaton.getVisitor().getSwapOtherPieces().contains(second))
|
||||
|| (this.powerCardAutomaton.getVisitor().getSwapOwnPieces().contains(second)
|
||||
&& this.powerCardAutomaton.getVisitor().getSwapOtherPieces().contains(first))) {
|
||||
this.powerCardAutomaton.addSelectedPiece(first);
|
||||
this.powerCardAutomaton.addSelectedPiece(second);
|
||||
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
|
||||
}
|
||||
} else {
|
||||
this.logic.getServerSender().send(from, new IncorrectRequestMessage(4));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package pp.mdga.server.automaton.game.turn.powercard;
|
||||
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TurboCardState extends PowerCardAutomatonState {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public TurboCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
|
||||
super(powerCardAutomaton, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be entered.
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
this.logic.getGame().getDie().modify();
|
||||
this.logic.getGame().setDiceModifier(this.logic.getGame().getDiceModifier());
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), new ArrayList<>(), this.logic.getGame().getDiceModifier()));
|
||||
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used whenever this state will be exited.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a SelectedPiecesMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
public void received(SelectedPiecesMessage msg, int from) {
|
||||
// ToDo: We can use this method to catch irregular client messages.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user