Class MapLoader
java.lang.Object
model.map.MapLoader
Loads one of 10 preset maps, randomly selected for each game.
Uses a shuffle bag to avoid repetition until all 10 maps have been used.
MAP_DATA:
0 = NORMAL 1 = RIVER 2 = TREE 3 = ROCK 4 = ITEM 5 = GOBLIN
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static intCurrent index within the shuffle bag.private static final intTotal number of available maps.private static final int[][][]Data for all 10 map layouts.private static final RandomShared random instance for the shuffle bag and item type selection.private static final int[]Shuffle bag used to select maps without repetition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static MapGridbuildMap(int[][] data) Builds a MapGrid from a raw int[][] data array, placing random items (HealItem, BuffItem, or DefenseItem) and Goblins in the designated cells.static MapGridloadMap(int index) Loads the map at the specified index, intended for testing.static MapGridRandomly loads one of the 10 maps, ensuring no repetition until all maps have been used.private static intPicks the next map index from the shuffle bag.
-
Field Details
-
MAP_COUNT
private static final int MAP_COUNTTotal number of available maps.- See Also:
-
RANDOM
Shared random instance for the shuffle bag and item type selection. -
shuffleBag
private static final int[] shuffleBagShuffle bag used to select maps without repetition. -
bagIndex
private static int bagIndexCurrent index within the shuffle bag. -
MAP_DATA
private static final int[][][] MAP_DATAData for all 10 map layouts.
-
-
Constructor Details
-
MapLoader
public MapLoader()
-
-
Method Details
-
loadRandomMap
Randomly loads one of the 10 maps, ensuring no repetition until all maps have been used.- Returns:
- A ready-to-use MapGrid
-
nextMapIndex
private static int nextMapIndex()Picks the next map index from the shuffle bag. Refills and reshuffles the bag when exhausted.- Returns:
- Index of the map to load (0-9)
-
loadMap
Loads the map at the specified index, intended for testing.- Parameters:
index- Map index (0-9)- Returns:
- A ready-to-use MapGrid
- Throws:
IllegalArgumentException- if the index is not in the range 0-9
-
buildMap
Builds a MapGrid from a raw int[][] data array, placing random items (HealItem, BuffItem, or DefenseItem) and Goblins in the designated cells.- Parameters:
data- Raw map data as int[][]- Returns:
- A MapGrid with all items and goblins placed
-