Skip to content

Commit 6302008

Browse files
committed
Added JavaDoc for RiddlePuzzleController.java
1 parent bcba0a1 commit 6302008

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/main/java/com/escapegame/RiddlePuzzleController.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
import javafx.scene.image.ImageView;
2222
import javafx.scene.layout.HBox;
2323
import javafx.scene.layout.StackPane;
24-
24+
/**
25+
* Controller for the riddle puzzle screen.
26+
* Manages UI bindings, background image loading, riddle state (attempts,
27+
* hints, solved flag), persistence to a per user properties file, and simple
28+
* navigation back to the puzzle home or to the next screen upon success.
29+
*/
2530
public class RiddlePuzzleController implements Initializable {
2631

2732
@FXML private StackPane rootPane;
@@ -48,7 +53,10 @@ public class RiddlePuzzleController implements Initializable {
4853

4954
private static final String RESOURCE_PATH = "/images/background.png";
5055
private static final String DEV_FALLBACK = "file:/mnt/data/Screenshot 2025-11-19 204918.png";
51-
56+
/**
57+
* Initializes the puzzle UI, attempts to load a background image, binds
58+
* sizing, initializes hint/attempt displays and loads any saved progress.
59+
*/
5260
@Override
5361
public void initialize(URL location, ResourceBundle resources) {
5462
System.out.println("RiddlePuzzleController.initialize() start");
@@ -93,7 +101,10 @@ public void initialize(URL location, ResourceBundle resources) {
93101

94102
System.out.println("RiddlePuzzleController.initialize() done");
95103
}
96-
104+
/**
105+
* Returns the per-user save file for the riddle puzzle.
106+
* Uses App.getCurrentUser() when available; falls back to "guest".
107+
*/
97108
private File getSaveFileForCurrentUser() {
98109
String userId = "guest";
99110
try {
@@ -107,7 +118,10 @@ private File getSaveFileForCurrentUser() {
107118
String fileName = ".escapegame_riddle_" + userId + ".properties";
108119
return new File(System.getProperty("user.home"), fileName);
109120
}
110-
121+
/**
122+
* Refreshes the heart icons that represent remaining attempts.
123+
* Disables input when no attempts remain.
124+
*/
111125
private void refreshHearts() {
112126
heartsBox.getChildren().clear();
113127
for (int i = 0; i < attemptsLeft; i++) {
@@ -120,7 +134,10 @@ private void refreshHearts() {
120134
if (answerField != null) answerField.setDisable(true);
121135
}
122136
}
123-
137+
/**
138+
* Handles answer submission: validates, checks against accepted answers,
139+
* updates state, shows alerts, saves progress and navigates when solved.
140+
*/
124141
@FXML
125142
private void onSubmit() {
126143
if (solved) {
@@ -170,7 +187,9 @@ private void onSubmit() {
170187
}
171188
}
172189
}
173-
190+
/**
191+
* Shows the next hint if available and saves progress.
192+
*/
174193
@FXML
175194
private void onHint() {
176195
if (solved) {
@@ -204,7 +223,10 @@ private void onQuit() {
204223
e.printStackTrace();
205224
}
206225
}
207-
226+
/**
227+
* Persists the riddle puzzle state to a per user properties file.
228+
* @return true if save succeeded, false on error
229+
*/
208230
private boolean saveProgress() {
209231
try {
210232
Properties p = new Properties();
@@ -222,7 +244,10 @@ private boolean saveProgress() {
222244
return false;
223245
}
224246
}
225-
247+
/**
248+
* Loads saved progress from the per-user properties file if present.
249+
* Updates UI state to reflect loaded values.
250+
*/
226251
private void loadSave() {
227252
try {
228253
File f = getSaveFileForCurrentUser();

0 commit comments

Comments
 (0)