Skip to content

Commit 6e1c7d2

Browse files
committed
refactor: split long render method and add JavaDoc
1 parent 2c25491 commit 6e1c7d2

File tree

13 files changed

+150
-169
lines changed

13 files changed

+150
-169
lines changed

client/src/main/java/io/exterminator3618/client/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public enum GameState {
129129

130130
public static int BUTTON_WIDTH = 300;
131131
public static int BUTTON_HEIGHT = 75;
132+
132133
/**
133134
* game borders
134135
*/
@@ -141,4 +142,9 @@ public enum GameState {
141142
* Saved game path
142143
*/
143144
public static final String SAVE_FILE = "client/src/main/resources/data/save/saved_game.json";
145+
146+
/**
147+
* Number of game levels
148+
*/
149+
public static final int Level = 3;
144150
}

client/src/main/java/io/exterminator3618/client/components/Box.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import io.exterminator3618.client.utils.Assets;
99
import io.exterminator3618.client.utils.Renderer;
1010

11+
/**
12+
* Menu box for pause screen and setting screen.
13+
*/
1114
public class Box {
1215

1316
private int x = Constants.WINDOW_WIDTH / 2;

client/src/main/java/io/exterminator3618/client/components/Brick.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,5 @@ public String getType() {
8787
*/
8888
@Override
8989
public void update(float deltaTime) {
90-
// nó đứng im, đéo cần update đâu, thêm cái này cho có
9190
}
9291
}

client/src/main/java/io/exterminator3618/client/components/SolidBrick.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@ public class SolidBrick extends Brick {
1515
* @param y initial Y position in pixels
1616
*/
1717
public SolidBrick(int x, int y) {
18-
// Sử dụng một hình ảnh trông cứng cáp, ví dụ THICK_YELLOW_BRICK
19-
// hitPoints có thể là bất kỳ số nào, vì nó sẽ không bao giờ bị trừ.
20-
// Type là "indestructible" để phân biệt.
2118
super(x, y, Constants.BRICK_WIDTH, Constants.BRICK_HEIGHT, Constants.THICK_BLUE_BRICK, 1, "solid_brick");
2219
}
2320

2421
/**
25-
* Ghi đè (Override) phương thức takeHit.
26-
* Đây là điểm mấu chốt: phương thức này không làm gì cả.
27-
* Nó không trừ hitPoints và luôn trả về false (không bị phá hủy).
28-
* @return luôn luôn là false
22+
* This brick is indestructible.
2923
*/
3024
@Override
3125
public boolean takeHit() {
32-
// Không làm gì cả. Gạch này không nhận sát thương.
3326
return false;
3427
}
3528
}

client/src/main/java/io/exterminator3618/client/components/TextButton.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import io.exterminator3618.client.Constants;
88
import io.exterminator3618.client.utils.Renderer;
99
import io.exterminator3618.client.utils.Assets;
10+
11+
/**
12+
* A simple text button with an optional 9-patch-style background frame.
13+
*/
1014
public class TextButton {
1115

1216
public String text;
@@ -16,6 +20,16 @@ public class TextButton {
1620
public String middleRegion;
1721
public String rightRegion;
1822

23+
/**
24+
* Creates a new TextButton.
25+
*
26+
* @param text The text to display.
27+
* @param x The x-coordinate (bottom-left).
28+
* @param y The y-coordinate (bottom-left).
29+
* @param width The button's width.
30+
* @param height The button's height.
31+
* @param hasFrame True to draw the 9-patch style frame, false for text only.
32+
*/
1933
public TextButton(String text, float x, float y, float width, float height, boolean hasFrame) {
2034
this.text = text;
2135
this.bounds = new Rectangle(x, y, width, height);
@@ -30,25 +44,28 @@ public TextButton(String text, float x, float y, float width, float height, bool
3044
this.rightRegion = null;
3145
}
3246
}
47+
3348
/**
34-
* Tạo một TextButton mới.
49+
* Creates a new TextButton without a frame.
3550
*
36-
* @param text Văn bản sẽ hiển thị.
37-
* @param x Tọa độ X (góc DƯỚI-BÊN TRÁI) của vùng nhấp.
38-
* @param y Tọa độ Y (góc DƯỚI-BÊN TRÁI) của vùng nhấp.
39-
* @param width Chiều rộng của vùng nhấp.
40-
* @param height Chiều cao của vùng nhấp.
51+
* @param text The text to display.
52+
* @param x The x-coordinate (bottom-left).
53+
* @param y The y-coordinate (bottom-left).
54+
* @param width The button's width.
55+
* @param height The button's height.
4156
*/
4257
public TextButton(String text, float x, float y, float width, float height) {
4358
this.text = text;
4459
this.bounds = new Rectangle(x, y, width, height);
4560
}
4661

4762
/**
48-
* Vẽ button này bằng Renderer.
63+
* Draws the button (frame and text) using the provided Renderer.
64+
* @param renderer The renderer to use for drawing.
4965
*/
5066
public void draw(Renderer renderer) {
5167

68+
// Draw the 9-patch style frame if regions are defined
5269
if (leftRegion != null && middleRegion != null && rightRegion != null) {
5370

5471
TextureRegion leftTex = Assets.getUiRegion(leftRegion);
@@ -63,10 +80,13 @@ public void draw(Renderer renderer) {
6380
int width = (int)bounds.width;
6481
int height = (int)bounds.height;
6582

83+
// Draw left cap
6684
renderer.drawUi(leftRegion, x, y, leftWidth, height);
6785

86+
// Draw right cap
6887
renderer.drawUi(rightRegion, (x + width) - rightWidth, y, rightWidth, height);
6988

89+
// Draw tiled middle section
7090
int middleX = x + leftWidth;
7191
int middleWidth = width - leftWidth - rightWidth;
7292

@@ -76,21 +96,20 @@ public void draw(Renderer renderer) {
7696
}
7797
}
7898

99+
// Draw the text centered
79100
int centerX = (int)(bounds.x + bounds.width / 2);
80101
int centerY = (int)(bounds.y + bounds.height / 2);
81102
renderer.drawTextMiddle(text, centerX, centerY);
82103
}
83104

84105
/**
85-
* Kiểm tra xem tọa độ (đã được unproject) có nằm trong nút này không.
106+
* Checks if the given (unprojected) coordinates are within the button's bounds.
86107
*
87-
* @param touchX Tọa độ X của thế giới game (đã qua camera.unproject).
88-
* @param touchY Tọa độ Y của thế giới game (đã qua camera.unproject).
89-
* @return true nếu được nhấp, false nếu không.
108+
* @param touchX The world x-coordinate (already unprojected).
109+
* @param touchY The world y-coordinate (already unprojected).
110+
* @return true if clicked, false otherwise.
90111
*/
91112
public boolean isClicked(float touchX, float touchY) {
92113
return bounds.contains(touchX, touchY);
93114
}
94-
95-
96115
}

0 commit comments

Comments
 (0)