GridManager
Overview
The GridManager
class is responsible for managing the game grid's entities, enemy counters, and special objects like XpCrystals and TreasureChests. It provides methods for registering and unregistering entities at specific grid positions, handling their movement, and querying the grid for entity and obstacle information.
Properties and Fields
Instance: Singleton instance for global access.
POSSIBLE_MOVES: A list of Vector2s representing possible movement directions.
xpSmall, xpMedium, xpLarge, xpUnlimited, treasureChest: GameObjects for different kinds of pickups.
enemyCounterPrefab: Prefab used for UI enemy counters.
playerPosition: Vector2 holding the player's position on the grid.
serializedObstaclePositions, ObstaclePositionsDictionary: Collections for storing obstacle positions.
obstaclePositions, enemyPositions: HashSets for efficient position lookups.
grid: A dictionary mapping grid positions to lists of entities.
enemyCounters, enemyCounts: Dictionaries for managing enemy counters in the UI.
XpCrystals, xpPrefabs: Dictionaries holding information about XpCrystals.
TreasureChests: Dictionary for managing TreasureChest objects.
Methods
Initialization
Start(): Initialize various settings and objects.
HandleStartMethods(): Additional initialization steps.
Game State
HandleOnGameEnd(): Actions to take when the game ends.
ResetGrid(): Clears the grid of all entities.
Entity Registration and Movement
RegisterEntityAtPosition(), UnregisterEntityAtPosition(): Methods to register and unregister entities at specific grid positions.
MoveEntityOneStep(): Move an entity from an old position to a new position.
IsValidMove(), PerformMove(): Validate and perform entity movement.
Grid Querying
PositionExists(), IsEnemyAtPosition(): Methods to check if a position exists or is occupied by an enemy.
GetRandomLivingEnemy(): Returns a random living enemy entity.
GetEntitiesAtPosition(): Returns a list of entities at a specific grid position.
IsPositionOccupiedByObstacle(), GetOObstacleAtPosition(): Checks for obstacles at a specific position and returns the obstacle entity if present.
Pathfinding
- GetBestNextStep(), GetBestPathToTarget(): Methods for determining best paths for entities.
Special Objects
CreateXpCrystalAtPosition(), RemoveXpCrystalAtPosition(): Methods for adding and removing XpCrystals.
AddTreasureChest(), RemoveTreasureChestAtPosition(): Methods for managing TreasureChest objects.
Refactoring and Auditing Considerations for Version 0.6.0
Consider breaking down
GridManager
into more specialized managers for better separation of concerns.Evaluate the efficiency of grid querying and look-up methods for potential optimizations.
Assess the possibility of improving the pathfinding algorithms.
Evaluate the need for thread-safety, particularly in methods that alter shared data structures.