Class GameManager

  • All Implemented Interfaces:
    com.esotericsoftware.kryo.KryoCopyable<GameManager>, com.esotericsoftware.kryo.KryoSerializable

    public class GameManager
    extends java.lang.Object
    implements com.esotericsoftware.kryo.KryoSerializable, com.esotericsoftware.kryo.KryoCopyable<GameManager>
    The GameManager stores every Turn-objects, happened in the game, the binds the views to update them for every move and runs the GameEngine step for step.
    • Constructor Summary

      Constructors 
      Constructor Description
      GameManager​(java.lang.Class<? extends Searcher> searcherClass, java.lang.Class<? extends Hider> hiderClass, java.lang.Class<? extends GameEngine> gameEngineClass)  
    • Constructor Detail

      • GameManager

        public GameManager​(java.lang.Class<? extends Searcher> searcherClass,
                           java.lang.Class<? extends Hider> hiderClass,
                           java.lang.Class<? extends GameEngine> gameEngineClass)
                    throws java.lang.NoSuchMethodException,
                           java.lang.IllegalAccessException,
                           java.lang.reflect.InvocationTargetException,
                           java.lang.InstantiationException
        Parameters:
        searcherClass - (Sub-)class of Searcher
        hiderClass - (Sub-)class of Hider
        gameEngineClass - (Sub-)class of GameEngine
        Throws:
        java.lang.NoSuchMethodException - from Class.getDeclaredConstructor(Class[])
        java.lang.IllegalAccessException - from Constructor.newInstance(Object...)
        java.lang.reflect.InvocationTargetException - from Constructor.newInstance(Object...)
        java.lang.InstantiationException - from Constructor.newInstance(Object...)
    • Method Detail

      • init

        public void init()
        Initializes the internal GameEngine
      • next

        public void next()
        (Simulates) and shows the next Turn, if the game is not finished.
      • previous

        public void previous()
        Shows the simulation-state, before the last Turn. Works only for stepView > 0.
      • stopBeat

        public void stopBeat()
        Stops the beating thread from executing next().
      • beat

        public java.util.concurrent.CompletableFuture<java.lang.Void> beat​(javafx.beans.property.ReadOnlyObjectProperty<java.lang.Double> delay)
        This starts a thread, executing next() in each timeinterval of delay.
        Parameters:
        delay - the time interval, the thread executes next()
        Returns:
        a thread CompletableFuture, executing next() in each timeinterval of delay.
        See Also:
        beat(ReadOnlyObjectProperty, Boolean, Integer)
      • beat

        public java.util.concurrent.CompletableFuture<java.lang.Void> beat​(java.lang.Integer maxSteps)
        This simulates the whole game, until its finished.
        Parameters:
        maxSteps - the maximum number of steps, which will be simulated
        Returns:
        the CompletableFuture executing, running maxSteps times next().
      • beatSync

        public void beatSync​(java.lang.Integer maxSteps)
        This simulates the whole game, until its finished.
        Parameters:
        maxSteps - the maximum number of steps, which will be simulated
      • beat

        public java.util.concurrent.CompletableFuture<java.lang.Void> beat​(javafx.beans.property.ReadOnlyObjectProperty<java.lang.Double> delay,
                                                                           java.lang.Boolean executeNextOnJavaFxThread,
                                                                           java.lang.Integer maxSteps)
        This simulates the whole game, until its finished.
        Parameters:
        delay - time between each move
        executeNextOnJavaFxThread - if set to true the next call is made on javafx thread that is important when UI is attached to the GameManager, if it false the delay parameter is ignored
        maxSteps - the number of time, the beating thread should execute next(). Could be null.
        Returns:
        the CompletableFuture thread, executing next() maxSteps times, if its not null, each timeinterval of delay, if executeNextOnJavaFxThread is true.
      • getVisibleGeometries

        public java.util.stream.Stream<GeometryItem<?>> getVisibleGeometries()
        Get visible geometry items. The visible Turns determine which GeometryItem are visible.
        Returns:
        stream of visible geometry items
      • getVisibleTurns

        public java.util.List<Turn> getVisibleTurns()
        Returns:
        only viewed moves
      • isLatestStepViewed

        public boolean isLatestStepViewed()
        Returns:
        true, if the shown step is the most up to date one. false, otherwise.
      • addAdditional

        public void addAdditional​(java.lang.String key,
                                  GeometryItem<?> item)
        Add an additional GeometryItem to the rendering queue.
        Parameters:
        key - name of the additional item
        item - the additional item
      • removeAdditional

        public void removeAdditional​(java.lang.String key)
        Remove an additional GeometryItem from the rendering queue.
        Parameters:
        key - name of the additional item to be removed
      • write

        public void write​(com.esotericsoftware.kryo.Kryo kryo,
                          com.esotericsoftware.kryo.io.Output output)
        Specified by:
        write in interface com.esotericsoftware.kryo.KryoSerializable
      • read

        public void read​(com.esotericsoftware.kryo.Kryo kryo,
                         com.esotericsoftware.kryo.io.Input input)
        Specified by:
        read in interface com.esotericsoftware.kryo.KryoSerializable
      • copy

        public GameManager copy​(com.esotericsoftware.kryo.Kryo kryo)
        Specified by:
        copy in interface com.esotericsoftware.kryo.KryoCopyable<GameManager>
      • earlyExit

        protected boolean earlyExit()
        Whether the game exits early because of the search being stuck in a specified circular area.
        Returns:
        whether the game exits early or not
      • slowApproachExit

        protected boolean slowApproachExit()
        Tests, if the last few steps of the searcher approach the treasure fast enough. The approach is measured as the euclidean distance between the treasure and the respective search paths last point.
        Returns:
        whether the game exits early because of the searcher not progressing fast enough
      • getTurns

        public javafx.collections.ObservableList<Turn> getTurns()
        Contains the "gameHistory".
      • getBeatThreadRunning

        public javafx.beans.property.BooleanProperty getBeatThreadRunning()
      • getFinishedProperty

        public javafx.beans.property.BooleanProperty getFinishedProperty()
      • getViewIndex

        public javafx.beans.property.IntegerProperty getViewIndex()
      • getLatestStepViewedBinding

        public javafx.beans.binding.BooleanBinding getLatestStepViewedBinding()
      • getLastMoveBinding

        public javafx.beans.binding.ObjectBinding<Turn> getLastMoveBinding()
      • getLastTreasureBindings

        public javafx.beans.binding.ObjectBinding<org.locationtech.jts.geom.Point> getLastTreasureBindings()
      • getLastPointBinding

        public javafx.beans.binding.ObjectBinding<org.locationtech.jts.geom.Point> getLastPointBinding()
      • getMoveSizeBinding

        public javafx.beans.binding.IntegerBinding getMoveSizeBinding()
      • getStepForwardImpossibleBinding

        public javafx.beans.binding.BooleanBinding getStepForwardImpossibleBinding()
      • getStepBackwardImpossibleBinding

        public javafx.beans.binding.BooleanBinding getStepBackwardImpossibleBinding()
      • getStatistics

        public javafx.beans.binding.ObjectBinding<java.util.List<StatisticObject>> getStatistics()
      • getStatusMessageItemsBinding

        public javafx.beans.binding.ObjectBinding<java.util.List<StatusMessageItem>> getStatusMessageItemsBinding()