Map design
The following class diagram (Figure 5) shows the top-level architecture for handling the loading of multiple maps and their corresponding entities:
Here, we first start with the MapFactory
class, which can be found at core/src/com/packtpub/libgdx/bludbourne/MapFactory.java
, with the source code as follows:
package com.packtpub.libgdx.bludbourne; import java.util.Hashtable; public class MapFactory { //All maps for the game private static Hashtable<MapType,Map> _mapTable = new Hashtable<MapType, Map>(); public static enum MapType{ TOP_WORLD, TOWN, CASTLE_OF_DOOM } static public Map getMap(MapType mapType){ Map map = null; switch(mapType){ case TOP_WORLD: map = _mapTable.get(MapType.TOP_WORLD); if( map == null ){ map = new TopWorldMap(); _mapTable.put(MapType.TOP_WORLD, map); } break...