mhframework
Interface MHObjectFactory


public interface MHObjectFactory

This interface is to be implemented by the class in your game that is responsible for taking a tile ID and returning a special non-static object.

The code in such a class might look something like this:

    if (layer == MHMapCell.FLOOR_LAYER)
    {
        switch(tileID)
        {
            case FLOOR_SWITCH:
                return new MyGameFloorSwitch();
                break;
            case HAZARD_SPIKES:
                return new MyGameSpikeHazard();
                break;
            default:
                return null;
        }
    }
        else if (layer == MHMapCell.WALL_LAYER)
        {
            switch(tileID)
            {
                case DOOR_1:
                case DOOR_2:
                case DOOR_3:
                    return new MyGameDoor(tileID);
                    break;
                case COMPUTER_CONSOLE:
                    return new MyGameComputerConsole();
                    break;
                case ALIEN_0:
                    return new MyGameAlien0();
                    break;
            default:
                return null;
            }
        }
        else if (layer == MHMapCell.ITEM_LAYER)
        {
            switch(tileID)
            {
                case WEAPON_1:
                    return new MyGameLaserPistol();
                    break;
                case WEAPON_2:
                    return new MyGameLaserRifle();
                    break;
                case POWERUP:
                        return new MyGamePowerUp();
                        break;
                case KEY:
                        return new MyGameKey();
                        break;
            default:
                return null;
            }
        }
        else
        {
            return null;
        }


Method Summary
 MHActor getObject(int layer, int tileID)
          Accepts layer and tile identifiers, instantiates a special object indicated by them, and returns a reference to it.
 

Method Detail

getObject

MHActor getObject(int layer,
                  int tileID)
Accepts layer and tile identifiers, instantiates a special object indicated by them, and returns a reference to it. If there is no special object for a given identifier, this method should return null.

Parameters:
layer - The layer of the map for which this tile is intended.
tileID - A tile identifier, usually read from a map data file.
Returns:
An object to be placed into a layer of a map cell.