My Project
Static Public Member Functions | List of all members
Controller.MouseHandler Class Reference

Handles all user mouse input. More...

Static Public Member Functions

static void updateMouse (Graph graph, Camera camera)
 

Detailed Description

Handles all user mouse input.

This class performs appropriate actions in response to user mouse input by updating the Model.
It does so by calling GameFunction (which is also in the Controller) to update the Model (state of the game) in reaction to user input. Additionally, it updates GameState (in the Model) in order to reflect an update in the game's current status based upon specific conditions in addition to mouse input.
All of the mouse handling is done within one function, the updateMouse() function, as mouse handling only consists of checking conditionals to perform calls to the GameFunction (which performs further actions) or an update in the GameState.

Member Function Documentation

§ updateMouse()

static void Controller.MouseHandler.updateMouse ( Graph  graph,
Camera  camera 
)
inlinestatic

Performs appropriate actions in response to mouse input and current state of the game. These actions include updating the GameState and calling the GameFunction to perform further actions.

Mouse Handling Actions:

  • No reaction to mouse input if the game currently has an animation on the screen (condition checked using GameState.isAnimating).
  • No reaction if mouse clicks occur outside of the game window (invalid mouse click coordinates).
  • Scrolling of map corresponding to the position of the mouse relative to the window. Scrolling occurs through calling GameFunction's scrollMap().
  • If any unit is selected and a right-click occurs, deselect it.
  • If no unit is selected and a right-click occurs, display the 'End Turn' button.
  • If 'End Turn' button is displayed and a left-click occurs on it, call GameFunction's endTurn() to end the current player's turn.
  • If screen currently displays 'Game Over', check if a left-click occurs on the 'Exit Game' button. If so, set GameState's exitGameClicked to true.
  • If an enemy unit is selected and a left-click occurs, deselect it.
  • If a playable unit is selected and a left-click occurs:
    1. Check if the click occured on a menu button; if so, update GameState's TurnState.
    2. Check if the click occured on a valid moveable node (by checking if GameFunction's pathFinder() function does not return null) and if GameState's TurnState is currently Move. If so, call GameFunction's updateUnitPosition() to move the unit. Else, deselect the unit.
    3. Check if the click occured on an enemy unit within attack range (by using GameFunction's isEnemyUnitInRange()) and if GameState's TurnState is currently Attack. If so, prompt the Attack Confirm (by updating GameState's attackConfirmOpen) and set GameState's unitToAttack. Else, deselect the unit.
  • If no unit is selected and a left-click occurs, check if the user clicked on a unit. If the user clicked on a playable unit, set GameState's selectedUnit. If the user clicked on an enemy unit, set GameState's selectedEnemyUnit. Else, do nothing.
    Parameters
    graphThe Graph representing the current game map (see Graph class). Requires the graph in order to verify conditions that may lead to a change in the Model.
    cameraThe camera of the game. Requires the camera in order to scroll the map upon satisfactory circumstances (see Mouse Handling Actions bullet 3).

The documentation for this class was generated from the following file: