Convert setting cell in room generation method into cell transform
This commit is contained in:
parent
89902ccc03
commit
aa50054108
1 changed files with 18 additions and 18 deletions
|
@ -11,6 +11,12 @@ class Cell {
|
|||
upStair() { this.character = "<"; }
|
||||
downStair() { this.character = ">"; }
|
||||
cooridor() { this.character = "#"; }
|
||||
topLeftWall() { this.character = "┌"; }
|
||||
topRightWall() { this.character = "┐"; }
|
||||
bottomLeftWall() { this.character = "└"; }
|
||||
bottomRightWall() { this.character = "┘"; }
|
||||
horizontalWall() { this.character = "─"; }
|
||||
verticalWall() { this.character = "│"; }
|
||||
}
|
||||
|
||||
class Point {
|
||||
|
@ -114,13 +120,9 @@ class Grid {
|
|||
for (let room of this.#rooms) {
|
||||
for (let y = room.minY; y <= room.maxY; y++) {
|
||||
for (let x = room.minX; x <= room.maxX; x++) {
|
||||
let charAtXY = room.charAt(x, y);
|
||||
if (!charAtXY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let point = new Point(x, y);
|
||||
let cell = this.cellAt(x, y);
|
||||
cell.character = charAtXY;
|
||||
room.transformCellAt(point, cell);
|
||||
cell.characterColor = p.color(255);
|
||||
}
|
||||
}
|
||||
|
@ -169,24 +171,22 @@ class Room {
|
|||
);
|
||||
}
|
||||
|
||||
charAt(x, y) {
|
||||
transformCellAt(pt, cell) {
|
||||
const minX = this.minX;
|
||||
const minY = this.minY;
|
||||
const maxX = this.maxX;
|
||||
const maxY = this.maxY;
|
||||
|
||||
if (y == minY && x == minX) { return "┌"; }
|
||||
if (y == minY && x == maxX) { return "┐"; }
|
||||
if (y == maxY && x == minX) { return "└"; }
|
||||
if (y == maxY && x == maxX) { return "┘"; }
|
||||
if (y == minY || y == maxY) { return "─"; }
|
||||
if (x == minX || x == maxX) { return "│"; }
|
||||
const x = pt.x;
|
||||
const y = pt.y;
|
||||
|
||||
if ((x > minX && x < maxX) && (y > minY && y < maxY)) {
|
||||
return ".";
|
||||
}
|
||||
|
||||
return undefined;
|
||||
if (y === minY && x === minX) { cell.topLeftWall(); }
|
||||
else if (y === minY && x === maxX) { cell.topRightWall(); }
|
||||
else if (y === maxY && x === minX) { cell.bottomLeftWall(); }
|
||||
else if (y === maxY && x === maxX) { cell.bottomRightWall(); }
|
||||
else if (y === minY || y === maxY) { cell.horizontalWall(); }
|
||||
else if (x === minX || x === maxX) { cell.verticalWall(); }
|
||||
else if ((x > minX && x < maxX) && (y > minY && y < maxY)) { return cell.floor(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue