📄 gridcell.java
字号:
import java.util.*;/** * Creates a field on the board, and keeps track of its neighbours. It also * sets up a new field controller. This class also keeps track of the token * that occupys each field, if any. When a field becomes occupied, it also sets * that it is the next players turn. It also sets up the winline, and cheks if * a move makes one of the players win. */class GridCell extends Observable{ // basic data protected boolean _border; // navigation protected GridCell _neighbour[]; /** * Constructor that takes a game as a parameter. It sets up an * array to keep track of each fields neigbours. */ public GridCell() { _neighbour = new GridCell[8]; _border = false; } // border /** * Sets border to be true. Is set from the Board class when all the * fields of * a board is created, the fiels that are not actually on the board is a * boarder field */ public void setBorder() { _border = true; } /** * Returns true if the field is a border */ public boolean isBorder() { return _border; } /** * Returns true if one of the neighbours is a border and not * actually on the board */ public boolean isAtRim(int direction) { return _neighbour[direction].isBorder(); } // neighbours /** * Gets the neighbouring field in the direction given as parameter */ public GridCell getNeighbour(int direction) { return _neighbour[direction]; } /** * Gets the neighbouring field in the direction given as parameter */ public GridCell go(Direction d) { return d.go(this); } /** * Sets the field, given as the second parameter, to be the neighbour * in the direction given as the first parameter */ public void setNeighbour(int direction, GridCell n) { _neighbour[direction] = n; } /** * Clears a cell; to be overridden by subclasses */ public void clear() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -