-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActor.java
63 lines (56 loc) · 1.47 KB
/
Actor.java
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
/**
* An actor in a Sokoban puzzle.
*
* @author Dr Mark C. Sinclair
* @version September 2021
*
*/
public class Actor extends Occupant {
/**
* Constructor with cell currently occupied
*
* @param cell the cell occupied by this actor (Occupant constructor checks for null)
*/
public Actor(Cell cell) {
super(cell);
}
/**
* Checks if this occupant is an actor
*
* @return true
*/
@Override
public boolean isActor() {
return true;
}
/**
* Gets the character to use for display purposes for this cell
*
* @return character to use for display purposes for this cell
*/
@Override
public char getDisplay() {
return (cell.isTarget()) ? Sokoban.TARGET_ACTOR : Sokoban.ACTOR;
}
/**
* Checks if the actor can move to the next cell in a given direction
*
* @param dir the direction to check
* @return can the actor move to the next cell in a given direction?
*/
@Override
public boolean canMove(Direction dir) {
Cell next = cell.getCell(dir);
return (next != null) && (next.isEmpty() || next.canMove(dir));
}
/**
* A trace method for debugging (active when traceOn is true)
*
* @param s the string to output
*/
public static void trace(String s) {
if (traceOn)
System.out.println("trace: " + s);
}
private static boolean traceOn = false; // for debugging
}