Class ReplacementTool
java.lang.Object
com.csse3200.game.components.structures.tools.Tool
com.csse3200.game.components.structures.tools.PlacementTool
com.csse3200.game.components.structures.tools.ReplacementTool
- Direct Known Subclasses:
ExtractorTool
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 inherited from class com.csse3200.game.components.structures.tools.PlacementTool
snapX, snapY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedReplacementTool(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.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.Methods inherited from class com.csse3200.game.components.structures.tools.PlacementTool
getSnapPosition
-
Constructor Details
-
ReplacementTool
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.- Overrides:
interactin classPlacementTool- Parameters:
player- - the player interacting with the tool.position- - the position to place the structure.- Returns:
- whether the structure was successfully placed.
-
createStructure
Creates the structure to be placed. This must be implemented in subclasses to function.- Specified by:
createStructurein classPlacementTool- 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.- Overrides:
isPositionValidin classPlacementTool- 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.- Overrides:
hasEnoughResourcesin classPlacementTool- Returns:
- whether the player has sufficient resources to place the structure.
-