Skip to content

Commit

Permalink
fixed plant cost
Browse files Browse the repository at this point in the history
  • Loading branch information
MargheritaZanchini committed Feb 17, 2024
1 parent 82de10b commit 710f09d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/main/java/pvzclone/model/impl/GameImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public final class GameImpl implements Game {
private static final int DELTA_TIME_FIRST_ZOMBIE = 4000;

// Base plant
private static final int PLANT_COST = 20;
private static final int DAMAGE_BASE_PLANT = 20;
private static final int LIFE_BASE_PLANT = 100;
private static final int COOLDOWN_BASE_PLANT = 3000;
Expand Down Expand Up @@ -192,9 +191,9 @@ private void createWave() {

@Override
public boolean createPlant(final Pair<Integer, Integer> position) {
if (this.gameState.getSunScore() >= PLANT_COST) {
if (this.gameState.getSunScore() >= PlantImpl.PLANT_COST) {
final PlantImpl newPlant = new PlantImpl(DAMAGE_BASE_PLANT, LIFE_BASE_PLANT, "Plant", position,
COOLDOWN_BASE_PLANT, PLANT_COST);
COOLDOWN_BASE_PLANT);
plants.add(newPlant);
this.gameState.decSunScore(newPlant.getPlantCost());
return true;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/pvzclone/model/impl/PlantImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

public final class PlantImpl implements Plant {

private final int cost;
/**
* is the cost of the plant.
*/
public static final int PLANT_COST = 100;

private final double damage;
private final String entityName;
private final Pair<Integer, Integer> position;
Expand All @@ -24,11 +28,9 @@ public final class PlantImpl implements Plant {
* @param entityName is the name of the entity, for the plant is "plant"
* @param position is the position of the plant
* @param cooldown is the time between two attack of the plant
* @param cost is the Sun cost of the plant
*/
public PlantImpl(final double damage, final double remainingLife, final String entityName,
final Pair<Integer, Integer> position, final long cooldown, final int cost) {
this.cost = cost;
final Pair<Integer, Integer> position, final long cooldown) {
this.damage = damage;
this.remainingLife = remainingLife;
this.entityName = entityName;
Expand Down Expand Up @@ -84,7 +86,7 @@ public long getLastTimeAttack() {

@Override
public int getPlantCost() {
return this.cost;
return PlantImpl.PLANT_COST;
}

}
3 changes: 2 additions & 1 deletion src/main/java/pvzclone/view/impl/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pvzclone.model.api.Entities;
import pvzclone.model.api.Sun;
import pvzclone.model.impl.Pair;
import pvzclone.model.impl.PlantImpl;

/**
* Panel used in the Gameplay Section.
Expand Down Expand Up @@ -129,7 +130,7 @@ public GamePanel(final SwingViewImpl parent, final String backgroundSource) {
plantCardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (parent.getController().getSunScore() >= 100) {
if (parent.getController().getSunScore() >= PlantImpl.PLANT_COST) {
userIsPlanting = !userIsPlanting;
if (userIsPlanting) {
showGrid();
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/pvzclone/PlantTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ final class PlantTest {
private static final String NAME = "plant";
private static final Pair<Integer, Integer> POS = new Pair<>(0, 0);
private static final long COOLDOWN = 3000;
private static final int COST = 100;

private final Plant plant = new PlantImpl(DAMAGE, LIFE, NAME, POS, COOLDOWN, COST);
private final Plant plant = new PlantImpl(DAMAGE, LIFE, NAME, POS, COOLDOWN);

@Test
void isPlantAliveWithCorrectValues() {
Expand All @@ -32,7 +31,6 @@ void isPlantAliveWithCorrectValues() {
assertEquals(NAME, plant.getEntityName());
assertEquals(POS, plant.getPosition());
assertEquals(COOLDOWN, plant.getCooldown());
assertEquals(COST, plant.getPlantCost());
}

@Test
Expand Down

0 comments on commit 710f09d

Please sign in to comment.