- All Known Implementing Classes:
LetterCell,SymbolCell
Cell
serves as the smallest element that a player can interact with during
gameplay.
This interface outlines the expected behaviour of a Cell within the
context of the program, allowing it to:
- Contain a letter, symbol, or other character.
- Be associated with a group, cluster, or exist in isolation.
Implementing classes should ensure that these behaviours are appropriately defined and adhere to the game's logic and interactive design principles.
- Since:
- 2024-08-12
- Version:
- 3.0
- Author:
- Kheagen Haskins
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classTheIllegalCharAdditionclass is a specific type ofIllegalArgumentExceptionthat is thrown when an invalid character is added to a cell. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClickListener(javafx.beans.value.ChangeListener<? super Boolean> listener) Adds a listener that will be notified whenever the value of the `clickCount` property changes.voidaddContentListener(javafx.beans.value.ChangeListener<? super Character> listener) Registers a listener that will be notified when the content of the cell changes, such as when it is filled or modified.voidaddStateListener(javafx.beans.value.ChangeListener<? super Boolean> listener) Adds a listener to the `isActiveProperty` to monitor changes in its value.booleanaddToCluster(CellCluster cluster) Adds thisCellto the specifiedCellCluster.voidclick()Handles the internal behaviour triggered by a click on this cell.charRetrieves the content (a character) contained within thisCell.Retrieves the primary cluster that thisCellis associated with.booleanChecks if the cell is part of an active cluster.booleanChecks if the cell is part of a cluster.booleanisActive()Checks if the cell is currently active.booleanDetermines whether the content of thisCellmatches the content of the specifiedCell.booleanremoveCluster(CellCluster cluster) Removes thisCellfrom the specifiedCellCluster.voidsetActive(boolean newState) Changes the state of the cell.voidsetContent(char content) Sets the content (a character) of thisCell.booleansharesClusterWith(Cell cell) Determines whether thisCellshares the same cluster with another specifiedCell.
-
Method Details
-
getContent
char getContent()Retrieves the content (a character) contained within thisCell.- Returns:
- the character content of this
Cell.
-
setContent
void setContent(char content) Sets the content (a character) of thisCell.- Parameters:
content- the character to be set as the content of thisCell.
-
setActive
void setActive(boolean newState) Changes the state of the cell. This changes the visual properties of the Cell.- Parameters:
newState- the new state of the cell,truefor active,falsefor inactive.
-
addToCluster
Adds thisCellto the specifiedCellCluster.- Parameters:
cluster- theCellClusterto which thisCellwill be added.- Returns:
trueif the cell was successfully added to the cluster.
-
removeCluster
Removes thisCellfrom the specifiedCellCluster.- Parameters:
cluster- theCellClusterto which thisCellwill be removed.- Returns:
trueif the cluster was successfully removed.
-
getMainCluster
CellCluster getMainCluster()Retrieves the primary cluster that thisCellis associated with. The determination of the main cluster is contingent upon the type and internal content of theCell.For
LetterCellinstances, which can only be part of a single cluster, this method will always return that cluster.In contrast,
SymbolCellinstances may belong to multiple clusters. This method will return the main cluster only if theSymbolCellis the first element in that cluster. If theSymbolCellis part of one or more clusters but not as the first element, this method will returnnull.- Returns:
- The primary cluster associated with this
Cell, ornullif no such cluster exists.
-
isActive
boolean isActive()Checks if the cell is currently active. In the context of the game, an active cell is one that the mouse is currently hovered over, highlighting it for potential interaction.- Returns:
trueif the cell is active,falseotherwise.
-
addStateListener
Adds a listener to the `isActiveProperty` to monitor changes in its value. The listener will be notified whenever the value of the `isActiveProperty` changes.- Parameters:
listener- the listener to add; it must be an implementation ofChangeListenerthat can handle the value of typeBoolean.
-
addContentListener
Registers a listener that will be notified when the content of the cell changes, such as when it is filled or modified. The listener will receive a notification whenever the character content within the cell is altered.- Parameters:
listener- theChangeListenerto be added; it will be triggered with aCharacterwhen the cell's content changes
-
addClickListener
Adds a listener that will be notified whenever the value of the `clickCount` property changes.- Parameters:
listener- the listener to be added, which should implement theChangeListener<? super Boolean>interface. This listener will be notified with the new value whenever the `clickCount` changes.
-
inActiveCluster
boolean inActiveCluster()Checks if the cell is part of an active cluster. Active clusters might have special behaviour or visual indications in the game.- Returns:
trueif the cell is part of an active cluster,falseotherwise.
-
inCluster
boolean inCluster()Checks if the cell is part of a cluster.- Returns:
trueif the cell is part of a cluster,falseotherwise.
-
matches
Determines whether the content of thisCellmatches the content of the specifiedCell.This method compares the content of the two
Cellinstances. If theCells belong to different subclasses, this method will automatically returnfalse, ensuring that only cells of the same type are considered comparable.For most subclasses, including
LetterCell, this method checks if the content of both cells is identical. However, for more specialised subclasses likeSymbolCell, the implementation may involve more nuanced rules, such as determining whether certain types of symbols are considered equivalent, even if their content differs.- Parameters:
cell- TheCellwhose content is to be compared with thisCell.- Returns:
trueif the content of the twoCells matches and they belong to the same subclass;falseotherwise.
-
click
void click()Handles the internal behaviour triggered by a click on this cell. This typically involves delegating the click to any main cluster. The exact behavior may vary depending on the implementation specifics.
-