tiles now have lake or ocean method

This commit is contained in:
evanpelle
2024-08-23 17:53:55 -07:00
parent f52b62a354
commit 41d7c77d2d
14 changed files with 89 additions and 70 deletions
+4 -20
View File
@@ -3,7 +3,7 @@ import {Cell, Game, PlayerEvent, Tile, TileEvent, Player, Execution, BoatEvent}
import {Theme} from "../../core/configuration/Config";
import {DragEvent, ZoomEvent} from "../InputHandler";
import {NameRenderer} from "./NameRenderer";
import {manhattanDist} from "../../core/Util";
import {bfs, manhattanDist} from "../../core/Util";
import {PseudoRandom} from "../../core/PseudoRandom";
@@ -146,30 +146,14 @@ export class GameRenderer {
}
boatEvent(event: BoatEvent) {
this.bfs(event.oldTile, 2).forEach(t => this.paintTerritory(t))
bfs(event.oldTile, 2).forEach(t => this.paintTerritory(t))
if (event.boat.isActive()) {
this.bfs(event.boat.tile(), 2).forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.boat.owner().id())))
this.bfs(event.boat.tile(), 1).forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.boat.owner().id())))
bfs(event.boat.tile(), 2).forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.boat.owner().id())))
bfs(event.boat.tile(), 1).forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.boat.owner().id())))
}
}
private bfs(tile: Tile, dist: number): Set<Tile> {
const seen = new Set<Tile>
const q: Tile[] = []
q.push(tile)
while (q.length > 0) {
const curr = q.pop()
seen.add(curr)
for (const n of curr.neighbors()) {
if (!seen.has(n) && manhattanDist(tile.cell(), n.cell()) <= dist) {
q.push(n)
}
}
}
return seen
}
resize(width: number, height: number): void {
this.canvas.width = Math.ceil(width / window.devicePixelRatio);
this.canvas.height = Math.ceil(height / window.devicePixelRatio);
+1 -1
View File
@@ -74,7 +74,7 @@ export function createGrid(game: Game, player: Player, boundingBox: {min: Point;
const cell = new Cell(x * scalingFactor, y * scalingFactor);
if (game.isOnMap(cell)) {
const tile = game.tile(cell);
grid[x - scaledBoundingBox.min.x][y - scaledBoundingBox.min.y] = tile.owner() === player; // TODO: okay if lake
grid[x - scaledBoundingBox.min.x][y - scaledBoundingBox.min.y] = tile.isLake() || tile.owner() === player; // TODO: okay if lake
}
}
}