GetNeighbours
This method allows you to find and retrieve the neighbors of a particular Ball
in your game. You can specify both the type of Ball
you are interested in and a condition to further filter these neighbouring balls.
Syntax:
Parameters:
T
: The type of theBall
that you want to find among the neighbours. This could be any class that derives from theBall
base class (likeColorBall
for instance).ball
: TheBall
whose neighbours you want to find.filter
: AFunc<T, bool>
that represents the condition to further filter the neighbours. This is a function that takes aBall
of typeT
and returns a boolean. If the function returnstrue
for a specificBall
, then thatBall
will be included in the returned array of neighbours.
Example:
In this example, GetNeighbours
is called to find all neighboring ColorBall
s of someBall
that have the same color as targetColor
. The method returns an array of these ColorBall
s.
Here, ball => ball.GetColor() == targetColor
is a lambda expression that represents the filter
function. It checks if the color of a ColorBall
is the same as targetColor
.
This method is powerful because it allows you to customize the condition for filtering neighbours, resulting in more flexibility when designing game mechanics. For example, you could easily find all ColorBall
s of a certain color, or BombBall
s that are about to explode, etc.
Last updated