Class GameEngine

java.lang.Object
org.bitsquad.warzone.gameengine.GameEngine

public class GameEngine extends Object
Represents the Game engine.

This class defines a game with a map and a list of players, along with execution details and methods.

  • Method Details

    • getWinner

      public BasePlayer getWinner()
      Getter for winner
      Returns:
      BasePlayer Player instance who won the game
    • setWinner

      public void setWinner(BasePlayer d_winner)
      Setter for winner
      Parameters:
      d_winner -
    • setRoundNumber

      public void setRoundNumber(int p_value)
      Setter for round number
      Parameters:
      p_value - Round number
    • incrementRoundNumber

      public void incrementRoundNumber()
      Increments the round number
    • getRoundNumber

      public int getRoundNumber()
      Getter for round number
      Returns:
      int Round number
    • setMaxRounds

      public void setMaxRounds(int p_value)
      Sets the max rounds for the game
      Parameters:
      p_value - Integer
    • getMaxRounds

      public int getMaxRounds()
      Getter for max rounds of the game
      Returns:
    • setPhase

      public void setPhase(Phase p_newPhase)
      Sets the phase
      Parameters:
      p_newPhase -
    • getPhase

      public Phase getPhase()
      Getter for game phase
      Returns:
      Phase
    • getPolicyManager

      public PolicyManager getPolicyManager()
      Getter for PolicyManager instance
      Returns:
      PolicyManager
    • getCurrentPlayerIndex

      public int getCurrentPlayerIndex()
      Returns the currentPlayerIndex
      Returns:
      int
    • setCurrentPlayerIndex

      public void setCurrentPlayerIndex(int p_currentPlayerIndex)
      Sets the currentPlayer
      Parameters:
      p_currentPlayerIndex - is the current player index
    • setCurrentPlayerIndexToNextPlayer

      public void setCurrentPlayerIndexToNextPlayer()
      Increments the player index to the next logical one
    • getGameMap

      public Map getGameMap()
      Getter method for game map
      Returns:
      gamemap the map of the current game engine
    • setGameMap

      public void setGameMap(Map p_gameMap)
      Setter for game map
      Parameters:
      p_gameMap - the map
    • getGamePlayers

      public List<BasePlayer> getGamePlayers()
      Getter for game players list
      Returns:
      list of game players
    • setGamePlayers

      public void setGamePlayers(List<BasePlayer> p_gamePlayers)
      Setter for game players
      Parameters:
      p_gamePlayers - list of game players
    • getCurrentPlayer

      public BasePlayer getCurrentPlayer()
      Returns the current player object
      Returns:
      Player
    • getInstance

      public static GameEngine getInstance()
      Singleton instance getter
      Returns:
      instance of GameEngine
    • resetInstance

      public static void resetInstance()
      Resets the gameengine instance
    • handleExecuteOrders

      public void handleExecuteOrders()
      Handler for executing orders
    • executeOrders

      public void executeOrders()
      Executes orders in Round-Robin fashion
    • nextRound

      public void nextRound()
      Sets up the start of a new round
    • getNumberOfReinforcementUnits

      public int getNumberOfReinforcementUnits(BasePlayer p_player)
      Calculates number of reinforcement units for a player
      Parameters:
      p_player - Player Objec
      Returns:
      int number of reinforcement units
    • checkPlayerWinAndRemoveLosers

      public boolean checkPlayerWinAndRemoveLosers()
      Checks for player win and removes losers
      Returns:
      Boolean if there is a game winner
    • handleLoadMap

      public void handleLoadMap(String p_filename) throws Exception
      Handler method for loadmap command
      Parameters:
      p_filename - filename of map file
      Throws:
      Exception - if the map is invalid or IOError
    • handleDeployArmy

      public void handleDeployArmy(int p_targetCountryID, int p_armyUnits) throws Exception
      Handler method for deploy army command
      Parameters:
      p_targetCountryID - ID of target country
      p_armyUnits - number of army units
      Throws:
      Exception
    • handleAssignCountries

      public void handleAssignCountries() throws Exception
      Handler for assigncountries command
      Throws:
      Exception
    • handleEditContinent

      public void handleEditContinent(int[] p_addArray, int[] p_removeIds)
      Handler method for the editcontinent command
      Parameters:
      p_addArray -
      p_removeIds -
    • handleEditCountry

      public void handleEditCountry(int[] p_addIds, int[] p_removeIds)
      Handler method for editcountry command
      Parameters:
      p_addIds -
      p_removeIds -
    • handleEditNeighbor

      public void handleEditNeighbor(int[] p_addIds, int[] p_removeIds)
      Handler method for editneighbor command
      Parameters:
      p_addIds -
      p_removeIds -
    • handleSaveMap

      public void handleSaveMap(String p_filename, boolean c) throws Exception
      Handler method for savemap command
      Parameters:
      p_filename -
      Throws:
      Exception
    • handleEditMap

      public void handleEditMap(String p_filename) throws IOException
      Handler method for editmap command
      Parameters:
      p_filename -
      Throws:
      IOException
    • handleValidateMap

      public void handleValidateMap()
      Handler method for the validatemap command
    • handleGamePlayer

      public void handleGamePlayer(String[] p_addNames, String[] p_removeNames)
      Handler method for the gameplayer command
      Parameters:
      p_addNames -
      p_removeNames -
    • handleAddPlayer

      public void handleAddPlayer(String p_playerName) throws Exception
      Handler method for gamplayer -add command
      Parameters:
      p_playerName - name of the player
      Throws:
      Exception
    • handleRemovePlayer

      public void handleRemovePlayer(String p_playerName) throws Exception
      Handler method of remove player command
      Parameters:
      p_playerName - Player name
      Throws:
      Exception
    • handleAdvance

      public void handleAdvance(String p_countryNameFrom, String p_targetCountryName, int p_armyUnits) throws Exception
      Handler method for advance command
      Parameters:
      p_countryNameFrom -
      p_targetCountryName -
      p_armyUnits -
      Throws:
      Exception
    • handleBomb

      public void handleBomb(int p_countryId) throws Exception
      Handler method for bomb command
      Parameters:
      p_countryId -
      Throws:
      Exception
    • handleBlockade

      public void handleBlockade(int p_targetCountryId) throws Exception
      Handler method for blockade command
      Parameters:
      p_targetCountryId -
      Throws:
      Exception
    • handleAirlift

      public void handleAirlift(int p_sourceCountryId, int p_targetCountryId, int p_numArmies) throws Exception
      Handler method for airlift command
      Parameters:
      p_sourceCountryId -
      p_targetCountryId -
      p_numArmies -
      Throws:
      Exception
    • handleNegotiate

      public void handleNegotiate(int p_targetPlayerId) throws Exception
      Handler method for the negotiate command
      Parameters:
      p_targetPlayerId -
      Throws:
      Exception
    • handleCommit

      public void handleCommit()
      Handler method for commit command
    • getPlayerByID

      public BasePlayer getPlayerByID(int p_playerID)
      Used to get player instance using the player ID
      Parameters:
      p_playerID - Player ID
      Returns:
      Player instance