Package application.model.simulation
Class Block
java.lang.Object
application.model.simulation.Block
- All Implemented Interfaces:
java.lang.Cloneable
public class Block
extends java.lang.Object
implements java.lang.Cloneable
Represents a block of cells
-
Constructor Summary
Constructors Constructor Description Block(Coordinate startingCoordinate, int width, int height)Constructs a block with a specific width and height -
Method Summary
Modifier and Type Method Description java.lang.Objectclone()intgetCell(int x, int y)Gets the state of the cell at coordinate (x, y)intgetPopulation()Gets the population of alive cells (> state 0) in the blockCoordinategetStartCoordinate()Gets the starting coordinate of the block (top-left)BlockStategetState()Gets the state of the blockinthashCode()booleaninBlock(Coordinate coordinate)Checks if the coordinate is within the current blockvoidsetCell(int x, int y, int state)Sets the value of a cell in the blockvoidsetState(BlockState state)Sets the state of the block
-
Constructor Details
-
Block
Constructs a block with a specific width and height- Parameters:
startingCoordinate- The coordinate of the block (top-left)width- Width of the blockheight- Height of the block
-
-
Method Details
-
setCell
public void setCell(int x, int y, int state)Sets the value of a cell in the block- Parameters:
x- The x-coordinate of the celly- The y-coordinate of the cellstate- The state of the cell
-
getCell
public int getCell(int x, int y)Gets the state of the cell at coordinate (x, y)- Parameters:
x- The x-coordinate of the cell to gety- The y-coordinate of the cell to get- Returns:
- Returns the state of the cell at (x, y)
-
getStartCoordinate
Gets the starting coordinate of the block (top-left)- Returns:
- Returns the starting coordinate of the block
-
inBlock
Checks if the coordinate is within the current block- Parameters:
coordinate- The coordinate to check- Returns:
- Returns true if the coordinate is within the block, false otherwise
-
getPopulation
public int getPopulation()Gets the population of alive cells (> state 0) in the block- Returns:
- Returns the population of the block
-
getState
Gets the state of the block- Returns:
- Returns the state of the block
-
setState
Sets the state of the block- Parameters:
state- The state of the block
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
clone
public java.lang.Object clone()- Overrides:
clonein classjava.lang.Object
-