public class GameState
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
activePlayer
The index of the player whose turn it is.
|
private VerticalDecomposition |
decomp
The vertical decomposition for the game state.
|
private boolean |
ended
Whether the game has ended or not.
|
private long |
gameEnd
Millisecond time the game ended or -1.
|
private long |
gameStart
Millisecond time the game started or -1 if the game has not started.
|
private java.util.List<GameStateListener> |
listeners
Listeners subscribed for gamestate events.
|
private java.util.List<ConvexObject> |
objects
The convex objects in this game.
|
private java.util.List<Player> |
players
The players playing in this game.
|
private java.lang.String |
seed
The seed of the generator that generated this game's playfield.
|
private SegmentPartitionTree<ConjugationTree<SegmentPartitionTree.LineSegment>> |
segmentTreeConj
The conjugation tree based segment intersection tree.
|
private SegmentPartitionTree<KDTree<SegmentPartitionTree.LineSegment>> |
segmentTreeKD
The kd-tree based segment intersection tree.
|
private ConvexObject |
selected
The convex object currently selected by the player,
or
null if there is no selected object. |
private int |
turns
The number of individual player turns so far in this game.
|
Constructor and Description |
---|
GameState(java.util.List<ConvexObject> objects,
java.lang.String seed,
java.util.List<Player> players)
Constructs a new game state with the given playfield objects, seed and
list of participating players.
|
GameState(PlayfieldGenerator generator,
java.util.List<Player> players)
Constructs a new game state with the given playfield generator and
list of participating players.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Signals that this game was forcefully terminated
before it was supposed to finish.
|
ClaimResult |
claimObject(ConvexObject obj)
Attempts to claim the given convex object for the active player.
|
ClaimResult |
claimObject(ConvexObject obj,
java.awt.geom.Point2D location)
Attempts to claim the given convex object for the active player.
|
void |
clearSelection()
Clears the object selection for the active player,
meaning they are no longer selecting a second object for a merge.
|
private void |
endTurn()
Ends the turn for the active player moving on to the next player.
|
void |
executePlayerTurn()
Executes the turn for the active player.
|
Player |
getActivePlayer()
Gets the active players whose turn it is currently.
|
long |
getGameTime()
Gets the total number of milliseconds this game took
or is taking up to this point in time.
|
java.util.List<java.awt.geom.Line2D> |
getHelperLines(java.awt.geom.Point2D p)
Gets the helper lines to be drawn from the currently
selected first object to the given point.
|
ConvexObject |
getObject(double x,
double y)
Gets the object located at the given coordinates.
|
ConvexObject |
getObject(java.awt.geom.Point2D p)
Gets the object located at the given coordinates.
|
java.util.List<ConvexObject> |
getObjects()
Gets all the objects in this game.
|
int |
getPlayerCount()
Gets the total number of players in this game.
|
java.util.List<Player> |
getPlayers()
Gets a list of all the players in this game.
|
int |
getRounds()
Gets the number of rounds in this game.
|
java.lang.String |
getSeed()
Gets the seed of the playfield generator that
was used to generate this game.
|
SegmentPartitionTree<ConjugationTree<SegmentPartitionTree.LineSegment>> |
getSegmentTreeConj()
Gets the conjugation tree based segment intersection tree for this game state.
|
SegmentPartitionTree<KDTree<SegmentPartitionTree.LineSegment>> |
getSegmentTreeKD()
Gets the kd-tree based segment intersection tree for this game state.
|
ConvexObject |
getSelectedObject()
Gets the (first) object selected by the player.
|
VerticalDecomposition |
getVerticalDecomposition()
Gets the vertical decomposition for the game state.
|
void |
init()
Initialises the game state running tasks that
need to run on the main game thread.
|
boolean |
isFinished()
Checks if the game is finished.
|
boolean |
isSelectingSecond()
True if the active player is currently selecting
a second object to merge with.
|
private ConvexObject |
mergeObjects(ConvexObject first,
ConvexObject second)
Attempts to merge the given two convex objects.
|
boolean |
ready()
Checks if the game state is ready to handle the next turn.
|
void |
registerStateListener(GameStateListener listener)
Registers a listener to receive game status updates.
|
void |
setSelectedObject(ConvexObject obj)
Sets the object selected by the current player.
|
java.util.stream.Stream<ConvexObject> |
stream()
Streams all the objects in this game.
|
private java.util.List<ConvexObject> objects
private java.util.List<Player> players
private VerticalDecomposition decomp
private int activePlayer
private ConvexObject selected
null
if there is no selected object.private boolean ended
private long gameStart
private long gameEnd
private int turns
private java.util.List<GameStateListener> listeners
private java.lang.String seed
private SegmentPartitionTree<ConjugationTree<SegmentPartitionTree.LineSegment>> segmentTreeConj
private SegmentPartitionTree<KDTree<SegmentPartitionTree.LineSegment>> segmentTreeKD
public GameState(PlayfieldGenerator generator, java.util.List<Player> players)
generator
- The generator to use to generate the playfield.players
- The list of participating players.public GameState(java.util.List<ConvexObject> objects, java.lang.String seed, java.util.List<Player> players)
objects
- The playfield objects for the game.seed
- The seed of the playfield generator.players
- The list of participating players.public SegmentPartitionTree<ConjugationTree<SegmentPartitionTree.LineSegment>> getSegmentTreeConj()
public SegmentPartitionTree<KDTree<SegmentPartitionTree.LineSegment>> getSegmentTreeKD()
public void init() throws java.lang.InterruptedException
java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.public boolean ready()
public java.lang.String getSeed()
public void registerStateListener(GameStateListener listener)
listener
- The listener to register.public ClaimResult claimObject(ConvexObject obj) throws java.lang.InterruptedException
obj
- The object to claim.java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.getActivePlayer()
public ClaimResult claimObject(ConvexObject obj, java.awt.geom.Point2D location) throws java.lang.InterruptedException
obj
- The object to claim.location
- The point within the object that was clicked to claim it.java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.getActivePlayer()
private void endTurn()
getActivePlayer()
private ConvexObject mergeObjects(ConvexObject first, ConvexObject second) throws java.lang.InterruptedException
first
- The first object to merge (already owned).second
- The second object to merge (could be unowned).null
if the merge
was not possible.java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.public Player getActivePlayer()
public ConvexObject getObject(java.awt.geom.Point2D p)
p
- The coordinates to get the object at.public ConvexObject getObject(double x, double y)
x
- The x coordinate to look at.y
- The y coordinate to look at.public java.util.List<ConvexObject> getObjects()
public VerticalDecomposition getVerticalDecomposition()
public java.util.List<java.awt.geom.Line2D> getHelperLines(java.awt.geom.Point2D p)
p
- The point to draw the helper lines to.null
if there is no object selected currently.public boolean isSelectingSecond()
public java.util.stream.Stream<ConvexObject> stream()
public java.util.List<Player> getPlayers()
public int getPlayerCount()
public void executePlayerTurn() throws java.lang.InterruptedException
java.lang.InterruptedException
- When the current
thread is interrupted while the player
is executing its move. This signals that
the game was aborted.getActivePlayer()
public boolean isFinished()
public long getGameTime()
public int getRounds()
public void setSelectedObject(ConvexObject obj)
claimObject(ConvexObject)
to set this value as this method does not perform any checks
to ensure it is actually valid for the player to select the
provided object.obj
- The objected to set as selected.claimObject(ConvexObject)
,
claimObject(ConvexObject, Point2D)
public void clearSelection()
public ConvexObject getSelectedObject()
null
.isSelectingSecond()
public void abort()