-
Notifications
You must be signed in to change notification settings - Fork 4
Tile Highlighting Test
Objective: Confirm that hovering over a tile changes its texture based on the game's conditions, such as the player's currency or existing entities in the tile.
Overview:
The TerrainComponent
class provides functionality to highlight tiles when they are hovered over by the cursor. Depending on the game's state, such as available currency or if a tower is placed, the tile might be highlighted in different colors. This test aims to confirm that these conditions correctly influence the tile's highlighting.
Steps:
-
Initialize
TerrainComponent
:- Set up a mock
TerrainComponent
with a specified orientation, sayTerrainOrientation.ORTHOGONAL
for this test.
- Set up a mock
-
Mock Gdx Input:
- Use Mockito to mock the Gdx.input object.
- Simulate a mouse position by setting values for
getX()
andgetY()
methods.
-
Mock Map Components:
- Create mock objects for the map layers, cells, and tiles to emulate a real map environment.
-
Simulate Mouse Hover:
- Call the
hoverHighlight()
method ofTerrainComponent
.
- Call the
-
Validation:
- Depending on the test scenario (e.g., having enough currency to buy a tower or not), verify that the
setTextureRegion
method of the mock tile is called with the expected texture (e.g., green or red).
- Depending on the test scenario (e.g., having enough currency to buy a tower or not), verify that the
Expected Outcome:
When the mouse hovers over a tile, the tile's texture should be updated to represent the game's current state (e.g., whether the player can afford a tower or not).
Potential Challenges:
-
Multiple Hover Regions: If the game design includes multiple hover states based on several conditions, this test might need to be adapted or expanded to cover those scenarios.
-
Interactions with Other Systems: Ensure that the highlighting mechanism's interactions with other game systems are isolated so they don't interfere with the basic functionality of tile highlighting on hover.
-
Tile Boundaries: It's essential to ensure that the highlighted region is constrained to the boundaries of the tile and does not overflow.
Detailed Test Scenarios:
-
Green Highlight on Hover with Affordability:
Objective: Ensure that the tile turns green when the player has enough currency to buy a specific tower type.
Steps:
- Use the
setUp()
method to initialize the required mocks. - Mock the tower type to be
TowerType.WEAPON
. - Ensure that the entity does not exist on the tile and that the player can afford the tower.
- Simulate the hover action and verify that the tile's texture region changes to green.
- Use the
-
Red Highlight on Hover without Affordability:
Objective: Ensure that the tile turns red when the player does not have enough currency to buy a specific tower type.
Steps:
- Use the
setUp()
method to initialize the required mocks. - Mock the tower type to be
TowerType.TNT
. - Ensure that the entity does not exist on the tile and that the player cannot afford the tower.
- Simulate the hover action and verify that the tile's texture region changes to red.
- Use the