I want to post this here because is not too complicated to understand to new, interested people to show something that has nothing to do with the BDI-Agent Sytem, just plain Java.
Just almost finished refractoring the Tileset-Logic, Saved inside every SpaceObject inside the WorldModel as Pojos (Plain old Java Object... ^^ so just a normal Java Class) with the help of the power of Enums in Java.
So we have now the Enums for the Tilesets:
(I need the String for setting the SpaceObject-Type inside the running Worldmodel to "find" them later again for manipulating by the user or the Agents)
- {l Code}: {l Select All Code}
public enum MapType
{
// Unknown, need for MapEditor issues
UNKNOWN("unknown", UnknownInfo.class),
// Buildings
HATCHERY("hatchery",HatcheryInfo.class),
LAIR("lair",LairInfo.class),
LIBRARY("library",LibraryInfo.class),
PORTAL("portal",PortalInfo.class),
TORTURE("portal",TortureInfo.class),
TREASURY("treasury",TreasuryInfo.class),
DUNGEONHEART("dungeonheart",DungeonHeartInfo.class),
TRAININGROOM("trainingroom",TrainingRoomInfo.class),
//Solid Types
IMPENETRABLE_ROCK("impenetrable_rock", DirtInfo.class),
ROCK("rock", DirtInfo.class),
REINFORCED_WALL("reinforced_wall", DirtInfo.class),
GOLD("gold", DirtInfo.class),
GOLD_DROPED("gold_dropped", DirtInfo.class),
DIRT_PATH("dirt_path", DefaultTileInfo.class),
CLAIMED_PATH("claimed_path", DefaultTileInfo.class),
GEMS("gems", DefaultTileInfo.class),
WATER("water", WaterInfo.class),
LAVA("lava", WaterInfo.class),
HEROTILE("herotile", DefaultTileInfo.class);
private String name;
private Class<?> pojo;
private MapType(String name, Class<?> pojo)
{
this.name = name;
this.pojo = pojo;
}
..... and getter and setters
And This is the most “abstract” TileType informations that all tiletype share, as you can see I have an abstract Method because I want to force in every more specific Type to set the related Neighbors (Importand for the Neighbour-calculation, most Tiles have 48 possible tiles according to the neighbours):
- {l Code}: {l Select All Code}
public abstract class TileInfo {
protected static MapType mapType;
private static int quantity;
protected int hitpoints;
protected int owner = 0;
protected String neighbourhood;
protected WalkType walkType;
protected boolean locked;
protected NeighbourType neighbourType;
public TileInfo(MapType mapType) {
quantity++;
this.locked = false;
this.hitpoints = 10;
this.owner = 0;
this.neighbourhood = "00000000";
this.walkType = WalkType.PASSABLE;
this.neighbourType = NeighbourType.COMPLEX;
TileInfo.mapType = mapType;
}
public abstract MapType[] getNeighbors();
...and getter and setters of course ^^
So we have then for example an HatcheryInfo who extends the ACenterInfo(that also extends the TileInfo) - a class save the centering value for the center of a Building, for example where the hatchery building should be.
- {l Code}: {l Select All Code}
public class HatcheryInfo extends ACenterBuildingInfo {
private int numChickens;
public HatcheryInfo(MapType mapType)
{
super(mapType);
this.hitpoints = 30;
this.hitpoints = isCenter ? 60 : 30;
}
public int getNumChickens() {
return numChickens;
}
public void setNumChickens(int numChickens) {
this.numChickens = numChickens;
}
}
And I have to use this HashMap to Map the Enums to the Information from the created Map which is saved as String-Informations in a Textfile (created by the MapEditor explained here: Video) :
- {l Code}: {l Select All Code}
public static final Map<String, MapType> TILE_MAP = new HashMap<String, MapType>();
static
{
TILE_MAP.put("1F", MapType.HATCHERY);
TILE_MAP.put("1G", MapType.DUNGEONHEART);
TILE_MAP.put("1C", MapType.TREASURY);
TILE_MAP.put("1F", MapType.HATCHERY);
TILE_MAP.put("1D", MapType.LAIR);
TILE_MAP.put("1E", MapType.PORTAL);
TILE_MAP.put("1I", MapType.TRAININGROOM);
TILE_MAP.put("1L", MapType.LIBRARY);
TILE_MAP.put("1X", MapType.TORTURE);
TILE_MAP.put("Ob", MapType.IMPENETRABLE_ROCK);
TILE_MAP.put("Oc", MapType.ROCK);
TILE_MAP.put("1B", MapType.REINFORCED_WALL);
TILE_MAP.put("Og", MapType.GOLD);
TILE_MAP.put("Oh", MapType.GEMS);
TILE_MAP.put("Od", MapType.DIRT_PATH);
TILE_MAP.put("1A", MapType.CLAIMED_PATH);
TILE_MAP.put("Oe", MapType.WATER);
TILE_MAP.put("Of", MapType.LAVA);
TILE_MAP.put("Oh", MapType.HEROTILE);
....
For the Moment every default/starting Value is saved in the Java-Objects directly. (But when there is more time we should make an external config-file for all the relevant values to easier balance the Game).
- Flipflop