From 79cf187272ecd44b141cde1f265552d06edcbf46 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 30 Apr 2024 15:07:09 -0500 Subject: [PATCH] game kinda works ish --- html/main.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/html/main.js b/html/main.js index 54ed08f..106d44c 100644 --- a/html/main.js +++ b/html/main.js @@ -281,14 +281,45 @@ function highlightPath(start, end, color) { } } -function highlightCell(row, col) { + function highlightCell(row, col, color) { + const cellId = `cell-${row}-${col}`; + const cell = document.getElementById(cellId); - // Highlight the new cell for HINT + if (cell) { + // Check if the cell is already highlighted with the same player's color + const isHighlighted = cell.classList.contains('highlighted'); + const isSameColor = cell.dataset.playerColor === color; + + if (isHighlighted && isSameColor) { + // If the cell is already highlighted with the same player's color, remove the highlight + removeHighlightCell(row, col); + } else { + // If the cell is not already highlighted with the same player's color, + // highlight it with light green + cell.style.backgroundColor = "lightgreen"; + cell.classList.add('highlighted'); + + // Store the player's color + cell.dataset.playerColor = color; + } + } else { + console.error('Cell not found:', cellId); + } +} + +function removeHighlightCell(row, col) { const cellId = `cell-${row}-${col}`; const cell = document.getElementById(cellId); + if (cell) { - cell.style.backgroundColor = "lightgreen"; - cell.classList.add('highlighted'); + // Remove the light green highlight + cell.classList.remove('highlighted'); + + // Restore the player's color + if (cell.dataset.playerColor) { + cell.style.backgroundColor = cell.dataset.playerColor; + delete cell.dataset.playerColor; + } } else { console.error('Cell not found:', cellId); }