evolution
Class WorldController


public class WorldController
implements Observer

A class of world controllers. This is a facade.


Constructor Summary
WorldController(String configFile, int width, int height)
          Create a new worldcontroller (and a new world).

Method Summary
 voidclearSelection()
          Clear the selected humans.
 voidcontinueGame()
          Resume the game.
 voidcreateHuman()
          Toggle creating a human.
 protected StringgetActionName()
          Return the name of the currently selected action.
 InfoListgetActionsInfo()
          All available actions.
 InfoListgetConstructionInfo()
          Get an infolist with info about the selected construction.
 protected StringgetConstructionName()
          Return the currently selected construction name.
 protected StringgetConstructionShape()
          Return the selected construction shape.
 ListgetConstructionShapes(String constructionName)
          The shapes the given construction can be build in.
 InfoListgetConstructionsInfo()
          All available constructions.
 intgetHeight()
          Get the height of this world.
 InfoListgetHumanInfo()
          Get an infolist with info about the selected human.
 protected HumanSelectiongetHumanSelection()
          Return the human selection of this human.
 StringgetResourcePath()
          The resource path.
 InfoListgetResourcesInfo()
          Get an infolist with all the world resources.
 protected SquareOfLandgetSelectedSquare()
          Return the square of land that is currently selected.
 InfoListgetSquareInfo()
          Get an infolist with info about the selected square.
 intgetWidth()
          Get the width of this world.
 protected WorldgetWorld()
          return the world (= singleton !) of this worldcontroller.
 protected voidinitState()
          Return to the initial state of this worldcontroller.
 booleanisActiveSelected(Human human)
          Is the given human actively selected?
 protected booleanisCreateHuman()
          Return whether we are going to create a human with the next square selection
 booleanisRunning()
          Is the game running?
 booleanisSelected(Human human)
          Is the given human selected?
 voidmodifyVisionRange(int value)
          Modify the visionrange of this worldcontroller.
 voidpauseGame()
          Pause the game.
 voidrefresh()
          Let all the squares fire a changed event.
 protected voidresetActionName()
          Set the selected action to the default action.
 voidselectActionType(String actionName)
          Select an action to be performed.
 voidselectConstructionShape(String shape)
          Specify the shape the construction should have.
 voidselectConstructionType(String constructionName)
          Select a construction to be constructed.
 voidselectSquareOfLand(int x, int y)
          Select a square of land.
 protected voidsetActionName(String actionName)
          Set the selected action to the given action.
 protected voidsetConstructionName(String constructionName)
          Set the selected construction name to the given construction name.
 protected voidsetConstructionShape(String constructionShape)
          Set the selected construction shape to the given construction shape.
 protected voidsetCreateHuman(boolean b)
          Set the boolean value that determines whether we are going to create a human with the next square selection
 protected voidsetSelectedSquare(SquareOfLand square)
          Set the selected square of land to the given square of land.
 protected voidstartAction()
          Start the selected action.
 voidstartGame()
          Start the game.
 voidupdate(Event evt)
          Called when an event happens this observer is interested in.

Constructor Detail

WorldController

public WorldController(String configFile, int width, int height)
throws java.io.FileNotFoundException,
java.io.IOException
Create a new worldcontroller (and a new world). The world will be created in the pause mode, so one needs to call startGame() to start playing.
Parameters:
width - The width of the game board
height - The height of the game board
configFile - The main configuration file on which this world should be based. From this configuration file the path is stripped and used as the resource path to load other config files and images.
Method Detail

clearSelection

public void clearSelection()
Clear the selected humans.

continueGame

public void continueGame()
Resume the game.

createHuman

public void createHuman()
Toggle creating a human.

getActionName

protected String getActionName()
Return the name of the currently selected action.

getActionsInfo

public InfoList getActionsInfo()
All available actions.

getConstructionInfo

public InfoList getConstructionInfo()
Get an infolist with info about the selected construction.

getConstructionName

protected String getConstructionName()
Return the currently selected construction name.

getConstructionShape

protected String getConstructionShape()
Return the selected construction shape.

getConstructionShapes

public List getConstructionShapes(String constructionName)
The shapes the given construction can be build in. Returns a List of Strings according to the shape spec. e.g. {"1x1:1", "2x2:1101", "3x2:111111101"}

getConstructionsInfo

public InfoList getConstructionsInfo()
All available constructions.

getHeight

public int getHeight()
Get the height of this world.

getHumanInfo

public InfoList getHumanInfo()
Get an infolist with info about the selected human.

getHumanSelection

protected HumanSelection getHumanSelection()
Return the human selection of this human.

getResourcePath

public String getResourcePath()
The resource path.

getResourcesInfo

public InfoList getResourcesInfo()
Get an infolist with all the world resources.

getSelectedSquare

protected SquareOfLand getSelectedSquare()
Return the square of land that is currently selected.

getSquareInfo

public InfoList getSquareInfo()
Get an infolist with info about the selected square.

getWidth

public int getWidth()
Get the width of this world.

getWorld

protected World getWorld()
return the world (= singleton !) of this worldcontroller.

initState

protected void initState()
Return to the initial state of this worldcontroller.

isActiveSelected

public boolean isActiveSelected(Human human)
Is the given human actively selected?

isCreateHuman

protected boolean isCreateHuman()
Return whether we are going to create a human with the next square selection

isRunning

public boolean isRunning()
Is the game running?

isSelected

public boolean isSelected(Human human)
Is the given human selected?

modifyVisionRange

public void modifyVisionRange(int value)
Modify the visionrange of this worldcontroller.

pauseGame

public void pauseGame()
Pause the game.

refresh

public void refresh()
Let all the squares fire a changed event.

resetActionName

protected void resetActionName()
Set the selected action to the default action.

selectActionType

public void selectActionType(String actionName)
Select an action to be performed.
Throws:
NoHumanSelectionException - If there are no humans selected to perform the given action when a square would be selected.

selectConstructionShape

public void selectConstructionShape(String shape)
Specify the shape the construction should have. e.g. "1x1:1", "2x2:1101", "3x2:111111101"

selectConstructionType

public void selectConstructionType(String constructionName)
Select a construction to be constructed.
Throws:
NoHumanSelectionException - If there are no humans selected to perform the action when a square would be selected.

selectSquareOfLand

public void selectSquareOfLand(int x, int y)
throws evolution.lands.IllegalPlacementException
Select a square of land.
If there is no human on the square
if we were to create a human
=> the human is created
elseif there are humans selected
=> one or more humans will be popped of the selection and
start performing the action.
else
=> the square is selected
else
if the human is selected
=> let it perform the selected action
else
=> the human is added to the selection and the square is selected
Precondition: the x, y must denote a valid square.
Throws:
IllegalPlacementException - The popped human can not stand on the given type of land. The human will stay were ever he was and stays selected.

setActionName

protected void setActionName(String actionName)
Set the selected action to the given action.

setConstructionName

protected void setConstructionName(String constructionName)
Set the selected construction name to the given construction name.

setConstructionShape

protected void setConstructionShape(String constructionShape)
Set the selected construction shape to the given construction shape.

setCreateHuman

protected void setCreateHuman(boolean b)
Set the boolean value that determines whether we are going to create a human with the next square selection

setSelectedSquare

protected void setSelectedSquare(SquareOfLand square)
Set the selected square of land to the given square of land.

startAction

protected void startAction()
throws evolution.lands.IllegalPlacementException
Start the selected action.

startGame

public void startGame()
Start the game. Does nothing if the game is already started.

update

public void update(Event evt)
Called when an event happens this observer is interested in.

Association Links

to Class evolution.HumanSelection

The human selection.

to Class evolution.lands.SquareOfLand

The selected square of land.

to Class java.lang.String

The action name which was selected.

to Class java.lang.String

The construction name which was selected.

to Class java.lang.String

The construction shape which was selected.

to Class evolution.World

Just for easy referencing, but remember: world is a singleton.

a gvijf production