C - The cell typepublic final class CellSight<C extends BattlefieldCell> extends Object
| Constructor and Description |
|---|
CellSight(BattlefieldSight<C> battlefield,
CoordinateCell<C> source) |
CellSight(CoordinateCell<C> source) |
| Modifier and Type | Method and Description |
|---|---|
Collection<C> |
accessible() |
Collection<C> |
blocked() |
void |
forEach(BiConsumer<C,Boolean> cellViewConsumer)
Iterate over all map cells, and check for each cells is the line of sight is free
final CellSight<FightCell> sight = fighter.cell().sight();
final CoordinateCell<FightCell> to = new CoordinateCell<>(target.cell());
sight.forEach((cell, free) -> {
if (free) {
performActionOnAccessibleCell(cell);
}
});
|
boolean |
isFree(C target)
Check if the line of sight is free towards the target
Usage:
{@code
final CellSight
|
boolean |
isFree(CoordinateCell<C> target)
Check if the line of sight is free towards the target
Usage:
{@code
final CellSight
|
Iterator<C> |
to(C target)
Iterator of cells between current one and the target
Note: the current cell is excluded from the iterator, but not the target.
|
Iterator<C> |
to(CoordinateCell<C> target)
Iterator of cells between current one and the target
Note: the current cell is excluded from the iterator, but not the target.
|
public CellSight(BattlefieldSight<C> battlefield, CoordinateCell<C> source)
public CellSight(CoordinateCell<C> source)
public boolean isFree(CoordinateCell<C> target)
final CellSight<FightCell> sight = fighter.cell().sight();
if (!sight.isFree(target.cell().coordinate())) {
throw new Exception("Target is no reachable");
}
target - The target cellpublic boolean isFree(C target)
final CellSight<FightCell> sight = fighter.cell().sight();
if (!sight.isFree(target.cell())) {
throw new Exception("Target is no reachable");
}
target - The target cellpublic Iterator<C> to(C target)
// Iterate over all cells between fighter.cell() and target.cell()
fighter.cell().sight().to(target.cell()).forEachRemaining(cell -> {
// cell is on the line of sight
});
target - The target cellpublic Iterator<C> to(CoordinateCell<C> target)
// Iterate over all cells between fighter.cell() and target.cell()
fighter.cell().sight().to(target.cell()).forEachRemaining(cell -> {
// cell is on the line of sight
});
target - The target cellpublic void forEach(BiConsumer<C,Boolean> cellViewConsumer)
final CellSight<FightCell> sight = fighter.cell().sight();
final CoordinateCell<FightCell> to = new CoordinateCell<>(target.cell());
sight.forEach((cell, free) -> {
if (free) {
performActionOnAccessibleCell(cell);
}
});
cellViewConsumer - The cell consumer. Takes as first parameter the cell and at second the sight status (true if free)For dump accessible cells,
For dump blocked cellspublic Collection<C> accessible()
public Collection<C> blocked()
Copyright © 2022. All rights reserved.