mhframework.tilemap
Class MHMap

java.lang.Object
  extended by mhframework.tilemap.MHMap

public class MHMap
extends java.lang.Object

Maintains data for a grid-based game map. This includes regular rectangular tile maps, isometric maps, and hexagonal maps.

Note that this class requires an existing class which implements the MHObjectVendor interface. The object vendor class is responsible for instantiating the dynamic actor objects in a map.

Also note that this class only maintains the data. The actual presentation of the map (scrolling, plotting, mouse mapping, etc.) is handled by subclasses of MHTileMap. If you are using a subclass of MHTileMap to handle your map presentation, then you do not need to explicitly instantiate an MHMap object because the MHTileMap base class takes care of that for you when you provide a map file name to the constructor.

The map data will be stored in five separate files:

  1. M0000000.map -- This file will contain only the following five lines in the order given:
  2. F0000000.dat -- The file containing floor layer data.
  3. I0000000.dat -- The file containing item layer data.
  4. W0000000.dat -- The file containing static wall layer data.
  5. C0000000.dat -- The file containing ceiling layer data.

Note: The file names given here are merely suggestions, and the code in this class does nothing to enforce any sort of naming conventions. It simply opens and reads whatever file names are supplied.


Constructor Summary
MHMap(int mapHeight, int mapWidth, MHObjectFactory vendor)
          Constructor that creates a map with the given number of rows and columns.
MHMap(java.lang.String filename, MHObjectFactory vendor)
          Constructor that creates a map using the given map file name.
 
Method Summary
 java.lang.String getCeilingFile()
          Returns the ceilingFile.
 java.lang.String getDetailFile()
          Returns the detailFile.
 java.lang.String getFloorFile()
          Returns the floorFile.
 int getHeight()
          Returns the number of rows in the map.
 java.lang.String getItemFile()
          Returns the itemFile.
 MHMapCell getMapCell(int row, int column)
          Returns the map cell at the given coordinates
static MHMapFileInfo getMapFileInfo()
           
 java.lang.String getMapFileName()
          Returns the fileName.
 int getTileSetId()
          Returns the tileSetId.
 java.lang.String getWallFile()
          Returns the wallFile.
 int getWidth()
          Returns the number of columns in the map.
 void loadMapFile(java.lang.String filename)
          Loads all the data files listed in the given file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MHMap

public MHMap(int mapHeight,
             int mapWidth,
             MHObjectFactory vendor)
Constructor that creates a map with the given number of rows and columns. If this constructor is used, it must be followed by a call to loadMapFile() to populate the map structure.

Parameters:
dataModel - A reference to the application's data model.
mapHeight - The height of the game map in number of cells.
mapWidth - The width of the game map in number of cells.

MHMap

public MHMap(java.lang.String filename,
             MHObjectFactory vendor)
Constructor that creates a map using the given map file name. The number of rows and columns is computed from the map data which is loaded into the map structure by this method.

Parameters:
filename - The name of the map file to be loaded.
Method Detail

loadMapFile

public void loadMapFile(java.lang.String filename)
Loads all the data files listed in the given file name. This method assumes that the image groups (MHImageGroup objects) for normal, static tiles already exist in a tile set manager (MHTileSetManager), and that specialized objects have taken the responsibility for acquiring their own image groups.

Parameters:
filename - The name of the map file to be loaded.

getMapCell

public MHMapCell getMapCell(int row,
                            int column)
Returns the map cell at the given coordinates


getHeight

public int getHeight()
Returns the number of rows in the map.


getWidth

public int getWidth()
Returns the number of columns in the map.


getCeilingFile

public java.lang.String getCeilingFile()
Returns the ceilingFile.

Returns:
String

getMapFileName

public java.lang.String getMapFileName()
Returns the fileName.

Returns:
String

getFloorFile

public java.lang.String getFloorFile()
Returns the floorFile.

Returns:
String

getItemFile

public java.lang.String getItemFile()
Returns the itemFile.

Returns:
String

getDetailFile

public java.lang.String getDetailFile()
Returns the detailFile.

Returns:
String

getTileSetId

public int getTileSetId()
Returns the tileSetId.

Returns:
int

getWallFile

public java.lang.String getWallFile()
Returns the wallFile.

Returns:
String

getMapFileInfo

public static MHMapFileInfo getMapFileInfo()