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 e31e83b commit 6898d11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/main/java/pvzclone/model/impl/GameImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class GameImpl implements Game {
private static final int DELTA_TIME_FIRST_ZOMBIE = 4000;

// Base plant
private static final int PLANT_COST = 100;
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,7 +192,7 @@ private void createWave() {

@Override
public boolean createPlant(final Pair<Integer, Integer> position) {
if (this.gameState.getSunScore() >= 100) {
if (this.gameState.getSunScore() >= PLANT_COST) {
final PlantImpl newPlant = new PlantImpl(DAMAGE_BASE_PLANT, LIFE_BASE_PLANT, "Plant", position,
COOLDOWN_BASE_PLANT, PLANT_COST);
plants.add(newPlant);
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/pvzclone/view/impl/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

/**
* Panel used in the Gameplay Section.
*
* @author Marco Marrelli
*/
@SuppressFBWarnings(value = {
"SE_TRANSIENT_FIELD_NOT_RESTORED",
Expand All @@ -46,12 +48,12 @@ public final class GamePanel extends GenericPanel {
private static final int X_MARGIN = 10; // 20/2
private static final int Y_MARGIN = 15; // 30/2

private static final String PLANT_CARD = "images/plantCard.png";
private static final String SUN_COUNTER_IMAGE = "images/sunCounter.jpg";
private static final String PLANT_IMAGE = "images/plantPeaShooter.png";
private static final String ZOMBIE_IMAGE = "images/zombieEntity.png";
private static final String BULLET_IMAGE = "images/ProjectilePea.png";
private static final String SUN_IMAGE = "images/sunEntity.png";
private static final String PLANT_CARD = "src/main/resources/images/plantCard.png";
private static final String SUN_COUNTER_IMAGE = "src/main/resources/images/sunCounter.jpg";
private static final String PLANT_IMAGE = "src/main/resources/images/plantPeaShooter.png";
private static final String ZOMBIE_IMAGE = "src/main/resources/images/zombieEntity.png";
private static final String BULLET_IMAGE = "src/main/resources/images/ProjectilePea.png";
private static final String SUN_IMAGE = "src/main/resources/images/sunEntity.png";

private static final int FIELD_STARTING_X = 220;
private static final int FIELD_STARTING_Y = 110;
Expand Down Expand Up @@ -122,7 +124,7 @@ public GamePanel(final SwingViewImpl parent, final String backgroundSource) {
}

final JButton plantCardButton = new JButton();
plantCardButton.setIcon(new ImageIcon(ClassLoader.getSystemResource(PLANT_CARD)));
plantCardButton.setIcon(new ImageIcon(PLANT_CARD));
plantCardButton.setBounds(CARD_STARTING_X, CARD_STARTING_Y, CARD_WIDTH, CARD_HEIGHT);
plantCardButton.addActionListener(new ActionListener() {
@Override
Expand All @@ -146,7 +148,7 @@ public void actionPerformed(final ActionEvent e) {
this.add(this.points);

final JLabel sunCounterImage = new JLabel();
sunCounterImage.setIcon(new ImageIcon(ClassLoader.getSystemResource(SUN_COUNTER_IMAGE)));
sunCounterImage.setIcon(new ImageIcon(SUN_COUNTER_IMAGE));
sunCounterImage.setBounds(SUN_COUNTER_STARTING_X, SUN_COUNTER_STARTING_Y, SUN_COUNTER_WIDTH,
SUN_COUNTER_HEIGHT);
this.add(sunCounterImage);
Expand Down Expand Up @@ -256,15 +258,14 @@ private void updateEntities(final Graphics2D g) {
* @return image of the entity.
*/
private ImageIcon getEntityImage(final Entities entity) {
final String resource = switch (entity.getEntityName()) {
case "Plant" -> PLANT_IMAGE;
case "Zombie" -> ZOMBIE_IMAGE;
case "Bullet" -> BULLET_IMAGE;
case "Sun" -> SUN_IMAGE;
default -> throw new IllegalArgumentException("Unexpected value: " + entity.getClass().getName());
};

return new ImageIcon(ClassLoader.getSystemResource(resource));
return new ImageIcon(
switch (entity.getEntityName()) {
case "Plant" -> PLANT_IMAGE;
case "Zombie" -> ZOMBIE_IMAGE;
case "Bullet" -> BULLET_IMAGE;
case "Sun" -> SUN_IMAGE;
default -> throw new IllegalArgumentException("Unexpected value: " + entity.getClass().getName());
});
}

/**
Expand Down Expand Up @@ -315,8 +316,8 @@ private void updateMatrix() {
public void endGame(final boolean win) {
this.removeAll();

final URL url = win ? ClassLoader.getSystemResource("images/winner.gif")
: ClassLoader.getSystemResource("images/loser.gif");
final URL url = win ? this.getClass().getResource("/images/winner.gif")
: this.getClass().getResource("/images/loser.gif");
final int scaledX = (int) (SwingViewImpl.APPLICATION_WIDTH * this.parent.getScale().getX());
final int scaledY = (int) (SwingViewImpl.APPLICATION_HEIGHT * this.parent.getScale().getY());
final Icon icon = new ImageIcon(
Expand Down

0 comments on commit 6898d11

Please sign in to comment.