Class PlacementTool
java.lang.Object
com.csse3200.game.components.structures.tools.Tool
com.csse3200.game.components.structures.tools.PlacementTool
- Direct Known Subclasses:
BasicWallTool,GateTool,IntermediateWallTool,ReplacementTool,TurretTool
An abstract tool which allows the player to place a structure.
This class must be inherited and the createEntity method implemented to function.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPlacementTool(com.badlogic.gdx.utils.ObjectMap<String, Integer> cost) Creates a new tool which allows the placing of structures with the given cost. -
Method Summary
Modifier and TypeMethodDescriptionabstract PlaceableEntitycreateStructure(Entity player) Creates the structure to be placed.com.badlogic.gdx.math.GridPoint2getSnapPosition(com.badlogic.gdx.math.GridPoint2 position) booleanChecks whether the player has sufficient resources to place the structure.booleanAttempts to place a structure at the specified position.booleanisPositionValid(com.badlogic.gdx.math.GridPoint2 position, PlaceableEntity structure) Checks whether the structure can be placed at the given position.
-
Field Details
-
snapX
protected int snapX -
snapY
protected int snapY
-
-
Constructor Details
-
PlacementTool
Creates a new tool which allows the placing of structures with the given cost.- Parameters:
cost- - the cost of the entity being placed.
-
-
Method Details
-
interact
Attempts to place a structure at the specified position. If the position is already occupied or the player has insufficient resources, does nothing. -
getSnapPosition
public com.badlogic.gdx.math.GridPoint2 getSnapPosition(com.badlogic.gdx.math.GridPoint2 position) -
createStructure
Creates the structure to be placed. This must be implemented in subclasses to function.- Parameters:
player- - the player placing the structure.- Returns:
- the structure to be placed.
-
isPositionValid
public boolean isPositionValid(com.badlogic.gdx.math.GridPoint2 position, PlaceableEntity structure) Checks whether the structure can be placed at the given position. By default, checks if the grid position is empty.- Parameters:
position- - the position the structure is trying to be placed at.- Returns:
- whether the structure can be placed at the given position.
-
hasEnoughResources
public boolean hasEnoughResources()Checks whether the player has sufficient resources to place the structure.- Returns:
- whether the player has sufficient resources to place the structure.
-