Class GameController

java.lang.Object
com.bdtripp.hauntedhouse.controller.GameController

@RestController @RequestMapping("/api/game") @Validated public class GameController extends Object
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 Details

    • GameController

      public GameController(GameService gameService)
      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

      @PostMapping("/start") public GameResponse 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 GameResponse containing the game's initial output and the current GameStatus.
    • 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 a GameRequest.
      Returns:
      a GameResponse containing the engine's output and the updated GameStatus.