diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml
index 8b57f45..05946a8 100644
--- a/.idea/google-java-format.xml
+++ b/.idea/google-java-format.xml
@@ -2,5 +2,6 @@
If hit points reach zero, the brick is marked as destroyed. + */ + public void hit() { + if (!destroyed && hp > 0) { + hp--; + if (hp == 0) { + this.destroyed = true; + } + } + } + + // Calculates the score awarded for destroying this brick. + public int getScore() { + return initialHp * 10; + } +} diff --git a/src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java new file mode 100644 index 0000000..c215265 --- /dev/null +++ b/src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java @@ -0,0 +1,34 @@ +package com.github.codestorm.bounceverse.brick; + +public class ExoplodeBrick extends Brick { + private static final int explodeRadius = 1; + + public ExoplodeBrick(int x, int y, int width, int height, int hp) { + super(x, y, width, height, hp); + } + + public int getRadius() { + return explodeRadius; + } + + /** + * Handles a hit on this brick. + * + *
Decreases hit points using the parent logic. If the brick is destroyed after the hit, it + * triggers an explosion. + */ + @Override + public void hit() { + super.hit(); + if (isDestroyed()) { + explode(); + } + } + + /** + * Triggers the explosion effect of this brick. + * + *
This method can be extended to apply damage to surrounding bricks + */ + private void explode() {} +} diff --git a/src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java new file mode 100644 index 0000000..42afcea --- /dev/null +++ b/src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java @@ -0,0 +1,28 @@ +package com.github.codestorm.bounceverse.brick; + +public class PowerBrick extends Brick { + public PowerBrick(int x, int y, int width, int height, int hp) { + super(x, y, width, height, hp); + } + + /** + * Handles a hit on this power brick. + * + *
Executes the normal hit logic from the parent class. If the brick is destroyed after the + * hit, it will randomly spawn its power-up. + */ + @Override + public void hit() { + super.hit(); + if (isDestroyed()) { + activePower(); + } + } + + /** + * Spawns the power-up associated with this brick. + * + *
Subclasses should override this method to define the specific power-up effect. + */ + public void activePower() {} +} diff --git a/src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java new file mode 100644 index 0000000..3e67912 --- /dev/null +++ b/src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java @@ -0,0 +1,32 @@ +package com.github.codestorm.bounceverse.brick; + +public class ProtectedBrick extends Brick { + private String shieldSide; + + public ProtectedBrick(int x, int y, int width, int height, int hp, String shieldSide) { + super(x, y, width, height, hp); + this.shieldSide = shieldSide; + } + + public String getShieldSide() { + return shieldSide; + } + + public void setShieldSide(String shieldSide) { + this.shieldSide = shieldSide; + } + + /** Handles a hit on this protected brick from a given direction. */ + public void hit(String direction) { + if (!isDestroyed()) { + if (!direction.equalsIgnoreCase(shieldSide)) { + super.hit(); + } + } + } + + // Score from protected brick have more than 20 points. + public int getScore() { + return super.getScore() + 20; + } +}