Class GameController
java.lang.Object
com.bdtripp.hauntedhouse.controller.GameController
Exposes the HTTP endpoints used by the client.
The GameController receives player input, delegates it to the GameService for processing, and
returns the resulting output and status.
- Author:
- Brian Tripp
-
Constructor Summary
ConstructorsConstructorDescriptionGameController(GameService gameService) Create the GameController and initialize the GameService. -
Method Summary
Modifier and TypeMethodDescriptionexecuteCommand(GameRequest request) Executes a player command within the current game session.start()Starts a new game session.
-
Constructor Details
-
GameController
Create the GameController and initialize the GameService. Since this class is annotated with @RestController, Spring takes care of instantiating it.- Parameters:
gameService- the GameService that the Game Controller routes request to and responses from.
-
-
Method Details
-
start
Starts a new game session.This endpoint initializes the game world, creates a new player state, and returns the initial output shown to the user. The client should call this endpoint before sending any commands.
- Returns:
- a
GameResponsecontaining the game's initial output and the currentGameStatus.
-
executeCommand
@PostMapping(value="/command", consumes="application/json", produces="application/json") public GameResponse executeCommand(@RequestBody GameRequest request) Executes a player command within the current game session.The client sends a textual command (e.g., "go north", "take key", "look") and receives the resulting game output and updated game status. Commands are interpreted by the game engine and may change the player's location, inventory, or stats.
- Parameters:
request- the player's input command, wrapped in aGameRequest.- Returns:
- a
GameResponsecontaining the engine's output and the updatedGameStatus.
-