GameAreaService - UQcsse3200/2024-studio-1 GitHub Wiki

Overview

GameAreaService is a service that provides access to the GameController and GameArea within the game. It acts as an intermediary, allowing other classes to interact with the game area and controller without direct dependencies.Basically it is a service for classes that need to spawn and dispose entities in the gamearea within their own class

Key Components

  • GameController: The main controller for the game, managing levels, rooms, and game state.
  • GameArea: Represents the current game area, handling entity spawning and disposal.

Core methods

  1. getGameArea(): Returns the current GameArea object.
  2. getGameController(): Returns the GameController object.
  3. update(): Triggers the spawning of the current room in the GameController.

Registering Service for Use

ServiceLocator.registerGameAreaService(new GameAreaService(gameController));
// spawning created entity
ServiceLocator.getGameAreaService().getGameArea().spawnEntity(entity);
// disposing entity
ServiceLocator.getGameAreaService().getGameArea().disposeEntity(entity);

When you should use GameAreaService

  • Spawn or dispose of entities from a class that doesn't directly interact with the game area.
  • Access the GameController for game state management.
  • Trigger updates to the current room or game state.

Usage

Correct implementation - is the WeaponComponent, that needs to spawn a projectile entity based off a triggered event acting within the bound of its class.
Incorrect implementation - is using the service in Rooms unnecessarily when the GameArea is passed as an argument to the function

UML Diagram

image