Skip to content

Commit 56ba8fa

Browse files
committed
Added JavaDoc for CipherPuzzleController.java
1 parent 47c6cee commit 56ba8fa

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/main/java/com/escapegame/CipherPuzzleController.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
/**
2424
* Cipher puzzle controller — easy Caesar cipher: DNWG -> BLUE (shift -2)
25+
* Manages UI bindings, puzzle state (attempts, hints, solved flag), simple
26+
* persistence to a properties file, and navigation after solving or quitting.
27+
* Designed to be minimal and defensive: all UI references are checked for null
28+
* before use.
2529
*/
2630
public class CipherPuzzleController implements Initializable {
2731

@@ -58,7 +62,10 @@ public class CipherPuzzleController implements Initializable {
5862
// resource and dev fallback paths
5963
private static final String RESOURCE_PATH = "/images/background.png";
6064
private static final String DEV_FALLBACK = "file:/mnt/data/Screenshot 2025-11-19 221015.png";
61-
65+
/**
66+
* Initializes UI state: loads background image (resource then dev fallback),
67+
* binds sizing, initializes labels, draws hearts and loads saved progress.
68+
*/
6269
@Override
6370
public void initialize(URL location, ResourceBundle resources) {
6471
System.out.println("CipherPuzzleController.initialize() start");
@@ -108,7 +115,10 @@ public void initialize(URL location, ResourceBundle resources) {
108115
System.out.println("CipherPuzzleController.initialize() done");
109116
}
110117

111-
// Draw hearts based on remaining attempts
118+
/**
119+
* Refreshes the heart icons representing remaining attempts and disables
120+
* input if no attempts remain.
121+
*/
112122
private void refreshHearts() {
113123
if (heartsBox == null) return;
114124
heartsBox.getChildren().clear();
@@ -122,7 +132,10 @@ private void refreshHearts() {
122132
if (answerField != null) answerField.setDisable(true);
123133
}
124134
}
125-
135+
/**
136+
* Handles submission of an answer: validates, compares to accepted answers,
137+
* updates state, shows alerts, saves progress and navigates on success.
138+
*/
126139
@FXML
127140
private void onSubmit() {
128141
if (solved) {
@@ -164,7 +177,9 @@ private void onSubmit() {
164177
}
165178
}
166179
}
167-
180+
/**
181+
* Shows the next hint if available, updates hint counters and saves progress.
182+
*/
168183
@FXML
169184
private void onHint() {
170185
if (solved) {
@@ -197,7 +212,10 @@ private void onQuit() {
197212
e.printStackTrace();
198213
}
199214
}
200-
215+
/**
216+
* Persists the puzzle state to a properties file in the user's home dir.
217+
* @return true if saving succeeded, false otherwise
218+
*/
201219
private boolean saveProgress() {
202220
try {
203221
Properties p = new Properties();
@@ -214,7 +232,9 @@ private boolean saveProgress() {
214232
return false;
215233
}
216234
}
217-
235+
/**
236+
* Loads saved puzzle state from the properties file if present and updates UI.
237+
*/
218238
private void loadSave() {
219239
try {
220240
if (!SAVE_FILE.exists()) return;

0 commit comments

Comments
 (0)