Package org.bitsquad.warzone.gameengine
Class GameEngine
java.lang.Object
org.bitsquad.warzone.gameengine.GameEngine
Represents the Game engine.
This class defines a game with a map and a list of players, along with execution details and methods.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks for player win and removes losersvoid
Executes orders in Round-Robin fashionReturns the current player objectint
Returns the currentPlayerIndexGetter method for game mapGetter for game players liststatic GameEngine
Singleton instance getterint
Getter for max rounds of the gameint
getNumberOfReinforcementUnits
(BasePlayer p_player) Calculates number of reinforcement units for a playergetPhase()
Getter for game phasegetPlayerByID
(int p_playerID) Used to get player instance using the player IDGetter for PolicyManager instanceint
Getter for round numberGetter for winnervoid
handleAddPlayer
(String p_playerName) Handler method for gamplayer -add commandvoid
handleAdvance
(String p_countryNameFrom, String p_targetCountryName, int p_armyUnits) Handler method for advance commandvoid
handleAirlift
(int p_sourceCountryId, int p_targetCountryId, int p_numArmies) Handler method for airlift commandvoid
Handler for assigncountries commandvoid
handleBlockade
(int p_targetCountryId) Handler method for blockade commandvoid
handleBomb
(int p_countryId) Handler method for bomb commandvoid
Handler method for commit commandvoid
handleDeployArmy
(int p_targetCountryID, int p_armyUnits) Handler method for deploy army commandvoid
handleEditContinent
(int[] p_addArray, int[] p_removeIds) Handler method for the editcontinent commandvoid
handleEditCountry
(int[] p_addIds, int[] p_removeIds) Handler method for editcountry commandvoid
handleEditMap
(String p_filename) Handler method for editmap commandvoid
handleEditNeighbor
(int[] p_addIds, int[] p_removeIds) Handler method for editneighbor commandvoid
Handler for executing ordersvoid
handleGamePlayer
(String[] p_addNames, String[] p_removeNames) Handler method for the gameplayer commandvoid
handleLoadMap
(String p_filename) Handler method for loadmap commandvoid
handleNegotiate
(int p_targetPlayerId) Handler method for the negotiate commandvoid
handleRemovePlayer
(String p_playerName) Handler method of remove player commandvoid
handleSaveMap
(String p_filename, boolean c) Handler method for savemap commandvoid
Handler method for the validatemap commandvoid
Increments the round numbervoid
Sets up the start of a new roundstatic void
Resets the gameengine instancevoid
setCurrentPlayerIndex
(int p_currentPlayerIndex) Sets the currentPlayervoid
Increments the player index to the next logical onevoid
setGameMap
(Map p_gameMap) Setter for game mapvoid
setGamePlayers
(List<BasePlayer> p_gamePlayers) Setter for game playersvoid
setMaxRounds
(int p_value) Sets the max rounds for the gamevoid
Sets the phasevoid
setRoundNumber
(int p_value) Setter for round numbervoid
setWinner
(BasePlayer d_winner) Setter for winner
-
Method Details
-
getWinner
Getter for winner- Returns:
- BasePlayer Player instance who won the game
-
setWinner
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
Sets the phase- Parameters:
p_newPhase
-
-
getPhase
Getter for game phase- Returns:
- Phase
-
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
Getter method for game map- Returns:
- gamemap the map of the current game engine
-
setGameMap
Setter for game map- Parameters:
p_gameMap
- the map
-
getGamePlayers
Getter for game players list- Returns:
- list of game players
-
setGamePlayers
Setter for game players- Parameters:
p_gamePlayers
- list of game players
-
getCurrentPlayer
Returns the current player object- Returns:
- Player
-
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
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
Handler method for loadmap command- Parameters:
p_filename
- filename of map file- Throws:
Exception
- if the map is invalid or IOError
-
handleDeployArmy
Handler method for deploy army command- Parameters:
p_targetCountryID
- ID of target countryp_armyUnits
- number of army units- Throws:
Exception
-
handleAssignCountries
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
Handler method for savemap command- Parameters:
p_filename
-- Throws:
Exception
-
handleEditMap
Handler method for editmap command- Parameters:
p_filename
-- Throws:
IOException
-
handleValidateMap
public void handleValidateMap()Handler method for the validatemap command -
handleGamePlayer
Handler method for the gameplayer command- Parameters:
p_addNames
-p_removeNames
-
-
handleAddPlayer
Handler method for gamplayer -add command- Parameters:
p_playerName
- name of the player- Throws:
Exception
-
handleRemovePlayer
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
Handler method for bomb command- Parameters:
p_countryId
-- Throws:
Exception
-
handleBlockade
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
Handler method for the negotiate command- Parameters:
p_targetPlayerId
-- Throws:
Exception
-
handleCommit
public void handleCommit()Handler method for commit command -
getPlayerByID
Used to get player instance using the player ID- Parameters:
p_playerID
- Player ID- Returns:
- Player instance
-