Skip to content

Commit a1d8f7f

Browse files
committed
component displaying current state of finding path process
1 parent 546e779 commit a1d8f7f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Grid.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ROWS, COLS, CELL, START, END, VISITED } from './const';
2+
import "./grid.css"
3+
function Grid({grid}) {
4+
const cells = [];
5+
for(let row = 0; row < ROWS; row++){
6+
for(let col = 0; col < COLS; col++){
7+
const value = grid[COLS * row + col]
8+
const className = value === START ?
9+
'cell start-cell' : value === END ?
10+
'cell end-cell' : value === VISITED ?
11+
'cell visited-cell' : 'cell'
12+
cells.push(<div className={className}></div>)
13+
}
14+
}
15+
return (
16+
<div style={{width: COLS * CELL, height: ROWS * CELL }} className="grid">
17+
{cells}
18+
</div>
19+
);
20+
}
21+
22+
export default Grid;

0 commit comments

Comments
 (0)