map
Class Grid

java.lang.Object
  extended by map.Grid

public class Grid
extends java.lang.Object

A Grid is divided into a set of Units. The first Unit is in the upper left corner with the values (0,0). Every Unit in the grid is assigned to a Unit Id that is put together by multipling the row of the Unit with the total number of Units per row and adding the column of the Unit + 1.
e.g.: Id(20) = (row_index * #units_per_row) + column_index + 1 = (3 * 5) + 4 + 1 = 20.



A Unit may contains one or more MapItems.



Map Items are loaded from ".list" files which contain a collection of Map Items. In such a file following syntax is used:

1:  5 // Number of Columns in the Grid
2:  4 // Number of Rows in the Grid
3:  -
4:  0 0 Hoobastank - The Reason.mp3
5:  0 0 Lenny Kravitz - Fly away.mp3
    . . ...
17: 0 2 Kylie Minogue - Slow.mp3
    . . ...

The first three lines specify the layout of the Grid, where as the rest of the file contains the Map Items (one per line). The first two values assign the Map Item to a Unit followed by the name of the item

Author:
Hlavac Peter
See Also:
MapItem, Unit

Constructor Summary
Grid(java.lang.String resource)
          Inits the Grid in building the Unit HashTable that holds UnitIds (Integer Objects) as a key with the corresponding Unit as value
 
Method Summary
 MapItem getMapItem(java.lang.Integer unitId, boolean bRotate)
          Gets a Map Item of a given Unit.
 java.util.Vector getMapItems(java.lang.Integer unitId)
          Returns all Map Items of a given Unit.
 java.lang.Integer getUnitId(int unitX, int unitY)
          Returns the UnitId of a given row and column
 int getUNITS_X()
          Gets the number of columns of the Grid
 int getUNITS_Y()
          Gets the number of rows of the Grid
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grid

public Grid(java.lang.String resource)
Inits the Grid in building the Unit HashTable that holds UnitIds (Integer Objects) as a key with the corresponding Unit as value

Parameters:
resource - The resource where to get the items from
Method Detail

getMapItem

public MapItem getMapItem(java.lang.Integer unitId,
                          boolean bRotate)
Gets a Map Item of a given Unit. Every time the method is called with the same UnitId and the parameter bRotate is set to true, the next Map Item of the Unit will be returned.

Parameters:
unit - the Unit where to get a Map Item from
bRotate -
  • if set to true return the next item of the given unit
  • if set to false return the first item of the unit
Returns:
the a Map Item of a given Unit

getMapItems

public java.util.Vector getMapItems(java.lang.Integer unitId)
Returns all Map Items of a given Unit.

Parameters:
unitId - the unitId to get Map Items from
Returns:
a vector of Map Items for the given Unit

getUnitId

public java.lang.Integer getUnitId(int unitX,
                                   int unitY)
Returns the UnitId of a given row and column

Parameters:
unitX - the column
unitY - the row
Returns:
the UnitId of a given row and column

getUNITS_X

public int getUNITS_X()
Gets the number of columns of the Grid

Returns:
the number of columns of the Grid

getUNITS_Y

public int getUNITS_Y()
Gets the number of rows of the Grid

Returns:
the number of rows of the Grid