Package com.treasure.hunt.game
Class GameManager
- java.lang.Object
-
- com.treasure.hunt.game.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 everyTurn-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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAdditional(java.lang.String key, GeometryItem<?> item)Add an additionalGeometryItemto the rendering queue.java.util.concurrent.CompletableFuture<java.lang.Void>beat(java.lang.Integer maxSteps)This simulates the whole game, until its finished.java.util.concurrent.CompletableFuture<java.lang.Void>beat(javafx.beans.property.ReadOnlyObjectProperty<java.lang.Double> delay)This starts a thread, executingnext()in each timeinterval ofdelay.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.voidbeatSync(java.lang.Integer maxSteps)This simulates the whole game, until its finished.GameManagercopy(com.esotericsoftware.kryo.Kryo kryo)protected booleanearlyExit()Whether the game exits early because of the search being stuck in a specified circular area.javafx.collections.ObservableMap<java.lang.String,GeometryItem<?>>getAdditional()Contains additionalGeometryItem's which does not belong to the strategies, like theGridorGeometryType.HIGHLIGHTER;javafx.beans.property.BooleanPropertygetBeatThreadRunning()javafx.beans.property.BooleanPropertygetFinishedProperty()javafx.beans.binding.ObjectBinding<Turn>getLastMoveBinding()javafx.beans.binding.ObjectBinding<org.locationtech.jts.geom.Point>getLastPointBinding()javafx.beans.binding.ObjectBinding<org.locationtech.jts.geom.Point>getLastTreasureBindings()javafx.beans.binding.BooleanBindinggetLatestStepViewedBinding()javafx.beans.binding.IntegerBindinggetMoveSizeBinding()javafx.beans.binding.ObjectBinding<java.util.List<StatisticObject>>getStatistics()javafx.beans.binding.ObjectBinding<java.util.List<StatusMessageItem>>getStatusMessageItemsBinding()javafx.beans.binding.BooleanBindinggetStepBackwardImpossibleBinding()javafx.beans.binding.BooleanBindinggetStepForwardImpossibleBinding()javafx.collections.ObservableList<Turn>getTurns()Contains the "gameHistory".javafx.beans.property.IntegerPropertygetViewIndex()java.util.stream.Stream<GeometryItem<?>>getVisibleGeometries()Get visible geometry items.java.util.List<Turn>getVisibleTurns()voidinit()Initializes the internalGameEnginebooleanisLatestStepViewed()voidnext()(Simulates) and shows the nextTurn, if the game is not finished.voidprevious()Shows the simulation-state, before the lastTurn.voidread(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)voidremoveAdditional(java.lang.String key)Remove an additionalGeometryItemfrom the rendering queue.protected booleanslowApproachExit()Tests, if the last few steps of the searcher approach the treasure fast enough.voidstopBeat()Stops the beating thread from executingnext().voidwrite(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
-
-
-
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 ofSearcherhiderClass- (Sub-)class ofHidergameEngineClass- (Sub-)class ofGameEngine- Throws:
java.lang.NoSuchMethodException- fromClass.getDeclaredConstructor(Class[])java.lang.IllegalAccessException- fromConstructor.newInstance(Object...)java.lang.reflect.InvocationTargetException- fromConstructor.newInstance(Object...)java.lang.InstantiationException- fromConstructor.newInstance(Object...)
-
-
Method Detail
-
init
public void init()
Initializes the internalGameEngine
-
next
public void next()
(Simulates) and shows the nextTurn, if the game is not finished.
-
previous
public void previous()
Shows the simulation-state, before the lastTurn. Works only for stepView > 0.
-
stopBeat
public void stopBeat()
Stops the beating thread from executingnext().
-
beat
public java.util.concurrent.CompletableFuture<java.lang.Void> beat(javafx.beans.property.ReadOnlyObjectProperty<java.lang.Double> delay)
This starts a thread, executingnext()in each timeinterval ofdelay.- Parameters:
delay- the time interval, the thread executesnext()- Returns:
- a thread
CompletableFuture, executingnext()in each timeinterval ofdelay. - 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
CompletableFutureexecuting, runningmaxStepstimesnext().
-
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 moveexecuteNextOnJavaFxThread- 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 ignoredmaxSteps- the number of time, the beating thread should executenext(). Could benull.- Returns:
- the
CompletableFuturethread, executingnext()maxStepstimes, if its notnull, each timeinterval ofdelay, ifexecuteNextOnJavaFxThreadistrue.
-
getVisibleGeometries
public java.util.stream.Stream<GeometryItem<?>> getVisibleGeometries()
Get visible geometry items. The visibleTurns determine whichGeometryItemare 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 additionalGeometryItemto the rendering queue.- Parameters:
key- name of the additional itemitem- the additional item
-
removeAdditional
public void removeAdditional(java.lang.String key)
Remove an additionalGeometryItemfrom 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:
writein interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)- Specified by:
readin interfacecom.esotericsoftware.kryo.KryoSerializable
-
copy
public GameManager copy(com.esotericsoftware.kryo.Kryo kryo)
- Specified by:
copyin interfacecom.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".
-
getAdditional
public javafx.collections.ObservableMap<java.lang.String,GeometryItem<?>> getAdditional()
Contains additionalGeometryItem's which does not belong to the strategies, like theGridorGeometryType.HIGHLIGHTER;
-
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()
-
-