// Position class, for use with Maze // august 1996, kt /** * Class recording location and state of a cell and also whether or not it has * been visited. */ public class Position { // fields protected int row, col; // row and column of cell // constructor public Position(int _row, int _col) { row = _row; col = _col; } // methods /** * post: Return row corresponding to the cell */ public int getRow() { return row; } /** * post: Return column corresponding to the cell */ public int getCol() { return col; } /** * post: Return true iff row and column is same as for p */ public boolean equals(Position p) { return ((row == p.getRow()) && (col == p.getCol())); } // post: returns position above this one public Position getNorth() { return new Position(row - 1, col); } // post: returns position below this one public Position getSouth() { return new Position(row + 1, col); } // post: returns position to right of this one public Position getEast() { return new Position(row, col + 1); } // post: returns position to left of this one public Position getWest() { return new Position(row, col - 1); } /** * post: Return String with location of cell */ public String toString() { return new String("(" + row + "," + col + ")"); } }