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 void
addAdditional(java.lang.String key, GeometryItem<?> item)
Add an additionalGeometryItem
to 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.void
beatSync(java.lang.Integer maxSteps)
This simulates the whole game, until its finished.GameManager
copy(com.esotericsoftware.kryo.Kryo kryo)
protected boolean
earlyExit()
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 theGrid
orGeometryType.HIGHLIGHTER
;javafx.beans.property.BooleanProperty
getBeatThreadRunning()
javafx.beans.property.BooleanProperty
getFinishedProperty()
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.BooleanBinding
getLatestStepViewedBinding()
javafx.beans.binding.IntegerBinding
getMoveSizeBinding()
javafx.beans.binding.ObjectBinding<java.util.List<StatisticObject>>
getStatistics()
javafx.beans.binding.ObjectBinding<java.util.List<StatusMessageItem>>
getStatusMessageItemsBinding()
javafx.beans.binding.BooleanBinding
getStepBackwardImpossibleBinding()
javafx.beans.binding.BooleanBinding
getStepForwardImpossibleBinding()
javafx.collections.ObservableList<Turn>
getTurns()
Contains the "gameHistory".javafx.beans.property.IntegerProperty
getViewIndex()
java.util.stream.Stream<GeometryItem<?>>
getVisibleGeometries()
Get visible geometry items.java.util.List<Turn>
getVisibleTurns()
void
init()
Initializes the internalGameEngine
boolean
isLatestStepViewed()
void
next()
(Simulates) and shows the nextTurn
, if the game is not finished.void
previous()
Shows the simulation-state, before the lastTurn
.void
read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
void
removeAdditional(java.lang.String key)
Remove an additionalGeometryItem
from the rendering queue.protected boolean
slowApproachExit()
Tests, if the last few steps of the searcher approach the treasure fast enough.void
stopBeat()
Stops the beating thread from executingnext()
.void
write(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 ofSearcher
hiderClass
- (Sub-)class ofHider
gameEngineClass
- (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
CompletableFuture
executing, runningmaxSteps
timesnext()
.
-
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
CompletableFuture
thread, executingnext()
maxSteps
times, if its notnull
, each timeinterval ofdelay
, ifexecuteNextOnJavaFxThread
istrue
.
-
getVisibleGeometries
public java.util.stream.Stream<GeometryItem<?>> getVisibleGeometries()
Get visible geometry items. The visibleTurn
s determine whichGeometryItem
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 additionalGeometryItem
to the rendering queue.- Parameters:
key
- name of the additional itemitem
- the additional item
-
removeAdditional
public void removeAdditional(java.lang.String key)
Remove an additionalGeometryItem
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 interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
- Specified by:
read
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
copy
public GameManager copy(com.esotericsoftware.kryo.Kryo kryo)
- Specified by:
copy
in 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 theGrid
orGeometryType.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()
-
-