Skip to content

Commit

Permalink
game kinda works ish
Browse files Browse the repository at this point in the history
  • Loading branch information
ixk3065 committed Apr 30, 2024
1 parent 338ddf4 commit 79cf187
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 79cf187

Please sign in to comment.