54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
package ch.fritteli.maze.generator.renderer.html;
|
|
|
|
import ch.fritteli.maze.generator.model.Direction;
|
|
import ch.fritteli.maze.generator.model.Maze;
|
|
import ch.fritteli.maze.generator.model.Tile;
|
|
import io.vavr.collection.HashSet;
|
|
import io.vavr.collection.Set;
|
|
import lombok.AccessLevel;
|
|
import lombok.NonNull;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
|
class Generator {
|
|
private final Maze maze;
|
|
private int y = 0;
|
|
|
|
boolean hasNext() {
|
|
return this.y < this.maze.getHeight();
|
|
}
|
|
|
|
String next() {
|
|
StringBuilder sb = new StringBuilder("<tr>");
|
|
for (int x = 0; x < this.maze.getWidth(); x++) {
|
|
final Tile currentTile = this.maze.getTileAt(x, this.y).get();
|
|
sb.append("<td class=\"");
|
|
sb.append(this.getClasses(currentTile).mkString(" "));
|
|
sb.append("\"> </td>");
|
|
}
|
|
sb.append("</tr>");
|
|
this.y++;
|
|
return sb.toString();
|
|
}
|
|
|
|
private Set<String> getClasses(@NonNull final Tile tile) {
|
|
Set<String> result = HashSet.empty();
|
|
if (tile.hasWallAt(Direction.TOP)) {
|
|
result = result.add("top");
|
|
}
|
|
if (tile.hasWallAt(Direction.RIGHT)) {
|
|
result = result.add("right");
|
|
}
|
|
if (tile.hasWallAt(Direction.BOTTOM)) {
|
|
result = result.add("bottom");
|
|
}
|
|
if (tile.hasWallAt(Direction.LEFT)) {
|
|
result = result.add("left");
|
|
}
|
|
if (tile.isSolution()) {
|
|
result = result.add("solution");
|
|
}
|
|
return result;
|
|
}
|
|
}
|