added JavaDocs commects where they where missing and removed outcommented code
This commit is contained in:
@@ -13,9 +13,11 @@ public class AnimatonState extends ClientState {
|
||||
private boolean myTurn;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
* creates an object of AnimationState
|
||||
*
|
||||
* @param logic the game logic
|
||||
* @param logic the client logic
|
||||
* @param myTurn a boolean containing if it is the clients turn
|
||||
* @param position the position a shell should be created
|
||||
*/
|
||||
public AnimatonState(ClientGameLogic logic, boolean myTurn, IntPoint position) {
|
||||
super(logic);
|
||||
@@ -28,6 +30,11 @@ public AnimatonState(ClientGameLogic logic, boolean myTurn, IntPoint position) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method makes sure the client renders the correct view
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
boolean showBattle() {
|
||||
return true;
|
||||
@@ -54,6 +61,11 @@ public void receivedEffect(EffectMessage msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is used to change the client to the battle state again
|
||||
*
|
||||
* @param msg the message to process
|
||||
*/
|
||||
@Override
|
||||
public void receivedSwitchBattleState(SwitchBattleState msg) {
|
||||
logic.setState(new BattleState(logic, msg.isTurn()));
|
||||
|
||||
@@ -35,6 +35,11 @@ public BattleState(ClientGameLogic logic, boolean myTurn) {
|
||||
this.myTurn = myTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method makes sure the client renders the correct view
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean showBattle() {
|
||||
return true;
|
||||
|
||||
@@ -225,11 +225,21 @@ public void received(EffectMessage msg) {
|
||||
state.receivedEffect(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that the client should start an animation
|
||||
*
|
||||
* @param msg the AnimationStartMessage received
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationStartMessage msg) {
|
||||
state.receivedAnimationStart(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that the client should move to the battle state
|
||||
*
|
||||
* @param msg the SwitchBattleState received
|
||||
*/
|
||||
@Override
|
||||
public void received(SwitchBattleState msg) {
|
||||
state.receivedSwitchBattleState(msg);
|
||||
|
||||
@@ -163,10 +163,20 @@ void receivedEffect(EffectMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedEffect not allowed in {0}", getName()); //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that the client should start an animation
|
||||
*
|
||||
* @param msg the AnimationStartMessage received
|
||||
*/
|
||||
void receivedAnimationStart(AnimationStartMessage msg){
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedEffect not allowed in {0}", getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports that the client should move to the battle state
|
||||
*
|
||||
* @param msg the SwitchBattleState received
|
||||
*/
|
||||
void receivedSwitchBattleState(SwitchBattleState msg){
|
||||
ClientGameLogic.LOGGER.log(Level.ERROR, "receivedSwitchBattleState not allowed in {0}", getName());
|
||||
}
|
||||
|
||||
@@ -251,6 +251,12 @@ else if (!checkMapToLoad(dto)) {
|
||||
selectedInHarbor = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to check if the loaded map is correct
|
||||
*
|
||||
* @param dto the data transfer object to check
|
||||
* @return boolean if map is correct or not
|
||||
*/
|
||||
private boolean checkMapToLoad(ShipMapDTO dto) {
|
||||
int mapWidth = dto.getWidth();
|
||||
int mapHeight = dto.getHeight();
|
||||
|
||||
@@ -205,6 +205,12 @@ public void received(ShootMessage msg, int from) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a clients message that it is done with the animation
|
||||
*
|
||||
* @param msg the AnimationEndMessage to be processed
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from){
|
||||
if(state != ServerState.ANIMATION_WAIT)
|
||||
@@ -248,45 +254,13 @@ void playerReady(Player player, List<Battleship> ships) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Handles the shooting action by the player.
|
||||
* This method decides what effectMessage the client should get based on the shot made
|
||||
* and switches the active player if a shot was missed
|
||||
*
|
||||
* @param p the player who shot
|
||||
* @param pos the position of the shot
|
||||
*//*
|
||||
void shoot(Player p, IntPoint pos) {
|
||||
if (p != activePlayer) return;
|
||||
final Player otherPlayer = getOpponent(activePlayer);
|
||||
final Battleship selectedShip = otherPlayer.getMap().findShipAt(pos);
|
||||
if (selectedShip == null) {
|
||||
// shot missed
|
||||
send(activePlayer, EffectMessage.miss(true, pos));
|
||||
send(otherPlayer, EffectMessage.miss(false, pos));
|
||||
activePlayer = otherPlayer;
|
||||
}
|
||||
else {
|
||||
// shot hit a ship
|
||||
selectedShip.hit(pos);
|
||||
if (otherPlayer.getMap().getRemainingShips().isEmpty()) {
|
||||
// game is over
|
||||
send(activePlayer, EffectMessage.won(pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.lost(pos, selectedShip, activePlayer.getMap().getRemainingShips()));
|
||||
setState(ServerState.GAME_OVER);
|
||||
}
|
||||
else if (selectedShip.isDestroyed()) {
|
||||
// ship has been destroyed, but game is not yet over
|
||||
send(activePlayer, EffectMessage.shipDestroyed(true, pos, selectedShip));
|
||||
send(otherPlayer, EffectMessage.shipDestroyed(false, pos, selectedShip));
|
||||
}
|
||||
else {
|
||||
// ship has been hit, but it hasn't been destroyed
|
||||
send(activePlayer, EffectMessage.hit(true, pos));
|
||||
send(otherPlayer, EffectMessage.hit(false, pos));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
* @param p the player to be sent the message
|
||||
* @param position the position where the shot would hit in the 2d map model
|
||||
*/
|
||||
void shoot(Player p, IntPoint position) {
|
||||
final Battleship selectedShip;
|
||||
if(p != activePlayer){
|
||||
|
||||
@@ -60,6 +60,13 @@ public void received(MapMessage msg, int from) {
|
||||
copiedMessage = new MapMessage(msg.getShips().stream().map(Copycat::copy).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reception of a AnimationEndMessage
|
||||
* Creates a copy of the AnimationEndMessage
|
||||
*
|
||||
* @param msg the AnimationEndMessage to be processed
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
copiedMessage = new AnimationEndMessage(msg.getPosition());
|
||||
|
||||
@@ -79,11 +79,21 @@ public void received(EffectMessage msg) {
|
||||
forward(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the received AnimationStartMessage to the client's game logic.
|
||||
*
|
||||
* @param msg the AnimationStartMessage received from the server
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationStartMessage msg) {
|
||||
forward(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the received SwitchBattleState to the client's game logic.
|
||||
*
|
||||
* @param msg the SwitchBattleState received from the server
|
||||
*/
|
||||
@Override
|
||||
public void received(SwitchBattleState msg){
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received SwitchBattleState");
|
||||
|
||||
@@ -111,8 +111,7 @@ public void received(StartBattleMessage msg) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an effect message, logs it, and updates the turn status.
|
||||
* If it is RobotClient's turn to shoot, schedules a shot using shoot();
|
||||
* Receives an effect message, logs it.
|
||||
*
|
||||
* @param msg The effect message
|
||||
*/
|
||||
@@ -121,12 +120,22 @@ public void received(EffectMessage msg) {
|
||||
LOGGER.log(Level.INFO, "Received EffectMessage: {0}", msg); //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an AnimationStartMessage, and responds instantly with an AnimationEndMessage
|
||||
*
|
||||
* @param msg the AnimationStartMessage received
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationStartMessage msg) {
|
||||
LOGGER.log(Level.INFO, "Received AnimationStartMessage: {0}", msg);
|
||||
connection.sendRobotMessage(new AnimationEndMessage(msg.getPosition()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a SwitchBattleState, and shots if it is the robots turn
|
||||
*
|
||||
* @param msg the SwitchBattleState received
|
||||
*/
|
||||
@Override
|
||||
public void received(SwitchBattleState msg){
|
||||
LOGGER.log(Level.INFO, "Received SwitchBattleStateMessage: {0}", msg);
|
||||
|
||||
@@ -8,16 +8,35 @@ public class AnimationEndMessage extends ClientMessage {
|
||||
|
||||
private IntPoint position;
|
||||
|
||||
/**
|
||||
* used for serialization
|
||||
*/
|
||||
private AnimationEndMessage(){ /* nothing */}
|
||||
|
||||
/**
|
||||
* constructs a new AnimationEndMessage
|
||||
*
|
||||
* @param position the position to be effected by the server
|
||||
*/
|
||||
public AnimationEndMessage(IntPoint position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for the position
|
||||
*
|
||||
* @return IntPoint position
|
||||
*/
|
||||
public IntPoint getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts Visitors to process this message
|
||||
*
|
||||
* @param interpreter the visitor to be used for processing
|
||||
* @param from the connection ID of the sender
|
||||
*/
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
|
||||
@@ -8,26 +8,55 @@ public class AnimationStartMessage extends ServerMessage {
|
||||
private IntPoint position;
|
||||
private boolean myTurn;
|
||||
|
||||
/**
|
||||
* used for serialization
|
||||
*/
|
||||
private AnimationStartMessage(){ /* nothing */}
|
||||
|
||||
/**
|
||||
* constructs a new AnimationStartMessage
|
||||
*
|
||||
* @param position the Position a shell should affect
|
||||
* @param isTurn boolean containing if it is the clients turn or not
|
||||
*/
|
||||
public AnimationStartMessage(IntPoint position, boolean isTurn) {
|
||||
this.position = position;
|
||||
this.myTurn = isTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for the position
|
||||
*
|
||||
* @return IntPoint position
|
||||
*/
|
||||
public IntPoint getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for myTurn
|
||||
*
|
||||
* @return boolean myTurn
|
||||
*/
|
||||
public boolean isMyTurn() {
|
||||
return myTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts visitors to process this message
|
||||
*
|
||||
* @param interpreter the visitor to be used for processing
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string that gives context to the message
|
||||
*
|
||||
* @return String teh context
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return (position + " to be animated");
|
||||
|
||||
@@ -6,21 +6,44 @@
|
||||
public class SwitchBattleState extends ServerMessage {
|
||||
private boolean isTurn;
|
||||
|
||||
/**
|
||||
* used for serialization
|
||||
*/
|
||||
private SwitchBattleState(){ /* nothing */}
|
||||
|
||||
/**
|
||||
* constructs a new SwitchBattleState message
|
||||
*
|
||||
* @param isTurn boolean containing if it is the clients turn
|
||||
*/
|
||||
public SwitchBattleState(boolean isTurn) {
|
||||
this.isTurn = isTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for isTurn
|
||||
*
|
||||
* @return boolean isTurn
|
||||
*/
|
||||
public boolean isTurn() {
|
||||
return isTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* accept visitors the process this message
|
||||
*
|
||||
* @param interpreter the visitor to be used for processing
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string containing context for this method
|
||||
*
|
||||
* @return String containing context
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
|
||||
@@ -1,35 +1,75 @@
|
||||
package pp.battleship.model;
|
||||
|
||||
/**
|
||||
* This class represents a shell
|
||||
*/
|
||||
public class Shell implements Item {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
/**
|
||||
* constructs a new shell object
|
||||
*
|
||||
* @param position the end position of the shell
|
||||
*/
|
||||
public Shell(IntPoint position) {
|
||||
x = position.getX();
|
||||
y = position.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for the x coordinate
|
||||
*
|
||||
* @return int x coordinate
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for the y coordinate
|
||||
*
|
||||
* @return int y coordinate
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for x coordinate
|
||||
*
|
||||
* @param x the new value of x coordinate
|
||||
*/
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for y coordinate
|
||||
*
|
||||
* @param y the new value of y coordinate
|
||||
*/
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor with a return value.
|
||||
*
|
||||
* @param visitor the visitor to accept
|
||||
* @param <T> the type of the return value
|
||||
* @return the result of the visitor's visit method
|
||||
*/
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor without a return value.
|
||||
*
|
||||
* @param visitor the visitor to accept
|
||||
*/
|
||||
@Override
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
Reference in New Issue
Block a user