From 1225f8da24fac9cefd55a1b020b4ca8956cbcec3 Mon Sep 17 00:00:00 2001 From: Reimar Date: Fri, 16 Aug 2024 23:45:52 +0200 Subject: [PATCH] wip --- minesweeper.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/minesweeper.js b/minesweeper.js index dace0d2..a76e568 100644 --- a/minesweeper.js +++ b/minesweeper.js @@ -164,15 +164,35 @@ window.addEventListener("mousedown", event => { draw(); }); +function columnContainsOnlyUnrevealed(column) { + return column.every(cell => !cell.isRevealed); +} + window.addEventListener("wheel", event => { + let deltaX = 0, deltaY = 0; + if (event.shiftKey) { - scrollX += event.deltaY; + deltaX = event.deltaY; } else { - scrollX += event.deltaX; - scrollY += event.deltaY; + deltaX = event.deltaX; + deltaY = event.deltaY; } - // TODO create new rows/columns on scroll + console.log(scrollY + deltaY + window.innerHeight, board.length * CELL_SIZE); + if (scrollY + deltaY + window.innerHeight > board.length * CELL_SIZE) { + if (board.slice(-20).every(columnContainsOnlyUnrevealed)) { + console.log("ignoring"); + return; + } + + const diff = scrollY + window.innerHeight - board.length * CELL_SIZE; + + for (let i = 0; i < diff + CELL_SIZE; i += CELL_SIZE) + createRowAtBottom(); + } + + scrollX += deltaX; + scrollY += deltaY; draw(); });