Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit b0844df

Browse files
feat: Brick (#1)
* feat: Brick * feat(brick): add PowerBrick and update Brick, ExoplodeBrick, ProtectedBrick * docs(brick): add Javadoc for Brick, ExoplodeBrick, PowerBrick, ProtectedBrick * refactor(brick): remove NormalBrick and StrongBrick * refactor(brick): rename packages and update formatting settings - Renamed package from `com.github.codestorm.brick` to `com.github.codestorm.bounceverse.brick` for consistency. - Updated Google Java Format settings to use AOSP style. --------- Co-authored-by: Mai Thành <62001770+thnhmai06@users.noreply.github.com>
1 parent 90d06b7 commit b0844df

4 files changed

Lines changed: 179 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.github.codestorm.bounceverse.brick;
2+
3+
public class Brick {
4+
private int x, y, width, height;
5+
private int hp;
6+
private final int initialHp;
7+
private boolean destroyed;
8+
9+
public Brick(int x, int y, int width, int height, int hp) {
10+
this.x = x;
11+
this.y = y;
12+
this.width = width;
13+
this.height = height;
14+
this.hp = hp;
15+
this.initialHp = hp;
16+
this.destroyed = false;
17+
}
18+
19+
public int getX() {
20+
return x;
21+
}
22+
23+
public void setX(int x) {
24+
this.x = x;
25+
}
26+
27+
public int getY() {
28+
return y;
29+
}
30+
31+
public void setY(int y) {
32+
this.y = y;
33+
}
34+
35+
public int getWidth() {
36+
return width;
37+
}
38+
39+
public void setWidth(int width) {
40+
this.width = width;
41+
}
42+
43+
public int getHeight() {
44+
return height;
45+
}
46+
47+
public void setHeight(int height) {
48+
this.height = height;
49+
}
50+
51+
public int getHp() {
52+
return hp;
53+
}
54+
55+
public void setHp(int hp) {
56+
this.hp = hp;
57+
}
58+
59+
public boolean isDestroyed() {
60+
return hp <= 0;
61+
}
62+
63+
public void setDestroyed(boolean destroyed) {
64+
this.destroyed = destroyed;
65+
}
66+
67+
/**
68+
* Reduces the brick's hit points by one when hit.
69+
*
70+
* <p>If hit points reach zero, the brick is marked as destroyed.
71+
*/
72+
public void hit() {
73+
if (!destroyed && hp > 0) {
74+
hp--;
75+
if (hp == 0) {
76+
this.destroyed = true;
77+
}
78+
}
79+
}
80+
81+
// Calculates the score awarded for destroying this brick.
82+
public int getScore() {
83+
return initialHp * 10;
84+
}
85+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.codestorm.bounceverse.brick;
2+
3+
public class ExoplodeBrick extends Brick {
4+
private static final int explodeRadius = 1;
5+
6+
public ExoplodeBrick(int x, int y, int width, int height, int hp) {
7+
super(x, y, width, height, hp);
8+
}
9+
10+
public int getRadius() {
11+
return explodeRadius;
12+
}
13+
14+
/**
15+
* Handles a hit on this brick.
16+
*
17+
* <p>Decreases hit points using the parent logic. If the brick is destroyed after the hit, it
18+
* triggers an explosion.
19+
*/
20+
@Override
21+
public void hit() {
22+
super.hit();
23+
if (isDestroyed()) {
24+
explode();
25+
}
26+
}
27+
28+
/**
29+
* Triggers the explosion effect of this brick.
30+
*
31+
* <p>This method can be extended to apply damage to surrounding bricks
32+
*/
33+
private void explode() {}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.codestorm.bounceverse.brick;
2+
3+
public class PowerBrick extends Brick {
4+
public PowerBrick(int x, int y, int width, int height, int hp) {
5+
super(x, y, width, height, hp);
6+
}
7+
8+
/**
9+
* Handles a hit on this power brick.
10+
*
11+
* <p>Executes the normal hit logic from the parent class. If the brick is destroyed after the
12+
* hit, it will randomly spawn its power-up.
13+
*/
14+
@Override
15+
public void hit() {
16+
super.hit();
17+
if (isDestroyed()) {
18+
activePower();
19+
}
20+
}
21+
22+
/**
23+
* Spawns the power-up associated with this brick.
24+
*
25+
* <p>Subclasses should override this method to define the specific power-up effect.
26+
*/
27+
public void activePower() {}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.codestorm.bounceverse.brick;
2+
3+
public class ProtectedBrick extends Brick {
4+
private String shieldSide;
5+
6+
public ProtectedBrick(int x, int y, int width, int height, int hp, String shieldSide) {
7+
super(x, y, width, height, hp);
8+
this.shieldSide = shieldSide;
9+
}
10+
11+
public String getShieldSide() {
12+
return shieldSide;
13+
}
14+
15+
public void setShieldSide(String shieldSide) {
16+
this.shieldSide = shieldSide;
17+
}
18+
19+
/** Handles a hit on this protected brick from a given direction. */
20+
public void hit(String direction) {
21+
if (!isDestroyed()) {
22+
if (!direction.equalsIgnoreCase(shieldSide)) {
23+
super.hit();
24+
}
25+
}
26+
}
27+
28+
// Score from protected brick have more than 20 points.
29+
public int getScore() {
30+
return super.getScore() + 20;
31+
}
32+
}

0 commit comments

Comments
 (0)