This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Merged
feat: Brick #1
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6229cc2
feat: Brick
ManhTanTran 7418ab1
feat(brick): add PowerBrick and update Brick, ExoplodeBrick, Protecte…
ManhTanTran b4f0622
docs(brick): add Javadoc for Brick, ExoplodeBrick, PowerBrick, Protec…
ManhTanTran 89c507a
refactor(brick): remove NormalBrick and StrongBrick
ManhTanTran bf9d2fb
refactor(brick): rename packages and update formatting settings
thnhmai06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
85 changes: 85 additions & 0 deletions
85
src/main/java/com/github/codestorm/bounceverse/brick/Brick.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| private boolean destroyed; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should define |
||
|
|
||
| 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; | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/codestorm/bounceverse/brick/ExoplodeBrick.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() {} | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/github/codestorm/bounceverse/brick/PowerBrick.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use |
||
| 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() {} | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/main/java/com/github/codestorm/bounceverse/brick/ProtectedBrick.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must using Enum for |
||
|
|
||
| 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; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary