-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPuzzle.java
More file actions
112 lines (86 loc) · 3.18 KB
/
Puzzle.java
File metadata and controls
112 lines (86 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
public class Puzzle {
// Attributes
private final String puzzleID;
private final String name;
private final String location;
private final String description;
private final String answer;
private final int maxAttempts;
private String passMessage;
private String failMessage;
private int attempts;
private boolean solved = false;
private boolean failed = false;
// 🔒 nuevo: referencia al jugador que está haciendo este puzzle
private Player puzzlePlayer;
// Constructor
public Puzzle(String puzzleID,
String name,
String location,
String description,
String answer,
int maxAttempts,
String passMessage,
String failMessage) {
this.puzzleID = puzzleID;
this.name = name;
this.location = location;
this.description = description;
this.answer = answer.toLowerCase().trim();
this.maxAttempts = maxAttempts;
this.passMessage = passMessage;
this.failMessage = failMessage;
this.attempts = maxAttempts;
this.solved = false;
this.failed = false;
this.puzzlePlayer = null;
}
// Getter methods
public String getPuzzleID() { return puzzleID; }
public String getName() { return name; }
public String getLocation() { return location; }
public String getDescription() { return description; }
public boolean isSolved() { return solved; }
public boolean isFailed() { return failed; }
// Method to try solving the puzzle
public String tryAnswer(String input) {
if (solved) {
return "Already solved.";
}
String playerAnswer = input.toLowerCase().trim();
if (playerAnswer.equals(answer)) {
solved = true;
// ✅ puzzle resuelto: liberar al jugador del modo puzzle
if (puzzlePlayer != null) {
puzzlePlayer.setInPuzzleMode(false);
}
return passMessage;
}
attempts--;
if (attempts <= 0) {
failed = true;
// ❌ sin intentos: también liberar al jugador (puzzle terminado)
if (puzzlePlayer != null) {
puzzlePlayer.setInPuzzleMode(false);
}
return failMessage + " (No attempts left. Puzzle locked.)";
}
return failMessage + " (" + attempts + " attempts left)";
}
// Reset puzzle
public void resetPuzzle() {
this.attempts = this.maxAttempts;
this.failed = false;
this.solved = false;
}
// ⭐ Aquí es donde Hina quería el lock del jugador
// Start puzzle when player enters the room
public void startPuzzle(Player player) {
// guardar referencia del jugador
this.puzzlePlayer = player;
// 🔒 BLOQUEAR MOVIMIENTO
player.setInPuzzleMode(true);
System.out.println("You encounter a puzzle: " + name);
System.out.println(description);
}
} // ← LAST BRACKET