Class GameEngine

java.lang.Object
com.bdtripp.hauntedhouse.engine.GameEngine

public class GameEngine extends Object
Orchestrates the overall game loop and state transitions. The GameEngine initializes the world, manages game state, delegates command execution, moves the player between rooms, and generates messages.
Author:
Michael Kölling, David J. Barnes, and Brian Tripp
  • Constructor Details

    • GameEngine

      public GameEngine()
      Creates the GameEngine and the game world.
  • Method Details

    • startGame

      public void startGame()
      Starts the game by placing the player in the starting room
    • processCommand

      public String processCommand(Command command)
      Given a command, process (that is: execute) the command.
      Parameters:
      command - the command to be processed.
      Returns:
      a message to display
    • getRandomRoom

      public Room getRandomRoom()
      Returns a random room in the haunted house
      Returns:
      a random room
    • buildWelcomeMessage

      public String buildWelcomeMessage()
      Build the welcome message that displays when a new game is started. Includes information about the room a player is in.
      Returns:
      the welcome message
    • describeCurrentRoom

      public String describeCurrentRoom()
      Gets a description about the room the player is currently in including the items and characters that it contains.
      Returns:
      a description of the room
    • movePlayerTo

      public String movePlayerTo(Room nextRoom, boolean addToHistory)
      Moves the player to the specified room and returns details about the room
      Parameters:
      nextRoom - the room to move to
      addToHistory - true if the current room should be added to history
      Returns:
      the details about the room
    • endGame

      public void endGame()
      Ends the game.
    • isGameOver

      public boolean isGameOver()
      Checks if the game is over
      Returns:
      true if the game is over, false otherwise