Class IslandField

java.lang.Object
it.polimi.ingsw.Model.IslandField
All Implemented Interfaces:
Serializable

public class IslandField extends Object implements Serializable
All IslandGroups in the game need to be contained in a circular structure. This class does just that - along joining the groups and tracking Mother Nature's position
See Also:
  • Field Details

  • Constructor Details

    • IslandField

      public IslandField()
      Creates the Field, populating it with 12 Islands and 12 IslandGroups. The generated elements are populated with following the rules of the game.
  • Method Details

    • getMutableGroups

      public List<IslandGroup> getMutableGroups()
      Returns:
      an unmodifiable List containing all the IslandGroups on the field. Each element on the list CAN be modified, the list itself can't.
    • getMutableIslands

      public List<Island> getMutableIslands()
      Returns:
      an unmodifiable List containing all the Islands on the field. Each element on the list CAN be modified, the list itself can't.
    • getMutableIslandGroupById

      public IslandGroup getMutableIslandGroupById(int id) throws InvalidContainerIndexException
      Parameters:
      id - the ID of the group to search for
      Returns:
      the IslandGroup matching the ID on the input
      Throws:
      InvalidContainerIndexException - if the specified ID is not in the list of currently active groups, this exception is thrown
    • getMutableIslandById

      public Island getMutableIslandById(int id) throws InvalidContainerIndexException
      Parameters:
      id - the ID of the island to search for
      Returns:
      the Island matching the ID on the input
      Throws:
      InvalidContainerIndexException - if the specified ID is not in the list of currently active islands, this exception is thrown
    • moveMotherNature

      protected void moveMotherNature(int moves)
      this method is Package-private - moving mother nature through this method does not enact its power. it is therefore unsafe to call this outside of very specific circumstances.
      Parameters:
      moves - the amount of moves mother nature will move.
    • joinGroups

      public void joinGroups()
      When called, this method will join the groups adjacent to mother nature following the game's rules.
    • getMutableMotherNaturePosition

      public IslandGroup getMutableMotherNaturePosition()
      Returns:
      the IslandGroup matching the position of mother nature
    • nextGroup

      private IslandGroup nextGroup(IslandGroup curr)
      searches for the IslandGroup adjacent to a selected one
      Parameters:
      curr - the IslandGroup you wish to find the next adjacent one
      Returns:
      the IslandGroup that comes after the one in input
    • prevGroup

      private IslandGroup prevGroup(IslandGroup curr)
      searches for the IslandGroup adjacent to a selected one
      Parameters:
      curr - the IslandGroup you wish to find the previous adjacent one
      Returns:
      the IslandGroup that comes before the one in input
    • ifJoinableThenJoin

      private void ifJoinableThenJoin(IslandGroup motherGroup, IslandGroup otherGroup)
      Two groups are considered joinable if they share the same tower colour.
      Parameters:
      motherGroup - the group on which Mother nature is standing
      otherGroup - a group adjacent to motherGroup