From 6229cc2699fd9c8cc82afbf3248c6d06a4e2e998 Mon Sep 17 00:00:00 2001 From: ManhTanTran <24021619@vnu.edu.vn> Date: Mon, 29 Sep 2025 17:13:19 +0700 Subject: [PATCH 1/5] feat: Brick --- .../com/github/codestorm/brick/Brick.java | 65 +++++++++++++++++++ .../github/codestorm/brick/ExoplodeBrick.java | 18 +++++ .../github/codestorm/brick/NormalBrick.java | 20 ++++++ .../codestorm/brick/ProtectedBrick.java | 5 ++ .../github/codestorm/brick/StrongBrick.java | 28 ++++++++ .../codestorm/gameManager/GameManager.java | 24 +++++++ .../com/github/codestorm/paddle/Paddle.java | 5 ++ 7 files changed, 165 insertions(+) create mode 100644 src/main/java/com/github/codestorm/brick/Brick.java create mode 100644 src/main/java/com/github/codestorm/brick/ExoplodeBrick.java create mode 100644 src/main/java/com/github/codestorm/brick/NormalBrick.java create mode 100644 src/main/java/com/github/codestorm/brick/ProtectedBrick.java create mode 100644 src/main/java/com/github/codestorm/brick/StrongBrick.java create mode 100644 src/main/java/com/github/codestorm/gameManager/GameManager.java create mode 100644 src/main/java/com/github/codestorm/paddle/Paddle.java diff --git a/src/main/java/com/github/codestorm/brick/Brick.java b/src/main/java/com/github/codestorm/brick/Brick.java new file mode 100644 index 0000000..63f663e --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/Brick.java @@ -0,0 +1,65 @@ +package com.github.codestorm.brick; + +public abstract class Brick { + protected int x, y, width, height; + protected boolean destroyed; + + public Brick() {} + + /** + * constructor + */ + public Brick(int x, int y, int width, int height){ + this.x = x; + this.y = y; + this.width = width; + this.height = height; + 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 boolean isDestroyed() { + return destroyed; + } + + public void setDestroyed(boolean destroyed) { + this.destroyed = destroyed; + } + + public void hit() {} + + public int getScore() { + return 0; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java new file mode 100644 index 0000000..b9a07e5 --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java @@ -0,0 +1,18 @@ +package com.github.codestorm.brick; + +public class ExoplodeBrick extends Brick { + private int radius = 1; + + public ExoplodeBrick(int x, int y, int width, int height, int radius){ + super(x, y, width, height); + this.radius = radius; + } + + @Override + public void hit(){ + this.destroyed = true; + explode(); + } + + private void explode{}; +} diff --git a/src/main/java/com/github/codestorm/brick/NormalBrick.java b/src/main/java/com/github/codestorm/brick/NormalBrick.java new file mode 100644 index 0000000..7e95763 --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/NormalBrick.java @@ -0,0 +1,20 @@ +package com.github.codestorm.brick; + +public class NormalBrick extends Brick { + + public NormalBrick(int x, int y, int width, int height){ + super(x, y, width, height); + } + + @Override + public void hit(){ + this.destroyed = true; + } + + @Override + public int getScore(){ + return 10; + } + + +} diff --git a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java new file mode 100644 index 0000000..6a4c0a7 --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java @@ -0,0 +1,5 @@ +package com.github.codestorm.brick; + +public class ProtectedBrick extends Brick{ + +} diff --git a/src/main/java/com/github/codestorm/brick/StrongBrick.java b/src/main/java/com/github/codestorm/brick/StrongBrick.java new file mode 100644 index 0000000..008ed8f --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/StrongBrick.java @@ -0,0 +1,28 @@ +package com.github.codestorm.brick; + +public class StrongBrick extends Brick { + private int hp; + private final int initialHp; + + public StrongBrick(int x, int y, int width, int height, int hp){ + super(x, y, width, height); + this.hp = hp; + this.initialHp = hp; + } + + @Override + public void hit(){ + if(!destroyed && hp >0){ + hp--; + if(hp == 0){ + destroyed = true; + } + + } + } + + @Override + public int getScore(){ + return initialHp*10; + } +} diff --git a/src/main/java/com/github/codestorm/gameManager/GameManager.java b/src/main/java/com/github/codestorm/gameManager/GameManager.java new file mode 100644 index 0000000..12d8d40 --- /dev/null +++ b/src/main/java/com/github/codestorm/gameManager/GameManager.java @@ -0,0 +1,24 @@ +package com.github.codestorm.gameManager; + +import java.util.List; + +import com.github.codestorm.brick.Brick; +import com.github.codestorm.paddle.Paddle; + +public class GameManager { + private Paddle paddle; + private Ball ball; + private List bricks; + private List powerups; + private int score; + private int lives; + private int level; + + public void updateScore() { + for (Brick x : bricks) { + if (x.isDestroyed()) { + score += x.getScore(); + } + } + } +} diff --git a/src/main/java/com/github/codestorm/paddle/Paddle.java b/src/main/java/com/github/codestorm/paddle/Paddle.java new file mode 100644 index 0000000..1dae678 --- /dev/null +++ b/src/main/java/com/github/codestorm/paddle/Paddle.java @@ -0,0 +1,5 @@ +package com.github.codestorm.paddle; + +public class Paddle { + +} From 7418ab18472511659043702d7e9f49b864219776 Mon Sep 17 00:00:00 2001 From: ManhTanTran <24021619@vnu.edu.vn> Date: Tue, 30 Sep 2025 08:15:19 +0700 Subject: [PATCH 2/5] feat(brick): add PowerBrick and update Brick, ExoplodeBrick, ProtectedBrick --- .../com/github/codestorm/brick/Brick.java | 42 ++++++++++++------- .../github/codestorm/brick/ExoplodeBrick.java | 21 ++++++---- .../github/codestorm/brick/PowerBrick.java | 17 ++++++++ .../codestorm/brick/ProtectedBrick.java | 26 +++++++++++- 4 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/github/codestorm/brick/PowerBrick.java diff --git a/src/main/java/com/github/codestorm/brick/Brick.java b/src/main/java/com/github/codestorm/brick/Brick.java index 63f663e..dffbff8 100644 --- a/src/main/java/com/github/codestorm/brick/Brick.java +++ b/src/main/java/com/github/codestorm/brick/Brick.java @@ -1,19 +1,18 @@ package com.github.codestorm.brick; -public abstract class Brick { - protected int x, y, width, height; - protected boolean destroyed; - - public Brick() {} - - /** - * constructor - */ - public Brick(int x, int y, int width, int height){ +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; } @@ -49,17 +48,32 @@ 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 destroyed; + return hp <= 0; } public void setDestroyed(boolean destroyed) { this.destroyed = destroyed; } - public void hit() {} + public void hit() { + if(!destroyed && hp >0){ + hp--; + if(hp == 0){ + this.destroyed = true; + } + } + } public int getScore() { - return 0; + return initialHp*10; } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java index b9a07e5..c6d0ac8 100644 --- a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java +++ b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java @@ -1,18 +1,23 @@ package com.github.codestorm.brick; public class ExoplodeBrick extends Brick { - private int radius = 1; + private static final int radius = 1; - public ExoplodeBrick(int x, int y, int width, int height, int radius){ - super(x, y, width, height); - this.radius = radius; + public ExoplodeBrick(int x, int y, int width, int height, int hp, int radius) { + super(x, y, width, height, hp); + } + + public int getRadius(){ + return radius; } @Override - public void hit(){ - this.destroyed = true; - explode(); + public void hit() { + super.hit(); + if(isDestroyed()){ + explode(); + } } - private void explode{}; + private void explode() {} } diff --git a/src/main/java/com/github/codestorm/brick/PowerBrick.java b/src/main/java/com/github/codestorm/brick/PowerBrick.java new file mode 100644 index 0000000..85ee6ce --- /dev/null +++ b/src/main/java/com/github/codestorm/brick/PowerBrick.java @@ -0,0 +1,17 @@ +package com.github.codestorm.brick; + +public class PowerBrick extends Brick { + public PowerBrick (int x, int y, int width, int height, int hp){ + super(x, y, width, height, hp); + } + + @Override + public void hit(){ + super.hit(); + if(isDestroyed()){ + activePower(); + } + } + + public void activePower() {}; +} diff --git a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java index 6a4c0a7..cd86864 100644 --- a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java +++ b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java @@ -1,5 +1,27 @@ package com.github.codestorm.brick; -public class ProtectedBrick extends 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; + } + + public void hit(String direction) { + if (!isDestroyed()) { + if (!direction.equalsIgnoreCase(shieldSide)) { + super.hit(); + } + } + } + } From b4f06227f6472b4d7fb0ffc466b870d89a21fa70 Mon Sep 17 00:00:00 2001 From: ManhTanTran <24021619@vnu.edu.vn> Date: Tue, 30 Sep 2025 09:16:27 +0700 Subject: [PATCH 3/5] docs(brick): add Javadoc for Brick, ExoplodeBrick, PowerBrick, ProtectedBrick --- .../com/github/codestorm/brick/Brick.java | 16 +++++++++++----- .../github/codestorm/brick/ExoplodeBrick.java | 15 +++++++++++++-- .../github/codestorm/brick/PowerBrick.java | 19 +++++++++++++++---- .../codestorm/brick/ProtectedBrick.java | 9 +++++++-- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/github/codestorm/brick/Brick.java b/src/main/java/com/github/codestorm/brick/Brick.java index dffbff8..99ddacd 100644 --- a/src/main/java/com/github/codestorm/brick/Brick.java +++ b/src/main/java/com/github/codestorm/brick/Brick.java @@ -48,11 +48,11 @@ public void setHeight(int height) { this.height = height; } - public int getHp(){ + public int getHp() { return hp; } - public void setHp(int hp){ + public void setHp(int hp) { this.hp = hp; } @@ -64,16 +64,22 @@ 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){ + if (!destroyed && hp > 0) { hp--; - if(hp == 0){ + if (hp == 0) { this.destroyed = true; } } } + // Calculates the score awarded for destroying this brick. public int getScore() { - return initialHp*10; + return initialHp * 10; } } diff --git a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java index c6d0ac8..6c0134d 100644 --- a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java +++ b/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java @@ -7,17 +7,28 @@ public ExoplodeBrick(int x, int y, int width, int height, int hp, int radius) { super(x, y, width, height, hp); } - public int getRadius(){ + public int getRadius() { return radius; } + /** + * 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()){ + 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/brick/PowerBrick.java b/src/main/java/com/github/codestorm/brick/PowerBrick.java index 85ee6ce..46b0b20 100644 --- a/src/main/java/com/github/codestorm/brick/PowerBrick.java +++ b/src/main/java/com/github/codestorm/brick/PowerBrick.java @@ -1,17 +1,28 @@ package com.github.codestorm.brick; public class PowerBrick extends Brick { - public PowerBrick (int x, int y, int width, int height, int hp){ + 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(){ + public void hit() { super.hit(); - if(isDestroyed()){ + if (isDestroyed()) { activePower(); } } - public void 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/brick/ProtectedBrick.java b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java index cd86864..4018d64 100644 --- a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java +++ b/src/main/java/com/github/codestorm/brick/ProtectedBrick.java @@ -8,14 +8,15 @@ public ProtectedBrick(int x, int y, int width, int height, int hp, String shield this.shieldSide = shieldSide; } - public String getShieldSide(){ + public String getShieldSide() { return shieldSide; } - public void setShieldSide(String 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)) { @@ -24,4 +25,8 @@ public void hit(String direction) { } } + // Score from protected brick have more than 20 points. + public int getScore() { + return super.getScore() + 20; + } } From 89c507ad5f2a493f942cf6b167195a98654be3ff Mon Sep 17 00:00:00 2001 From: ManhTanTran <24021619@vnu.edu.vn> Date: Tue, 30 Sep 2025 09:22:30 +0700 Subject: [PATCH 4/5] refactor(brick): remove NormalBrick and StrongBrick --- .../github/codestorm/brick/NormalBrick.java | 20 ------------- .../github/codestorm/brick/StrongBrick.java | 28 ------------------- 2 files changed, 48 deletions(-) delete mode 100644 src/main/java/com/github/codestorm/brick/NormalBrick.java delete mode 100644 src/main/java/com/github/codestorm/brick/StrongBrick.java diff --git a/src/main/java/com/github/codestorm/brick/NormalBrick.java b/src/main/java/com/github/codestorm/brick/NormalBrick.java deleted file mode 100644 index 7e95763..0000000 --- a/src/main/java/com/github/codestorm/brick/NormalBrick.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.codestorm.brick; - -public class NormalBrick extends Brick { - - public NormalBrick(int x, int y, int width, int height){ - super(x, y, width, height); - } - - @Override - public void hit(){ - this.destroyed = true; - } - - @Override - public int getScore(){ - return 10; - } - - -} diff --git a/src/main/java/com/github/codestorm/brick/StrongBrick.java b/src/main/java/com/github/codestorm/brick/StrongBrick.java deleted file mode 100644 index 008ed8f..0000000 --- a/src/main/java/com/github/codestorm/brick/StrongBrick.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.codestorm.brick; - -public class StrongBrick extends Brick { - private int hp; - private final int initialHp; - - public StrongBrick(int x, int y, int width, int height, int hp){ - super(x, y, width, height); - this.hp = hp; - this.initialHp = hp; - } - - @Override - public void hit(){ - if(!destroyed && hp >0){ - hp--; - if(hp == 0){ - destroyed = true; - } - - } - } - - @Override - public int getScore(){ - return initialHp*10; - } -} From bf9d2fb26917de70d9bff4fe8296b5f30a090624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mai=20Th=C3=A0nh?= <62001770+thnhmai06@users.noreply.github.com> Date: Wed, 1 Oct 2025 00:28:45 +0700 Subject: [PATCH 5/5] 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. --- .idea/google-java-format.xml | 1 + src/main/java/com/github/codestorm/.gitkeep | 0 .../{ => bounceverse}/brick/Brick.java | 2 +- .../brick/ExoplodeBrick.java | 8 +++---- .../{ => bounceverse}/brick/PowerBrick.java | 2 +- .../brick/ProtectedBrick.java | 2 +- .../codestorm/gameManager/GameManager.java | 24 ------------------- .../com/github/codestorm/paddle/Paddle.java | 5 ---- 8 files changed, 8 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/com/github/codestorm/.gitkeep rename src/main/java/com/github/codestorm/{ => bounceverse}/brick/Brick.java (97%) rename src/main/java/com/github/codestorm/{ => bounceverse}/brick/ExoplodeBrick.java (83%) rename src/main/java/com/github/codestorm/{ => bounceverse}/brick/PowerBrick.java (93%) rename src/main/java/com/github/codestorm/{ => bounceverse}/brick/ProtectedBrick.java (94%) delete mode 100644 src/main/java/com/github/codestorm/gameManager/GameManager.java delete mode 100644 src/main/java/com/github/codestorm/paddle/Paddle.java 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/brick/Brick.java b/src/main/java/com/github/codestorm/bounceverse/brick/Brick.java similarity index 97% rename from src/main/java/com/github/codestorm/brick/Brick.java rename to src/main/java/com/github/codestorm/bounceverse/brick/Brick.java index 99ddacd..9b80e18 100644 --- a/src/main/java/com/github/codestorm/brick/Brick.java +++ b/src/main/java/com/github/codestorm/bounceverse/brick/Brick.java @@ -1,4 +1,4 @@ -package com.github.codestorm.brick; +package com.github.codestorm.bounceverse.brick; public class Brick { private int x, y, width, height; diff --git a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java similarity index 83% rename from src/main/java/com/github/codestorm/brick/ExoplodeBrick.java rename to src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java index 6c0134d..c215265 100644 --- a/src/main/java/com/github/codestorm/brick/ExoplodeBrick.java +++ b/src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java @@ -1,14 +1,14 @@ -package com.github.codestorm.brick; +package com.github.codestorm.bounceverse.brick; public class ExoplodeBrick extends Brick { - private static final int radius = 1; + private static final int explodeRadius = 1; - public ExoplodeBrick(int x, int y, int width, int height, int hp, int radius) { + public ExoplodeBrick(int x, int y, int width, int height, int hp) { super(x, y, width, height, hp); } public int getRadius() { - return radius; + return explodeRadius; } /** diff --git a/src/main/java/com/github/codestorm/brick/PowerBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java similarity index 93% rename from src/main/java/com/github/codestorm/brick/PowerBrick.java rename to src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java index 46b0b20..42afcea 100644 --- a/src/main/java/com/github/codestorm/brick/PowerBrick.java +++ b/src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java @@ -1,4 +1,4 @@ -package com.github.codestorm.brick; +package com.github.codestorm.bounceverse.brick; public class PowerBrick extends Brick { public PowerBrick(int x, int y, int width, int height, int hp) { diff --git a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java b/src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java similarity index 94% rename from src/main/java/com/github/codestorm/brick/ProtectedBrick.java rename to src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java index 4018d64..3e67912 100644 --- a/src/main/java/com/github/codestorm/brick/ProtectedBrick.java +++ b/src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java @@ -1,4 +1,4 @@ -package com.github.codestorm.brick; +package com.github.codestorm.bounceverse.brick; public class ProtectedBrick extends Brick { private String shieldSide; diff --git a/src/main/java/com/github/codestorm/gameManager/GameManager.java b/src/main/java/com/github/codestorm/gameManager/GameManager.java deleted file mode 100644 index 12d8d40..0000000 --- a/src/main/java/com/github/codestorm/gameManager/GameManager.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.codestorm.gameManager; - -import java.util.List; - -import com.github.codestorm.brick.Brick; -import com.github.codestorm.paddle.Paddle; - -public class GameManager { - private Paddle paddle; - private Ball ball; - private List bricks; - private List powerups; - private int score; - private int lives; - private int level; - - public void updateScore() { - for (Brick x : bricks) { - if (x.isDestroyed()) { - score += x.getScore(); - } - } - } -} diff --git a/src/main/java/com/github/codestorm/paddle/Paddle.java b/src/main/java/com/github/codestorm/paddle/Paddle.java deleted file mode 100644 index 1dae678..0000000 --- a/src/main/java/com/github/codestorm/paddle/Paddle.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.codestorm.paddle; - -public class Paddle { - -}