You can define an enum something like:
enum Direction {
Invalid(-1),
North(0),
NorthEast(1),
South(2),
...
...
SouthEast(7);
private int val;
private static Map<int, Direction> intToTypeMap;
private Direction(int v) {
this.val = v;
this.addToMap(v);
}
public int getValue() {
return this.val;
}
private void addToMap(int v) {
if (intToTypeMap == null) {
intToTypeMap = new TreeMap<int, Direction>();
}
intToTypeMap.put(v, this);
}
public static Direction fromInt(int v) {
Direction type = intToTypeMap.get(Integer.valueOf(v));
if (type == null) {
return Direction.Invalid;
}
return type;
}
}
After above enum, you can change your switch statement something like as below:
. . .
. . .
for (particle particle:particleList) {
if(particle != null){
switch(Direction.fromtInt(r.nextInt(8))){
case North: if(particle.getY()-1 > 0){
particle.north();
}
break;
. . .
. . .