Implemented a half-way okay-ish user interaction pattern: mouse drag.

This commit is contained in:
Manuel Friedli 2023-04-17 01:19:42 +02:00
parent 0e5892147a
commit 8f64a65a2a
9 changed files with 233 additions and 72 deletions

View file

@ -1,16 +1,20 @@
import React from 'react';
import Row from "./Row";
import Cell from "./Cell";
export default function Maze({labyrinth, showSolution = false}) {
if (!labyrinth.grid) {
export default function Maze({state, dispatch}) {
if (!state.maze) {
return <div>No valid maze.</div>
}
const maze = labyrinth.grid.map((row, rowIdx) => <Row key={rowIdx}
spec={row}
index={rowIdx}
showSolution={showSolution}/>);
let maze = [];
for (let y = 0; y < state.maze.height; y++) {
let row = [];
for (let x = 0; x < state.maze.width; x++) {
row.push(<Cell key={`${x}x${y}`} x={x} y={y} state={state} dispatch={dispatch}/>)
}
maze.push(<div key={`r${y}`} className={"row"}>{row}</div>);
}
return (
<div className={"maze"}>
{maze}