Class MapLoader

java.lang.Object
model.map.MapLoader

public class MapLoader extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private static int
    Current index within the shuffle bag.
    private static final int
    Total number of available maps.
    private static final int[][][]
    Data for all 10 map layouts.
    private static final Random
    Shared 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static MapGrid
    buildMap(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 MapGrid
    loadMap(int index)
    Loads the map at the specified index, intended for testing.
    static MapGrid
    Randomly loads one of the 10 maps, ensuring no repetition until all maps have been used.
    private static int
    Picks the next map index from the shuffle bag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAP_COUNT

      private static final int MAP_COUNT
      Total number of available maps.
      See Also:
    • RANDOM

      private static final Random RANDOM
      Shared random instance for the shuffle bag and item type selection.
    • shuffleBag

      private static final int[] shuffleBag
      Shuffle bag used to select maps without repetition.
    • bagIndex

      private static int bagIndex
      Current index within the shuffle bag.
    • MAP_DATA

      private static final int[][][] MAP_DATA
      Data for all 10 map layouts.
  • Constructor Details

    • MapLoader

      public MapLoader()
  • Method Details

    • loadRandomMap

      public static MapGrid 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

      public static MapGrid loadMap(int index)
      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

      private static MapGrid buildMap(int[][] data)
      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