44 lines
1018 B
Java
44 lines
1018 B
Java
package cicaprojekt;
|
|
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* A játékban előforduló irányokat definiáló enumerátor.
|
|
*/
|
|
public enum Direction {
|
|
/**
|
|
* Az irányok felsorolása.
|
|
*/
|
|
NORTH, SOUTH, EAST, WEST;
|
|
|
|
/**
|
|
* A kapott irány megfordítottjával visszatérő függvény.
|
|
*
|
|
* @param direction a kapott irány
|
|
* @return az irány fordítottja
|
|
*/
|
|
public static Direction invert(Direction direction) {
|
|
switch (direction) {
|
|
case NORTH:
|
|
return SOUTH;
|
|
case EAST:
|
|
return WEST;
|
|
case SOUTH:
|
|
return NORTH;
|
|
case WEST:
|
|
return EAST;
|
|
default:
|
|
return NORTH;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Egy véletlenszerű iránnyal tér vissza.
|
|
*
|
|
* @return véletlen irány
|
|
*/
|
|
public static Direction getRandom() {
|
|
return Direction.values()[new Random().nextInt(Direction.values().length)];
|
|
}
|
|
}
|