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

Commit e977330

Browse files
committed
chore: reformatting code
1 parent 6017a9b commit e977330

12 files changed

Lines changed: 408 additions & 393 deletions

File tree

src/main/java/com/github/codestorm/bounceverse/Bounceverse.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.codestorm.bounceverse;
22

3-
import java.io.IOException;
4-
53
import com.almasb.fxgl.app.GameApplication;
64
import com.almasb.fxgl.app.GameSettings;
75
import com.github.codestorm.bounceverse.core.LaunchOptions;
@@ -11,19 +9,18 @@
119
import com.github.codestorm.bounceverse.core.systems.PhysicSystem;
1210
import com.github.codestorm.bounceverse.core.systems.UISystem;
1311
import com.github.codestorm.bounceverse.typing.exceptions.BounceverseException;
12+
import java.io.IOException;
1413

1514
/**
1615
*
1716
*
1817
* <h1>{@link Bounceverse}</h1>
1918
*
20-
* Phần Hệ thống Chương trình chính của game, nơi mà mọi thứ bắt đầu từ
21-
* {@link #main(String[])}...
19+
* Phần Hệ thống Chương trình chính của game, nơi mà mọi thứ bắt đầu từ {@link #main(String[])}...
2220
* <br>
23-
* <i>Game {@link Bounceverse} được lấy cảm hứng từ game Arkanoid nổi tiếng, nơi
24-
* người chơi điều khiển một thanh để đỡ bóng và phá vỡ các viên gạch. Mục tiêu
25-
* của game là phá vỡ tất cả các viên gạch và dành được điểm số cao nhất. Nhưng
26-
* liệu mọi thứ chỉ đơn giản như vậy?</i>
21+
* <i>Game {@link Bounceverse} được lấy cảm hứng từ game Arkanoid nổi tiếng, nơi người chơi điều
22+
* khiển một thanh để đỡ bóng và phá vỡ các viên gạch. Mục tiêu của game là phá vỡ tất cả các viên
23+
* gạch và dành được điểm số cao nhất. Nhưng liệu mọi thứ chỉ đơn giản như vậy?</i>
2724
*/
2825
public final class Bounceverse extends GameApplication {
2926

src/main/java/com/github/codestorm/bounceverse/Utils.java

Lines changed: 38 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.github.codestorm.bounceverse;
22

3+
import com.almasb.fxgl.dsl.FXGL;
4+
import com.almasb.fxgl.entity.Entity;
5+
import com.almasb.fxgl.physics.PhysicsComponent;
6+
import com.almasb.fxgl.time.TimerAction;
7+
import com.github.codestorm.bounceverse.data.types.DirectionUnit;
38
import java.io.IOException;
49
import java.io.InputStream;
510
import java.util.ArrayList;
@@ -8,41 +13,27 @@
813
import java.util.Map;
914
import java.util.Properties;
1015
import java.util.Scanner;
11-
12-
import com.almasb.fxgl.dsl.FXGL;
13-
import com.almasb.fxgl.entity.Entity;
14-
import com.almasb.fxgl.physics.PhysicsComponent;
15-
import com.almasb.fxgl.time.TimerAction;
16-
import com.github.codestorm.bounceverse.data.types.DirectionUnit;
17-
18-
import javafx.geometry.Rectangle2D;
1916
import javafx.geometry.Point2D;
17+
import javafx.geometry.Rectangle2D;
2018
import javafx.scene.shape.Circle;
2119
import javafx.util.Duration;
2220

23-
/**
24-
* Utilities.
25-
*/
21+
/** Utilities. */
2622
public final class Utils {
2723

28-
private Utils() {
29-
}
24+
private Utils() {}
3025

31-
/**
32-
* Input/Output utilities.
33-
*/
26+
/** Input/Output utilities. */
3427
public static final class IO {
3528

36-
private IO() {
37-
}
29+
private IO() {}
3830

3931
/**
4032
* Load .properties file.
4133
*
4234
* @param path Relative path
4335
* @return Parsed properties
44-
* @throws IOException if an error occurred when reading from the input
45-
* stream.
36+
* @throws IOException if an error occurred when reading from the input stream.
4637
*/
4738
public static Properties loadProperties(String path) throws IOException {
4839
InputStream fileStream = IO.class.getResourceAsStream(path);
@@ -57,18 +48,16 @@ public static Properties loadProperties(String path) throws IOException {
5748
}
5849

5950
/**
60-
* Convert an array of key=value pairs into a hashmap. The string "key="
61-
* maps key onto "", while just "key" maps key onto null. The value may
62-
* contain '=' characters, only the first "=" is a delimiter. <br>
63-
* Source code from
64-
* <a href="https://stackoverflow.com/a/52940215/16410937">here</a>.
51+
* Convert an array of key=value pairs into a hashmap. The string "key=" maps key onto "",
52+
* while just "key" maps key onto null. The value may contain '=' characters, only the first
53+
* "=" is a delimiter. <br>
54+
* Source code from <a href="https://stackoverflow.com/a/52940215/16410937">here</a>.
6555
*
66-
* @param args command-line arguments in the key=value format (or just
67-
* key= or key)
68-
* @param defaults a map of default values, may be null. Mappings to
69-
* null are not copied to the resulting map.
70-
* @param whiteList if not null, the keys not present in this map cause
71-
* an exception (and keys mapped to null are ok)
56+
* @param args command-line arguments in the key=value format (or just key= or key)
57+
* @param defaults a map of default values, may be null. Mappings to null are not copied to
58+
* the resulting map.
59+
* @param whiteList if not null, the keys not present in this map cause an exception (and
60+
* keys mapped to null are ok)
7261
* @return a map that maps these keys onto the corresponding values.
7362
*/
7463
public static HashMap<String, String> parseArgs(
@@ -114,8 +103,7 @@ public static List<String> readTextFile(String path) {
114103
public static final class Time {
115104

116105
/**
117-
* Thời gian hồi để thực hiện lại gì đó. Thực hiện thông qua
118-
* {@link #current}
106+
* Thời gian hồi để thực hiện lại gì đó. Thực hiện thông qua {@link #current}
119107
*
120108
* @see ActiveCooldown
121109
*/
@@ -142,26 +130,20 @@ public ActiveCooldown getCurrent() {
142130
return current;
143131
}
144132

145-
public Cooldown() {
146-
}
133+
public Cooldown() {}
147134

148135
public Cooldown(Duration duration) {
149136
this.duration = duration;
150137
}
151138

152-
/**
153-
* Cooldown thời điểm hiện tại. Giống như một wrapper của
154-
* {@link TimerAction}.
155-
*/
139+
/** Cooldown thời điểm hiện tại. Giống như một wrapper của {@link TimerAction}. */
156140
public final class ActiveCooldown {
157141

158142
private TimerAction waiter = null;
159143
private double timestamp = Double.NaN;
160144
private Runnable onExpiredCallback = null;
161145

162-
/**
163-
* Hành động khi cooldown hết.
164-
*/
146+
/** Hành động khi cooldown hết. */
165147
private void onExpired() {
166148
timestamp = Double.NaN;
167149
if (onExpiredCallback != null) {
@@ -187,18 +169,14 @@ public boolean expired() {
187169
return (waiter == null) || waiter.isExpired();
188170
}
189171

190-
/**
191-
* Khiến cooldown hết hạn ngay (nếu có).
192-
*/
172+
/** Khiến cooldown hết hạn ngay (nếu có). */
193173
public void expire() {
194174
if (!expired()) {
195175
waiter.expire();
196176
}
197177
}
198178

199-
/**
200-
* Set một cooldown mới.
201-
*/
179+
/** Set một cooldown mới. */
202180
public void makeNew() {
203181
expire();
204182

@@ -207,18 +185,14 @@ public void makeNew() {
207185
timestamp = gameTimer.getNow();
208186
}
209187

210-
/**
211-
* Tạm dừng cooldown.
212-
*/
188+
/** Tạm dừng cooldown. */
213189
public void pause() {
214190
if (!expired()) {
215191
waiter.pause();
216192
}
217193
}
218194

219-
/**
220-
* Tiếp tục cooldown.
221-
*/
195+
/** Tiếp tục cooldown. */
222196
public void resume() {
223197
if (!expired()) {
224198
waiter.resume();
@@ -253,8 +227,7 @@ public void reduce(Duration duration) {
253227
}
254228
}
255229

256-
private ActiveCooldown() {
257-
}
230+
private ActiveCooldown() {}
258231
}
259232
}
260233
}
@@ -284,15 +257,15 @@ public static List<Entity> getEntityInCircle(Circle circle) {
284257
* @return Các entity
285258
*/
286259
public static List<Entity> getEntityInCircle(double cx, double cy, double radius) {
287-
final Rectangle2D outRect
288-
= new Rectangle2D(cx - radius, cy - radius, 2 * radius, 2 * radius);
260+
final Rectangle2D outRect =
261+
new Rectangle2D(cx - radius, cy - radius, 2 * radius, 2 * radius);
289262
return FXGL.getGameWorld().getEntitiesInRange(outRect).stream()
290263
.filter(
291264
e -> {
292-
double nearestX
293-
= Math.max(e.getX(), Math.min(cx, e.getX() + e.getWidth()));
294-
double nearestY
295-
= Math.max(e.getY(), Math.min(cy, e.getY() + e.getHeight()));
265+
double nearestX =
266+
Math.max(e.getX(), Math.min(cx, e.getX() + e.getWidth()));
267+
double nearestY =
268+
Math.max(e.getY(), Math.min(cy, e.getY() + e.getHeight()));
296269
double dx = cx - nearestX;
297270
double dy = cy - nearestY;
298271
return (dx * dx + dy * dy) <= radius * radius;
@@ -304,9 +277,9 @@ public static List<Entity> getEntityInCircle(double cx, double cy, double radius
304277
public static final class Collision {
305278

306279
/**
307-
* Xác định hướng va chạm giữa hai Entity bằng cách tính độ chồng lấn
308-
* (overlap). Trả về hướng mà source "tiếp xúc" với target: UP, DOWN,
309-
* LEFT, RIGHT. Nếu không chồng lấn rõ ràng, trả về null.
280+
* Xác định hướng va chạm giữa hai Entity bằng cách tính độ chồng lấn (overlap). Trả về
281+
* hướng mà source "tiếp xúc" với target: UP, DOWN, LEFT, RIGHT. Nếu không chồng lấn rõ
282+
* ràng, trả về null.
310283
*/
311284
public static DirectionUnit getCollisionDirection(Entity source, Entity target) {
312285
var fromBox = source.getBoundingBoxComponent();

src/main/java/com/github/codestorm/bounceverse/components/behaviors/Attachment.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.almasb.fxgl.physics.PhysicsComponent;
77
import com.github.codestorm.bounceverse.factory.entities.BallFactory;
88
import com.github.codestorm.bounceverse.typing.enums.EntityType;
9-
109
import javafx.geometry.Point2D;
1110

1211
public class Attachment extends Component {
@@ -74,8 +73,8 @@ public void releaseBall() {
7473

7574
double dir = (ballCenterX >= paddleCenterX) ? 1 : -1;
7675

77-
double angle = Math.toRadians(45);
78-
double speed = 350;
76+
double angle = Math.toRadians(45);
77+
double speed = 350;
7978

8079
// Tính vận tốc thành phần
8180
double vx = speed * Math.sin(angle) * dir;

src/main/java/com/github/codestorm/bounceverse/components/behaviors/Explosion.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import com.github.codestorm.bounceverse.Utilities;
66
import com.github.codestorm.bounceverse.components.properties.Attributes;
77
import com.github.codestorm.bounceverse.typing.annotations.ForEntity;
8-
9-
import java.util.List;
10-
118
import com.github.codestorm.bounceverse.typing.enums.EntityType;
9+
import java.util.List;
1210

1311
/**
1412
*

src/main/java/com/github/codestorm/bounceverse/components/behaviors/Special.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import com.github.codestorm.bounceverse.typing.annotations.ForEntity;
66
import com.github.codestorm.bounceverse.typing.enums.EntityType;
77

8-
/**
9-
* Khi brick bị phá thì spawn PowerUp.
10-
*/
11-
@ForEntity({ EntityType.BRICK })
8+
/** Khi brick bị phá thì spawn PowerUp. */
9+
@ForEntity({EntityType.BRICK})
1210
public class Special extends Component {
1311

1412
@Override
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package com.github.codestorm.bounceverse.core;
22

3-
public class BackgroundColorVisual {
4-
5-
}
3+
public class BackgroundColorVisual {}

src/main/java/com/github/codestorm/bounceverse/core/systems/GameSystem.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
public final class GameSystem extends System {
1414

15-
private GameSystem() {
16-
}
15+
private GameSystem() {}
1716

1817
public static GameSystem getInstance() {
1918
return GameSystem.Holder.INSTANCE;
@@ -62,26 +61,19 @@ public void apply() {
6261
// Xác định loại brick theo hàng (bạn có thể chỉnh lại tuỳ ý)
6362
String type;
6463
switch (y) {
65-
case 0 ->
66-
type = "shieldBrick"; // Hàng đầu có khiên
67-
case 1 ->
68-
type = "explodingBrick"; // Hàng thứ 2 nổ
69-
case 2 ->
70-
type = "specialBrick"; // Hàng thứ 3 rơi power-up
71-
case 3 ->
72-
type = "strongBrick"; // Hàng thứ 4 trâu
73-
default ->
74-
type = "normalBrick"; // Còn lại là thường
64+
case 0 -> type = "shieldBrick"; // Hàng đầu có khiên
65+
case 1 -> type = "explodingBrick"; // Hàng thứ 2 nổ
66+
case 2 -> type = "specialBrick"; // Hàng thứ 3 rơi power-up
67+
case 3 -> type = "strongBrick"; // Hàng thứ 4 trâu
68+
default -> type = "normalBrick"; // Còn lại là thường
7569
}
7670

7771
FXGL.spawn(type, posX, posY);
7872
}
7973
}
8074

8175
// Paddle
82-
FXGL.getGameWorld()
83-
.getEntitiesByType(EntityType.PADDLE)
84-
.forEach(Entity::removeFromWorld);
76+
FXGL.getGameWorld().getEntitiesByType(EntityType.PADDLE).forEach(Entity::removeFromWorld);
8577

8678
double px = FXGL.getAppWidth() / 2.0 - 60;
8779
double py = FXGL.getAppHeight() - 40;
@@ -97,13 +89,11 @@ public void apply() {
9789
FXGL.spawn("ball", new com.almasb.fxgl.entity.SpawnData(x, y).put("attached", true));
9890
FXGL.set("ballAttached", true);
9991
}
100-
10192
}
10293

10394
/**
10495
* Lazy-loaded singleton holder. <br>
105-
* Follow
106-
* <a href= "https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom">
96+
* Follow <a href= "https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom">
10797
* Initialization-on-demand holder idiom</a>.
10898
*/
10999
private static final class Holder {

0 commit comments

Comments
 (0)