1 /***
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id: IGrid.java,v 1.5 2005/09/09 22:12:34 mat007 Exp $
29 */
30
31 package jtge.util.grid;
32
33 import java.util.Iterator;
34 import jtge.util.grid.direction.IDirection;
35
36 /***
37 * Abstract representation of a grid.
38 *
39 * @author Jean-Laurent Fabre de Morlhon
40 * @version $Id: IGrid.java,v 1.5 2005/09/09 22:12:34 mat007 Exp $
41 */
42 public interface IGrid
43 {
44 /***
45 * Retrieve the width.
46 *
47 * @return an int representing the maximum width of this grid
48 */
49 int getWidth();
50
51 /***
52 * Retrieve the height.
53 *
54 * @return an int representing the maximum height of this grid
55 */
56 int getHeight();
57
58 /***
59 * Retrieve the maximum number of tiles this hexGrid can hold.
60 *
61 * @return the maximum number of tiles.
62 */
63 int size();
64
65 /***
66 * Assign the supplied tile to this grid.
67 * <p>
68 * If a tile is already present at <code>coordinate()</code> for the current grid it gets replaced.
69 *
70 * @param tile the tile to set in this grid
71 * @param coordinate the coordinate to place the tile at
72 */
73 void setTile( ITile tile, Coordinate coordinate );
74
75 /***
76 * Retrieve the tile object at the supplied coordinate.
77 *
78 * @param coordinate the coordinate in the grid you want the tile for
79 * @return the tile at the current coordinate or null if none
80 */
81 ITile getTile( Coordinate coordinate );
82
83 /***
84 * Checks if the coordinate supplied is valid for this grid.
85 *
86 * @param coordinate the coordinate to test
87 * @return whether the given coordinate is within the bound of this grid or not
88 */
89 boolean isValid( Coordinate coordinate );
90
91 /***
92 * returns the adjacent Coordinate given a Coordinate center and a Direction.<br>
93 * Coordinate returned are always valid, an CoordinateOutOfBoundException is thrown if you asked for an impossible
94 * coordinate.
95 *
96 * @param coordinate the coordinate from which the adjacent coordinate is calculated.
97 * @param direction the direction from which the adjacent coordinate is calculated.
98 * @return an adjacent Coordiante given the center and direction or null if there is no adjacent coordinate.
99 */
100 Coordinate getAdjacent( Coordinate coordinate, IDirection direction );
101
102 /***
103 * Create an iterator on coordinates from the top left to the bottom right coordinate.
104 *
105 * @return an iterator on coordinates
106 */
107 Iterator linearIterator();
108
109 /***
110 * Create an iterator on tiles from the top left to the bottom right coordinate.
111 *
112 * @return an iterator on tiles
113 */
114 Iterator linearTileIterator();
115
116 /***
117 * Create an iterator on coordinates around a given coordinate.
118 *
119 * @param coordinate a coordinate
120 * @return an iterator on coordinates
121 */
122 Iterator adjacentIterator( Coordinate coordinate );
123
124 /***
125 * Create an iterator on tiles around a given coordinate.
126 *
127 * @param coordinate a coordinate
128 * @return an iterator on tiles
129 */
130 Iterator adjacentTileIterator( Coordinate coordinate );
131 }