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 @@ \ No newline at end of file diff --git a/src/main/java/com/github/codestorm/.gitkeep b/src/main/java/com/github/codestorm/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/github/codestorm/bounceverse/brick/Brick.java b/src/main/java/com/github/codestorm/bounceverse/brick/Brick.java new file mode 100644 index 0000000..9b80e18 --- /dev/null +++ b/src/main/java/com/github/codestorm/bounceverse/brick/Brick.java @@ -0,0 +1,85 @@ +package com.github.codestorm.bounceverse.brick; + +public class Brick { + private int x, y, width, height; + private int hp; + private final int initialHp; + private boolean destroyed; + + public Brick(int x, int y, int width, int height, int hp) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.hp = hp; + this.initialHp = hp; + this.destroyed = false; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getHp() { + return hp; + } + + public void setHp(int hp) { + this.hp = hp; + } + + public boolean isDestroyed() { + return hp <= 0; + } + + public void setDestroyed(boolean destroyed) { + this.destroyed = destroyed; + } + + /** + * Reduces the brick's hit points by one when hit. + * + *

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; + } +}