- 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 class
TheIllegalCharAddition
class is a specific type ofIllegalArgumentException
that is thrown when an invalid character is added to a cell. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClickListener
(javafx.beans.value.ChangeListener<? super Boolean> listener) Adds a listener that will be notified whenever the value of the `clickCount` property changes.void
addContentListener
(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.void
addStateListener
(javafx.beans.value.ChangeListener<? super Boolean> listener) Adds a listener to the `isActiveProperty` to monitor changes in its value.boolean
addToCluster
(CellCluster cluster) Adds thisCell
to the specifiedCellCluster
.void
click()
Handles the internal behaviour triggered by a click on this cell.char
Retrieves the content (a character) contained within thisCell
.Retrieves the primary cluster that thisCell
is associated with.boolean
Checks if the cell is part of an active cluster.boolean
Checks if the cell is part of a cluster.boolean
isActive()
Checks if the cell is currently active.boolean
Determines whether the content of thisCell
matches the content of the specifiedCell
.boolean
removeCluster
(CellCluster cluster) Removes thisCell
from the specifiedCellCluster
.void
setActive
(boolean newState) Changes the state of the cell.void
setContent
(char content) Sets the content (a character) of thisCell
.boolean
sharesClusterWith
(Cell cell) Determines whether thisCell
shares 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,true
for active,false
for inactive.
-
addToCluster
Adds thisCell
to the specifiedCellCluster
.- Parameters:
cluster
- theCellCluster
to which thisCell
will be added.- Returns:
true
if the cell was successfully added to the cluster.
-
removeCluster
Removes thisCell
from the specifiedCellCluster
.- Parameters:
cluster
- theCellCluster
to which thisCell
will be removed.- Returns:
true
if the cluster was successfully removed.
-
getMainCluster
CellCluster getMainCluster()Retrieves the primary cluster that thisCell
is associated with. The determination of the main cluster is contingent upon the type and internal content of theCell
.For
LetterCell
instances, which can only be part of a single cluster, this method will always return that cluster.In contrast,
SymbolCell
instances may belong to multiple clusters. This method will return the main cluster only if theSymbolCell
is the first element in that cluster. If theSymbolCell
is part of one or more clusters but not as the first element, this method will returnnull
.- Returns:
- The primary cluster associated with this
Cell
, ornull
if 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:
true
if the cell is active,false
otherwise.
-
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 ofChangeListener
that 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
- theChangeListener
to be added; it will be triggered with aCharacter
when 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:
true
if the cell is part of an active cluster,false
otherwise.
-
inCluster
boolean inCluster()Checks if the cell is part of a cluster.- Returns:
true
if the cell is part of a cluster,false
otherwise.
-
matches
Determines whether the content of thisCell
matches the content of the specifiedCell
.This method compares the content of the two
Cell
instances. If theCell
s 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
- TheCell
whose content is to be compared with thisCell
.- Returns:
true
if the content of the twoCell
s matches and they belong to the same subclass;false
otherwise.
-
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.
-