[Priority 3] - Add DefaultClassPlayer and refactor Player constructor
This commit is contained in:
parent
6c61be3a90
commit
498a449a91
@ -3,14 +3,14 @@ package fr.lnl.game.server;
|
|||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.grid.Grid;
|
import fr.lnl.game.server.games.grid.Grid;
|
||||||
import fr.lnl.game.server.games.player.ComputerPlayer;
|
import fr.lnl.game.server.games.player.ComputerPlayer;
|
||||||
|
import fr.lnl.game.server.games.player.DefaultClassPlayer;
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
import fr.lnl.game.server.games.weapon.Firearm;
|
|
||||||
|
|
||||||
public class ServerMain {
|
public class ServerMain {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Player playerOne = new ComputerPlayer(1,1000,new Firearm());
|
Player playerOne = new ComputerPlayer(1,new DefaultClassPlayer());
|
||||||
Player playerTwo = new ComputerPlayer(2,1000,new Firearm());
|
Player playerTwo = new ComputerPlayer(2,new DefaultClassPlayer());
|
||||||
|
|
||||||
Grid grid = new Grid(16,16,new Player[]{playerOne,playerTwo});
|
Grid grid = new Grid(16,16,new Player[]{playerOne,playerTwo});
|
||||||
grid.initGrid();
|
grid.initGrid();
|
||||||
|
@ -12,12 +12,14 @@ public abstract class AbstractPlayer implements Player {
|
|||||||
private Weapon weapon;
|
private Weapon weapon;
|
||||||
private boolean shieldDeploy;
|
private boolean shieldDeploy;
|
||||||
private Action[] actions;
|
private Action[] actions;
|
||||||
|
private ClassPlayer classPlayer;
|
||||||
|
|
||||||
public AbstractPlayer(int id, Point position, int energy, Weapon weapon, boolean shieldDeploy) {
|
public AbstractPlayer(int id, Point position, boolean shieldDeploy, ClassPlayer classPlayer) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.energy = energy;
|
this.classPlayer = classPlayer;
|
||||||
this.weapon = weapon;
|
this.energy = classPlayer.getEnergy();
|
||||||
|
this.weapon = classPlayer.getWeapon();
|
||||||
this.shieldDeploy = shieldDeploy;
|
this.shieldDeploy = shieldDeploy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,4 +62,12 @@ public abstract class AbstractPlayer implements Player {
|
|||||||
public void setWeapon(Weapon weapon) {
|
public void setWeapon(Weapon weapon) {
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action[] getActions() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassPlayer getClassPlayer() {
|
||||||
|
return classPlayer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package fr.lnl.game.server.games.player;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.games.weapon.Weapon;
|
||||||
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
|
public interface ClassPlayer {
|
||||||
|
|
||||||
|
int getEnergy();
|
||||||
|
int getShieldCost();
|
||||||
|
int getShootdCost();
|
||||||
|
int getMineCost();
|
||||||
|
int getBombCost();
|
||||||
|
int getDeplaceCost();
|
||||||
|
int getGainEnergyBall();
|
||||||
|
int getPenaltyShoot();
|
||||||
|
int getPenaltyMine();
|
||||||
|
int getPenaltyBomb();
|
||||||
|
Weapon getWeapon();
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
package fr.lnl.game.server.games.player;
|
package fr.lnl.game.server.games.player;
|
||||||
|
|
||||||
import fr.lnl.game.server.games.weapon.Weapon;
|
|
||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
public class ComputerPlayer extends AbstractPlayer{
|
public class ComputerPlayer extends AbstractPlayer{
|
||||||
|
|
||||||
public ComputerPlayer(int id, Point position, int energy, Weapon weapon, boolean shieldDeploy) {
|
public ComputerPlayer(int id, Point position, boolean shieldDeploy, ClassPlayer classPlayer) {
|
||||||
super(id, position, energy, weapon, shieldDeploy);
|
super(id, position, shieldDeploy, classPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputerPlayer(int id, int energy, Weapon weapon) {
|
public ComputerPlayer(int id, ClassPlayer classPlayer) {
|
||||||
super(id, null, energy, weapon, false);
|
super(id, null,false, classPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
package fr.lnl.game.server.games.player;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.games.weapon.Firearm;
|
||||||
|
import fr.lnl.game.server.games.weapon.Weapon;
|
||||||
|
|
||||||
|
public class DefaultClassPlayer implements ClassPlayer{
|
||||||
|
|
||||||
|
private final int ENERGY = 800;
|
||||||
|
private final int SHIELDCOST = 25;
|
||||||
|
private final int SHOOTDCOST = 40;
|
||||||
|
private final int MINECOST = 30;
|
||||||
|
private final int BOMBCOST = 40;
|
||||||
|
private final int DEPLACECOST = 10;
|
||||||
|
private final int GAINENERGYBALL = 800;
|
||||||
|
private final int PENALTYSHOOT = 20;
|
||||||
|
private final int PENALTYBOMB = 20;
|
||||||
|
private final int PENALTYMINE = 15;
|
||||||
|
private final Weapon WEAPON = new Firearm();
|
||||||
|
|
||||||
|
|
||||||
|
public DefaultClassPlayer(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEnergy() {
|
||||||
|
return this.ENERGY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getShieldCost() {
|
||||||
|
return this.SHIELDCOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getShootdCost() {
|
||||||
|
return this.SHOOTDCOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMineCost() {
|
||||||
|
return this.MINECOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBombCost() {
|
||||||
|
return this.BOMBCOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDeplaceCost() {
|
||||||
|
return this.DEPLACECOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getGainEnergyBall() {
|
||||||
|
return this.GAINENERGYBALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPenaltyShoot() {
|
||||||
|
return this.PENALTYSHOOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPenaltyMine() {
|
||||||
|
return this.PENALTYMINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPenaltyBomb() {
|
||||||
|
return this.PENALTYBOMB;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Weapon getWeapon() {
|
||||||
|
return this.WEAPON;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,8 @@ import fr.lnl.game.server.games.weapon.Weapon;
|
|||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
public class HumanPlayer extends AbstractPlayer {
|
public class HumanPlayer extends AbstractPlayer {
|
||||||
public HumanPlayer(int id, Point position, int energy, Weapon weapon, boolean shieldDeploy) {
|
|
||||||
super(id, position, energy, weapon, shieldDeploy);
|
public HumanPlayer(int id, Point position, boolean shieldDeploy, ClassPlayer classPlayer) {
|
||||||
|
super(id, position, shieldDeploy, classPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ public class Firearm implements Weapon{
|
|||||||
|
|
||||||
public Firearm(){
|
public Firearm(){
|
||||||
this.bullet = 10;
|
this.bullet = 10;
|
||||||
this.horizontalDistance = 10;
|
this.horizontalDistance = 2;
|
||||||
this.verticalDistance = 10;
|
this.verticalDistance = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user