java.lang.Object
de.hamstersimulator.objectsfirst.adapter.HamsterGameViewModel

public class HamsterGameViewModel extends Object
Provides all components of a game which are necessary to attach a UI or a test framework to a game
  • territory: makes it possible to bind to the territory and observe changes on it
  • controller: makes it possible to control the associated game: stop, pause etc.
  • log: makes it possible to display log messages
Also supports adding inputInterfaces via addInputInterface.
Besides inputInterfaces and the controller, this class only provides read-only access. In particular it is not possible to modify the territory or anything on it or add log messages.
  • Constructor Details

    • HamsterGameViewModel

      public HamsterGameViewModel(ObservableTerritory territory, HamsterGameController gameController, ObservableLog log, Collection<InputInterface> inputInterfaces)
      Creates a new HamsterGameViewModel This is only meant for internal use
      Parameters:
      territory - the territory, must be != null
      gameController - the gameController to stop, pause etc., must be != null
      log - the log with all log messages, must be != null
      inputInterfaces - an initial collection of InputInterfaces, must be != null, might be empty
  • Method Details

    • getTerritory

      public ObservableTerritory getTerritory()
      Getter for the territory This can be used to observe changes of the territory or objects on it (e.g. hamsters)
      Returns:
      The territory (not null)
    • getGameController

      public HamsterGameController getGameController()
      Getter for the gameController This can be used to control the associated game: stop, pause, resume, undo, redo etc.
      Returns:
      The gameController associated with this game (not null)
    • getLog

      public ObservableLog getLog()
      Getter for the log This can be used to get the log entries
      Returns:
      The ObservableLog associated with this game (not null)
    • getInputInterfaces

      public Set<InputInterface> getInputInterfaces()
      Gets the input interfaces of this game used to read values from users or mock objects.
      Returns:
      An unmodifiable set which contains all current input interfaces
    • addInputInterface

      public void addInputInterface(InputInterface newInputInterface)
      Adds newInputInterface to this game's input interfaces for reading values from users or mock objects. Duplicates are ignored
      Parameters:
      newInputInterface - The new input interface, must be != null.
    • removeInputInterface

      public void removeInputInterface(InputInterface inputInterfaceToRemove)
      Removes inputInterfaceToRemove from this game's input interfaces for reading values from users or mock objects
      Parameters:
      inputInterfaceToRemove - The input interface to remove, must be != null