C# Class Terrarium.Game.WorldState

Mostra file Open project: eugeniomiro/Terrarium Class Usage Examples

Public Methods

Method Description
AddOrganism ( OrganismBase.OrganismState state ) : void

Should only be called by the GameEngine.

BuildIndex ( ) : void

Build the cell index.

ClearIndex ( ) : void

Clear the current cell index.

DuplicateMutable ( ) : object

Copies the object, but not the isImmutable bit. Makes a newly immutable copy.

FillCells ( OrganismBase.OrganismState state, int cellX, int cellY, int cellRadius, System.Boolean clear ) : void

Fills in the appropriate grid cells in our CellIndex given the organism state.

FindOrganisms ( int x1, int x2, int y1, int y2 ) : ArrayList

Find organisms with the given rectangular area.

FindOrganismsInCells ( int minGridX, int maxGridX, int minGridY, int maxGridY ) : ArrayList

Finds all organisms within a range of cells.

FindOrganismsInView ( OrganismBase.OrganismState state, int radius ) : ArrayList

Find a list of organisms within the view of the given organism.

GetAvailableLight ( OrganismBase.PlantState plant ) : int

Percentage of light reaching this plant. We assume the sun moves from east to west directly overhead We get a rough estimation like this: Get all plants with a certain radius whose radius blocks any East-West vector that intersects any part of the radius of the plant in question -- assume they block it completely Figure out which blocks it at the highest angle. Discount the amount of light the plant sees by angle / 180

GetOrganismState ( string organismID ) : OrganismBase.OrganismState

Retrieve the organism state from the world state for the given ID.

IsGridCellOccupied ( int cellX, int cellY ) : System.Boolean

Used to determine if a grid cell is occupied.

MakeImmutable ( ) : void

Makes all portions of the world state immutable including all organism state objects.

OnlyOverlapsSelf ( OrganismBase.OrganismState state ) : System.Boolean

Make sure the organism only overlaps itself and not other organisms.

RefreshOrganism ( OrganismBase.OrganismState state ) : void

Should only be called by the game engine. Should be called if the state of the organism changes.

RemoveOrganism ( string organismID ) : void

Should only be called by the game engine. Removes an organism from the world state.

WorldState ( int gridWidth, int gridHeight ) : System

Creates a new world state with the given number of grid cells.

Private Methods

Method Description
buildIndexInternal ( bool isDeserializing ) : void

Builds the cell index.

Method Details

AddOrganism() public method

Should only be called by the GameEngine.
public AddOrganism ( OrganismBase.OrganismState state ) : void
state OrganismBase.OrganismState The state of the organism to add.
return void

BuildIndex() public method

Build the cell index.
public BuildIndex ( ) : void
return void

ClearIndex() public method

Clear the current cell index.
public ClearIndex ( ) : void
return void

DuplicateMutable() public method

Copies the object, but not the isImmutable bit. Makes a newly immutable copy.
public DuplicateMutable ( ) : object
return object

FillCells() public method

Fills in the appropriate grid cells in our CellIndex given the organism state.
public FillCells ( OrganismBase.OrganismState state, int cellX, int cellY, int cellRadius, System.Boolean clear ) : void
state OrganismBase.OrganismState The state of the organism being added.
cellX int The location of the organism in cells.
cellY int The location of the organism in cells.
cellRadius int The radius in cells of the organism.
clear System.Boolean Determines if cells should be cleared or set.
return void

FindOrganisms() public method

Find organisms with the given rectangular area.
public FindOrganisms ( int x1, int x2, int y1, int y2 ) : ArrayList
x1 int Part of the location rectangle.
x2 int Part of the location rectangle.
y1 int Part of the location rectangle.
y2 int Part of the location rectangle.
return System.Collections.ArrayList

FindOrganismsInCells() public method

Finds all organisms within a range of cells.
public FindOrganismsInCells ( int minGridX, int maxGridX, int minGridY, int maxGridY ) : ArrayList
minGridX int Leftmost grid cell
maxGridX int Rightmost grid cell
minGridY int Topmost grid cell
maxGridY int Bottommost grid cell
return System.Collections.ArrayList

FindOrganismsInView() public method

Find a list of organisms within the view of the given organism.
public FindOrganismsInView ( OrganismBase.OrganismState state, int radius ) : ArrayList
state OrganismBase.OrganismState The state of the organism to check.
radius int The radius of vision.
return System.Collections.ArrayList

GetAvailableLight() public method

Percentage of light reaching this plant. We assume the sun moves from east to west directly overhead We get a rough estimation like this: Get all plants with a certain radius whose radius blocks any East-West vector that intersects any part of the radius of the plant in question -- assume they block it completely Figure out which blocks it at the highest angle. Discount the amount of light the plant sees by angle / 180
public GetAvailableLight ( OrganismBase.PlantState plant ) : int
plant OrganismBase.PlantState The plant to get light for.
return int

GetOrganismState() public method

Retrieve the organism state from the world state for the given ID.
public GetOrganismState ( string organismID ) : OrganismBase.OrganismState
organismID string The ID to match an organism state.
return OrganismBase.OrganismState

IsGridCellOccupied() public method

Used to determine if a grid cell is occupied.
public IsGridCellOccupied ( int cellX, int cellY ) : System.Boolean
cellX int The cell index.
cellY int The cell index.
return System.Boolean

MakeImmutable() public method

Makes all portions of the world state immutable including all organism state objects.
public MakeImmutable ( ) : void
return void

OnlyOverlapsSelf() public method

Make sure the organism only overlaps itself and not other organisms.
public OnlyOverlapsSelf ( OrganismBase.OrganismState state ) : System.Boolean
state OrganismBase.OrganismState The state of the organism to check.
return System.Boolean

RefreshOrganism() public method

Should only be called by the game engine. Should be called if the state of the organism changes.
public RefreshOrganism ( OrganismBase.OrganismState state ) : void
state OrganismBase.OrganismState The state of the organism to refresh.
return void

RemoveOrganism() public method

Should only be called by the game engine. Removes an organism from the world state.
public RemoveOrganism ( string organismID ) : void
organismID string The ID of the organism that needs to be removed.
return void

WorldState() public method

Creates a new world state with the given number of grid cells.
public WorldState ( int gridWidth, int gridHeight ) : System
gridWidth int The width of the world state in grid cells.
gridHeight int The height of the world state in grid cells.
return System