Add FactoryPattern Javadoc

This commit is contained in:
Katchan 2021-12-09 20:56:50 +01:00
parent af5cbf80c1
commit 51a0498886
5 changed files with 34 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import fr.lnl.game.server.games.grid.build.GridFactoryBuilder;
import fr.lnl.game.server.games.grid.elements.CountdownBox;
import fr.lnl.game.server.games.player.ComputerPlayer;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -27,6 +27,11 @@ public abstract class AbstractPlayer implements Player {
this.position = position;
}
/**
*
* @return a list of {@link ReunionSameAction} which groups the same types of actions together.
* It is used by the player action choice strategy
*/
@Override
public List<ReunionSameAction> generateAvailableActions() {
List<ReunionSameAction> actions = new ArrayList<>();

View File

@ -30,5 +30,10 @@ public abstract class ComputerPlayer extends AbstractPlayer {
return action;
}
/**
*
* Method belonging to classes which extend this class to define the specific strategy of the player
* @return the chosen action between all available
*/
public abstract Action strategy(Game game);
}

View File

@ -13,6 +13,10 @@ public interface Player {
Point getPosition();
/**
*
* @return true if this player is Alive, false otherwise
*/
boolean isAlive();
int getId();
@ -21,6 +25,10 @@ public interface Player {
Weapon getWeapon();
/**
*
* @return true if this player has his shield activated, false otherwise
*/
boolean isShieldDeploy();
void setEnergy(int energy);
@ -37,8 +45,18 @@ public interface Player {
void setPosition(Point position);
/**
*
* Call by the implementing classes {@link fr.lnl.game.server.games.action.Action} to withdraw
* a certain number of energy from a player
*/
void decrementEnergy(int energy);
/**
*
* Call by the implementing classes {@link fr.lnl.game.server.games.action.Action} to add
* a certain number of energy from a player
*/
void incrementEnergy(int energy);
}

View File

@ -19,6 +19,10 @@ public class StrategyComputerPlayer extends ComputerPlayer {
super(id,point, classPlayer);
}
/**
* Choose an action following the strategy
* @return an action between all available
*/
@Override
public Action strategy(Game game) {
Action deployShield = choseDeployShield(game);
@ -38,6 +42,7 @@ public class StrategyComputerPlayer extends ComputerPlayer {
return choseExplosive(actions);
}
private Action choseExplosive(List<ReunionSameAction> actions){
Random random = new Random();
if(isInReunion(actions, DropBomb.class) || isInReunion(actions, DropMine.class)){