location.java
来自「swarm的例子,包換對java,xml,servlet等的介紹」· Java 代码 · 共 57 行
JAVA
57 行
import java.util.ArrayList;import java.awt.Color;import java.awt.Point;public class Location extends Point { SwarmRaster grid = null; Object object = null; ArrayList neighbors = new ArrayList(8); boolean isNeighborCacheInvalid = true; public Location(SwarmRaster sr, int myX, int myY) { super(myX,myY); grid = sr; } public ArrayList get_neighbors() { if (isNeighborCacheInvalid) { neighbors.clear(); Location n; if ((y-1 > 0) && ((n=((Location)grid.getLocationAt(x,y-1))) != null)) neighbors.add(n); if ((y+1 < grid.getHeight()) && ((n=((Location)grid.getLocationAt(x,y+1))) != null)) neighbors.add(n); if ((x-1 > 0) && ((n=((Location)grid.getLocationAt(x-1,y))) != null)) neighbors.add(n); if ((x+1 < grid.getWidth()) && ((n=((Location)grid.getLocationAt(x+1,y))) != null)) neighbors.add(n); neighbors.trimToSize(); isNeighborCacheInvalid = false; } return neighbors; } public Color get_color() { return ((Prisoner)object).get_color(); } public int get_xpos() { return x; } public int get_ypos() { return y; } public void set_object(Object o) { object = o; } public Object get_object() { return object; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?