相关疑难解决方法(0)

如何将Enum与其相反的值相关联,如在主要方向(南北,东西等)?

我还在为我的迷宫游戏制作我的Cell课程.在另一个线程的帮助之后,有人建议我使用EnumMap作为我的墙/邻居,这到目前为止工作得很好.

这是我到目前为止:

enum Dir {
    NORTH, SOUTH, EAST, WEST
}

class Cell {
    public Map<Dir, Cell> neighbors = Collections
            .synchronizedMap(new EnumMap<Dir, Cell>(Dir.class));
    public Map<Dir, Boolean> walls = Collections
            .synchronizedMap(new EnumMap<Dir, Boolean>(Dir.class));

    public boolean Visited;

    public Cell() {
        Visited = false;
        for (Dir direction : Dir.values()) {
            walls.put(direction, true);
        }
    }

    // Randomly select an unvisited neighbor and tear down the walls
    // between this cell and that neighbor.
    public Cell removeRandomWall() {
        List<Dir> unvisitedDirections = new ArrayList<Dir>();
        for (Dir direction …
Run Code Online (Sandbox Code Playgroud)

java enums

5
推荐指数
2
解决办法
4095
查看次数

标签 统计

enums ×1

java ×1