Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
85 changes: 85 additions & 0 deletions src/main/java/com/github/codestorm/bounceverse/brick/Brick.java
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary

private boolean destroyed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should define destroyed as a method (depend on hp)


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.
*
* <p>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;
}
}
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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.
*
* <p>This method can be extended to apply damage to surrounding bricks
*/
private void explode() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.codestorm.bounceverse.brick;

public class PowerBrick extends Brick {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use PowerUp as a attribute of Brick (The "rewards" after broke 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.
*
* <p>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.
*
* <p>Subclasses should override this method to define the specific power-up effect.
*/
public void activePower() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.codestorm.bounceverse.brick;

public class ProtectedBrick extends Brick {
private String shieldSide;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must using Enum for 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;
}
}
Loading