added JavaDocs commects where they where missing and removed outcommented code
This commit is contained in:
@@ -119,6 +119,12 @@ public Spatial visit(Battleship ship) {
|
||||
return shipNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method will create a representation of a shell in the map
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
* @return the node the representation is attached to
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
LOGGER.log(Logger.Level.DEBUG, "Visiting {0}", shell);
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
import java.lang.System.Logger;
|
||||
|
||||
/**
|
||||
* This class controls a 3D representation of a shell
|
||||
*/
|
||||
public class ShellControl extends AbstractControl {
|
||||
private final Shell shell;
|
||||
private final BattleshipApp app;
|
||||
@@ -19,11 +22,23 @@ public class ShellControl extends AbstractControl {
|
||||
|
||||
static final Logger LOGGER = System.getLogger(ShellControl.class.getName());
|
||||
|
||||
/**
|
||||
* Constructor to create a new ShellControl object
|
||||
*
|
||||
* @param shell the shell to be displayed
|
||||
* @param app the main application
|
||||
*/
|
||||
public ShellControl(Shell shell, BattleshipApp app) {
|
||||
this.shell = shell;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method moves the representation towards it destination
|
||||
* and deletes it if it reaches its target
|
||||
*
|
||||
* @param tpf time per frame (in seconds)
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
spatial.move(0, -MOVE_SPEED * tpf, 0);
|
||||
@@ -35,8 +50,14 @@ protected void controlUpdate(float tpf) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
|
||||
|
||||
@@ -9,12 +9,22 @@
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.util.Position;
|
||||
|
||||
/**
|
||||
* This class controls a ShellMap element
|
||||
*/
|
||||
public class ShellMapControl extends AbstractControl {
|
||||
private final Position position;
|
||||
private final IntPoint pos;
|
||||
private static final Vector3f vector = new Vector3f();
|
||||
private final BattleshipApp app;
|
||||
|
||||
/**
|
||||
* constructs a new ShellMapControl object
|
||||
*
|
||||
* @param position the position where the shell should move to on the map
|
||||
* @param app the main application
|
||||
* @param pos the position the then to render shot goes to
|
||||
*/
|
||||
public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) {
|
||||
super();
|
||||
this.position = position;
|
||||
@@ -23,6 +33,12 @@ public ShellMapControl(Position position, BattleshipApp app, IntPoint pos) {
|
||||
vector.set(new Vector3f(position.getX(), position.getY(), 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* this method moves the shell representation to its correct spot and removes it after
|
||||
* it arrived at its destination
|
||||
*
|
||||
* @param tpf time per frame (in seconds)
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
spatial.move(vector.mult(tpf));
|
||||
@@ -32,6 +48,14 @@ protected void controlUpdate(float tpf) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
|
||||
|
||||
@@ -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