-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyDiskStrategy.java
63 lines (55 loc) · 1.81 KB
/
KeyDiskStrategy.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
import java.awt.Point;
import java.util.ArrayList;
/**
* A class used to set the behaviours and specialize the movement strategy of "Key disk" key.
*
* @author Ramanan R Muralitharan (1141128291)
* @author Mohamed Haryz Izzudin bin Mohamed Rafy (1141127874)
*/
public class KeyDiskStrategy extends MoveStrategy {
/**
* Default constructor for the KeyDiskStrategy class.
* Does not do anything.
*
* @author Ramanan
*/
public KeyDiskStrategy() {}
/**
* Retrieves the squares that a player can move towards.
* Key disk movement permits the player to move up to three squares vertically or horizontally.
*
* @author Ramanan
* @param player The player that is interacting with the key.
* @return an ArrayList of Points.
*/
@Override
public ArrayList<Point> getValidMoveLocations(Player player) {
ArrayList<Point> validPoints = new ArrayList<Point>(12);
Point p = player.getSquare().getPosition();
int x = 3;
int y = 3;
for (int i = 1; i <= x; i++) {
if (p.y + i > -1 && p.y + i < 9)
validPoints.add(new Point(p.x, p.y + i));
if (p.y - i > -1 && p.y - i < 9)
validPoints.add(new Point(p.x, p.y - i));
}
for (int j = 1; j <= y; j++) {
if (p.x + j > -1 && p.x + j < 9)
validPoints.add(new Point(p.x + j, p.y));
if (p.x - j > -1 && p.x - j < 9)
validPoints.add(new Point(p.x - j, p.y));
}
return validPoints;
}
/**
* Gets a string containing the name of the strategy.
*
* @author Haryz
* @return The strategy's name as a string.
*/
@Override
public String toString() {
return "KeyDiskStrategy";
}
}