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.Object clone()  
    int getCell​(int x, int y)
    Gets the state of the cell at coordinate (x, y)
    int getPopulation()
    Gets the population of alive cells (> state 0) in the block
    Coordinate getStartCoordinate()
    Gets the starting coordinate of the block (top-left)
    BlockState getState()
    Gets the state of the block
    int hashCode()  
    boolean inBlock​(Coordinate coordinate)
    Checks if the coordinate is within the current block
    void setCell​(int x, int y, int state)
    Sets the value of a cell in the block
    void setState​(BlockState state)
    Sets the state of the block

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Block

      public Block​(Coordinate startingCoordinate, int width, int height)
      Constructs a block with a specific width and height
      Parameters:
      startingCoordinate - The coordinate of the block (top-left)
      width - Width of the block
      height - 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 cell
      y - The y-coordinate of the cell
      state - 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 get
      y - The y-coordinate of the cell to get
      Returns:
      Returns the state of the cell at (x, y)
    • getStartCoordinate

      public Coordinate getStartCoordinate()
      Gets the starting coordinate of the block (top-left)
      Returns:
      Returns the starting coordinate of the block
    • inBlock

      public boolean inBlock​(Coordinate coordinate)
      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

      public BlockState getState()
      Gets the state of the block
      Returns:
      Returns the state of the block
    • setState

      public void setState​(BlockState state)
      Sets the state of the block
      Parameters:
      state - The state of the block
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class java.lang.Object