From aa50054108e21f75acdc04e64754105cfaccd2b5 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 3 Feb 2023 18:12:07 -0800 Subject: [PATCH] Convert setting cell in room generation method into cell transform --- assets/scripts/nethack/dungeon.js | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/assets/scripts/nethack/dungeon.js b/assets/scripts/nethack/dungeon.js index 4638317..cc8e148 100644 --- a/assets/scripts/nethack/dungeon.js +++ b/assets/scripts/nethack/dungeon.js @@ -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(); } } }