⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 direction.java

📁 一个java的游戏程序
💻 JAVA
字号:
/** * Sets the directions, used mainly on the board, and crates the posibility for * finding the opposite direction. */class Direction {    final static  int NORTH;    final static  int NORTHEAST;    final static  int EAST;    final static  int SOUTHEAST;    final static  int SOUTH;    final static  int SOUTHWEST;    final static  int WEST;    final static  int NORTHWEST;    final static Direction north;    final static Direction northeast;    final static Direction east;    final static Direction south;    final static Direction southeast;    final static Direction southwest;    final static Direction west;    final static Direction northwest;        final static Direction all[];    static{       NORTH = 0;      NORTHEAST = 1;      EAST = 2;      SOUTHEAST = 3;      SOUTH = 4;      SOUTHWEST = 5;      WEST = 6;      NORTHWEST = 7;      north     = new Direction(NORTH, 0, 1);      northeast = new Direction(NORTHEAST, 1, 1);      east      = new Direction(EAST, 1, 0);      southeast = new Direction(SOUTHEAST, 1, -1);      south     = new Direction(SOUTH, 0, -1);      southwest = new Direction(SOUTHWEST, -1, -1);      west      = new Direction(WEST, -1, 0);      northwest = new Direction(NORTHWEST, -1, 1);      all = new Direction[8];      all[NORTH]     = north;      all[NORTHEAST] = northeast;      all[EAST]      = east;      all[SOUTHEAST] = southeast;      all[SOUTH]     = south;      all[SOUTHWEST] = southwest;      all[WEST]      = west;      all[NORTHWEST] = northwest;    }      /**   * Returns the opposite direction from the one given as a parameter,   * when the int given does not represent a valid direction a default   * negative number is returned.   */  public static int opposite(int direction)    {	if(direction == NORTH)	    return SOUTH;	else if(direction == SOUTH)	    return NORTH;	else if(direction == NORTHWEST)	    return SOUTHEAST;	else if(direction == SOUTHEAST)	    return NORTHWEST;	else if(direction == NORTHEAST)	    return SOUTHWEST;	else if(direction == SOUTHWEST)	    return NORTHEAST;	else if(direction == WEST)	    return EAST;	else if(direction == EAST)	    return WEST;	else	    return -1;    }    private int _direction;    private int _x;    private int _y;    public Direction(int direction, int x, int y)    {	_direction = direction;	_x = x;	_y = y;    }    public GridCell go(GridCell cell)    {	return cell.getNeighbour(_direction);    }    public Direction opposite()    {	return all[Direction.opposite(_direction)];    }    public Direction next()    {	return all[(_direction + 1) % 8];    }    public int x()    {	return _x;    }    public int y()    {	return _y;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -