-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDonkeyStrategy.java
65 lines (57 loc) · 1.87 KB
/
DonkeyStrategy.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
64
65
import java.awt.Point;
import java.util.ArrayList;
/**
* A class used to set the behaviours and specialize the movement strategy of "Donkey" key.
* Uses the strategy design pattern.
*
* @author Ramanan R Muralitharan (1141128291)
* @author Mohamed Haryz Izzudin bin Mohamed Rafy (1141127874)
*/
public class DonkeyStrategy extends MoveStrategy {
/**
* Default constructor for the DonkeyStrategy class.
* Does not do anything.
*
* @author Ramanan
*/
public DonkeyStrategy() {}
/**
* Retrieves the squares that a player can move towards.
* Donkey movement permits the player to move up to three squares diagonally.
*
* @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 = x; i >= 0; i--) {
if (y > 0) {
for (int j = y; j >= -y; j = j - y){
if (j != 0) {
if (p.x + i > -1 && p.x + i < 9 && p.y + j > -1 && p.y + j < 9)
validPoints.add(new Point(p.x + i, p.y + j));
if (p.x - i > -1 && p.x - i < 9 && p.y - j > -1 && p.y - j < 9)
validPoints.add(new Point(p.x - i, p.y - j));
}
}
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 "DonkeyStrategy";
}
}