Class MainController

java.lang.Object
com.slinky.hackmaster.controller.MainController

public class MainController extends Object
The MainController class serves as the central controller within the game, managing the interactions between the game's view (UI) components and the underlying game logic and data models. This controller is responsible for handling user inputs, such as cell clicks, and orchestrating the subsequent game responses, including updating the game state, processing word sets, and providing feedback to the player via the display.

The controller interacts with several key components:

  • CellManager - Manages the grid of cells, including their clusters and states.
  • MainView - Handles the display and user interface, showing the results of game actions and the current state of the game.
  • WordSet - Contains the set of possible words and the correct password, crucial to the gameplay.
  • GameState - Tracks the state of the game, including the number of remaining guesses and whether the game is still active.

The MainController is initialised with references to these components and binds event listeners to the cells in the grid. When a cell is clicked, it determines the appropriate response based on the cell's content and the current game state, such as checking if the clicked cell matches the correct password, removing a dud word, or resetting the player's guesses. The controller also ensures that once the correct password is found or guesses are exhausted, further interactions are appropriately disabled.

This class plays a pivotal role in ensuring the game's flow, enforcing the rules, and maintaining a coherent user experience.

Author:
Kheagen Haskins
  • Constructor Details

    • MainController

      public MainController(CellManager cellGrid, MainView display, WordSet wordSet)
      Constructs a new MainController with the specified cell manager, display, and word set. Initialises the correct word and binds click listeners to each cell.
      Parameters:
      cellGrid - the CellManager that manages the grid of cells
      display - the MainView responsible for displaying game information
      wordSet - the WordSet containing possible words and the correct word
  • Method Details

    • setStage

      public void setStage(javafx.stage.Stage stage)
      Sets the primary stage for the controller, allowing the controller to manage and change the scenes displayed on the stage. This method is typically called to pass the main application stage to the controller so that it can control the flow of the application by switching scenes.
      Parameters:
      stage - the primary Stage object of the application, which this controller will use to set and change scenes.