2023-04-17 01:19:42 +02:00
|
|
|
import React from 'react';
|
2023-04-14 02:01:55 +02:00
|
|
|
|
2023-04-17 01:19:42 +02:00
|
|
|
function isMarked(x, y, marked) {
|
|
|
|
return !!marked.find(e => e.x === x && e.y === y);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Cell({x, y, state, dispatch}) {
|
|
|
|
const cell = state.maze.grid[y][x];
|
|
|
|
let classes = "cell r" + y + " c" + x;
|
|
|
|
if (cell.top) classes += " top";
|
|
|
|
if (cell.right) classes += " right";
|
|
|
|
if (cell.bottom) classes += " bottom";
|
|
|
|
if (cell.left) classes += " left";
|
|
|
|
if (cell.solution && state.showSolution) classes += " solution";
|
|
|
|
const marked = isMarked(x, y, state.userPath);
|
|
|
|
if (marked) classes += " user";
|
2023-04-14 02:01:55 +02:00
|
|
|
return (
|
2023-04-16 02:36:27 +02:00
|
|
|
<div className={classes}
|
|
|
|
onMouseEnter={(e) => {
|
|
|
|
const leftPressed = e.buttons & 0x1;
|
|
|
|
if (leftPressed) {
|
2023-04-17 01:19:42 +02:00
|
|
|
dispatch({
|
|
|
|
type: 'clicked_cell',
|
|
|
|
x,
|
2023-04-17 01:24:28 +02:00
|
|
|
y
|
2023-04-17 01:19:42 +02:00
|
|
|
});
|
2023-04-16 02:36:27 +02:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
onClick={(e) => {
|
2023-04-17 01:19:42 +02:00
|
|
|
dispatch({
|
|
|
|
type: 'clicked_cell',
|
|
|
|
x,
|
2023-04-17 01:24:28 +02:00
|
|
|
y
|
2023-04-17 01:19:42 +02:00
|
|
|
});
|
|
|
|
}}>
|
|
|
|
</div>
|
2023-04-14 02:01:55 +02:00
|
|
|
);
|
|
|
|
}
|