Repository navigation
Expand file tree
/
Copy pathExit.java
More file actions
74 lines (67 loc) · 2.04 KB
/
Copy pathExit.java
File metadata and controls
74 lines (67 loc) · 2.04 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
import javafx.scene.image.Image;
/**
* Represents an Exit tile in the game.
* Only one exit can be created per level.
* Initially, cannot be entered/walked over or exploded.
* @author Rhys Llewellyn
* @author Joshua Aka
*/
public class Exit extends Element {
/**
* Allows us to keep track of whether an exit has already been created.
*/
private static boolean exitExists = false;
/**
* Creates a new Exit tile at the specified row and column (x and y).
* @param row the row position of the tile
* @param column the column position of the tile
* @throws IllegalStateException if an exit already exists
*/
public Exit(final int row, final int column) {
super(row, column);
// Ensures only one exit can be created per level
if (exitExists) {
throw new IllegalStateException("An exit already exists!");
}
image = new Image("images/Exit.png");
canBeEntered = false; // Initially can't be entered
canExplode = false;
name = "Exit";
exitExists = true;
}
/**
* Resets the exit existence flag to allow the creation of a new exit.
*/
public static void toggleFalseExitExists() {
exitExists = false;
}
/**
* Method to unlock the Exit so it can be entered
*/
public void unlock() {
this.canBeEntered = true;
System.out.println("Exit Unlocked!");
}
/**
* Locks the exit, preventing it from being entered.
*/
public void lock() {
this.canBeEntered = false;
System.out.println("Exit Locked!");
}
/**
* Checks if the exit is unlocked.
* @return true if the exit can be entered, false otherwise
*/
public boolean isLocked() {
return canBeEntered;
}
/**
* This returns a string representation of the exit and its locked status.
* @return the string representation of the exit
*/
@Override
public String toString() {
return super.toString() + " Unlocked: " + canBeEntered;
}
}