-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.java
More file actions
53 lines (53 loc) · 1.38 KB
/
Copy pathVector.java
File metadata and controls
53 lines (53 loc) · 1.38 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
import java.util.Random;
import java.util.Arrays;
enum Vector {
NORTH(0,-1),
NORTHEAST(1,-1),
EAST(1,0),
SOUTHEAST(1,1),
SOUTH(0,1),
SOUTHWEST(-1,1),
WEST(-1,0),
NORTHWEST(-1,-1)
;
private static final Vector[] VALUES = values();
private static final int SIZE = VALUES.length;
private static Random random = new Random();
private int changeInX;
private int changeInY;
private Vector(int changeInX, int changeInY) {
this.changeInX = changeInX;
this.changeInY = changeInY;
}
static Vector getRandomVector() {
int randomSelection = (int) random.nextInt(SIZE);
return VALUES[randomSelection];
}
static Vector getRandomEastWest() {
int randomSelection = (int) random.nextInt(1);
switch(randomSelection) {
case 0:
return EAST;
case 1:
return WEST;
}
return null;
}
static Vector changeDirection(Vector currentVector, int n) {
int index = Arrays.asList(VALUES).indexOf(currentVector);
index += n;
if (index == SIZE) {
index = 0;
}
if (index == -1) {
index = (SIZE-1);
}
return VALUES[index];
}
int getXTrajectory() {
return this.changeInX;
}
int getYTrajectory() {
return this.changeInY;
}
}