Skip to content

Commit e4fbb57

Browse files
committed
Added JavDoc for AnagramPuzzleController.java
1 parent 476a1ba commit e4fbb57

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/main/java/com/escapegame/AnagramPuzzleController.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
/**
2424
* Anagram puzzle controller — scrambled LPAEP -> APPLE (category Fruit)
25+
* Manages the anagram puzzle UI: background loading, attempts/hints state,
26+
* simple persistence to a properties file, and navigation on solve/quit.
27+
* UI references are checked for null to be defensive when used from FXML.
2528
*/
2629
public class AnagramPuzzleController implements Initializable {
2730

@@ -55,7 +58,12 @@ public class AnagramPuzzleController implements Initializable {
5558

5659
private static final String RESOURCE_PATH = "/images/background.png";
5760
private static final String DEV_FALLBACK = "file:/mnt/data/Screenshot 2025-11-22 202825.png";
58-
61+
/**
62+
* Initialize the puzzle screen: load background image (resource then fallback),
63+
* set initial UI labels, draw hearts and restore saved progress.
64+
* @param location not used
65+
* @param resources not used
66+
*/
5967
@Override
6068
public void initialize(URL location, ResourceBundle resources) {
6169
System.out.println("AnagramPuzzleController.initialize() start");
@@ -102,7 +110,9 @@ public void initialize(URL location, ResourceBundle resources) {
102110

103111
System.out.println("AnagramPuzzleController.initialize() done");
104112
}
105-
113+
/**
114+
* Draw hearts representing remaining attempts and disable inputs when none remain.
115+
*/
106116
private void refreshHearts() {
107117
if (heartsBox == null) return;
108118
heartsBox.getChildren().clear();
@@ -116,7 +126,10 @@ private void refreshHearts() {
116126
if (answerField != null) answerField.setDisable(true);
117127
}
118128
}
119-
129+
/**
130+
* Called when the user submits an answer. Validates input, checks accepted
131+
* answers, updates state, shows alerts, saves progress and navigates on success.
132+
*/
120133
@FXML
121134
private void onSubmit() {
122135
if (solved) {
@@ -158,7 +171,9 @@ private void onSubmit() {
158171
}
159172
}
160173
}
161-
174+
/**
175+
* Shows the next hint (if available), updates hint counters and saves progress.
176+
*/
162177
@FXML
163178
private void onHint() {
164179
if (solved) {
@@ -177,17 +192,20 @@ private void onHint() {
177192
new Alert(Alert.AlertType.INFORMATION, hint).showAndWait();
178193
saveProgress();
179194
}
180-
195+
/** Saves progress to the user's properties file and updates the status label. */
181196
@FXML
182197
private void onSave() {
183198
if (statusLabel != null) statusLabel.setText(saveProgress() ? "Progress saved." : "Save failed.");
184199
}
185-
200+
/** Quit action: navigate back to the previous/opened4 screen. */
186201
@FXML
187202
private void onQuit() {
188203
try { App.setRoot("opened4"); } catch (IOException e) { e.printStackTrace(); }
189204
}
190-
205+
/**
206+
* Persist puzzle state to a properties file under the user's home directory.
207+
* @return true if save succeeded, false otherwise
208+
*/
191209
private boolean saveProgress() {
192210
try {
193211
Properties p = new Properties();
@@ -204,7 +222,9 @@ private boolean saveProgress() {
204222
return false;
205223
}
206224
}
207-
225+
/**
226+
* Load saved puzzle state from properties file if present and update UI.
227+
*/
208228
private void loadSave() {
209229
try {
210230
if (!SAVE_FILE.exists()) return;

0 commit comments

Comments
 (0)