|
| 1 | +import React, {Component, useState, useRef} from 'react'; |
| 2 | +import Board from '../BoardCanvas/Board'; |
| 3 | +import Navigation from '../Page/partial/Navbar/Navigation'; |
| 4 | +import './display.css'; |
| 5 | +import {useBinaryTreeCreation} from './Maze/Generation/BinaryTreeCreation'; |
| 6 | +import {Strategy} from '../Strategy/Strategy'; |
| 7 | + |
| 8 | +/* |
| 9 | +
|
| 10 | + This is the main display of the game/visual demonstration. |
| 11 | + It contains the board, board control interface, orbital(camera)/Input interface, |
| 12 | + the game control interface, and the navigation bar. |
| 13 | +
|
| 14 | + "The Mediator" |
| 15 | + or a psudo |
| 16 | + "Layers Pattern" |
| 17 | +
|
| 18 | + */ |
| 19 | +export default function Display() { |
| 20 | + const [layoutType, setLayout] = useState('standard'); |
| 21 | + const [mazeType, setMazeType] = useState("_none_"); |
| 22 | + const [selectedPoint, setSelectedPoint] = useState(null); |
| 23 | + const [selectedGoalPoint, setSelectedGoalPoint] = useState(null); |
| 24 | + const [selectedStartPoint, setSelectedStartPoint] = useState(null); |
| 25 | + // const board = new Array(10000).fill(0).map( |
| 26 | + const board = new Array(3844).fill(0).map( |
| 27 | + // (i, id, type: string = '_floor_', visited: Boolean = false, x: Number, y: Number ) => ({id, type, visited})); |
| 28 | + // (i, id, type: string = '_floor_', visited: Boolean = false, x: Number, y: Number ) => ({x, y} ({id, type, visited}))); |
| 29 | + (i, id: number, type: String = '_wall_', sourceType: String = '_wall_', targetType: String = '_wall_', visited: Boolean = false, x: number, y: number ) => ({x, y, id, type, visited, sourceType, targetType})); |
| 30 | + |
| 31 | + const boardRef = useRef(); // Mutable(Persistant) board reference object. |
| 32 | + |
| 33 | + const handleResetCamera = () => { |
| 34 | + boardRef.current.resetCamera(); |
| 35 | + }; |
| 36 | + const handleResetBoard = () => { |
| 37 | + boardRef.current.resetBoard(); |
| 38 | + }; |
| 39 | + const handleMazeGeneration = (Strategy) => { |
| 40 | + boardRef.current.generateMaze(Strategy); |
| 41 | + }; |
| 42 | + |
| 43 | + |
| 44 | + return ( |
| 45 | + <> |
| 46 | + <Navigation/> |
| 47 | + <div className = "display-container"> |
| 48 | + |
| 49 | + <Board |
| 50 | + ref = {boardRef} |
| 51 | + board = {board} |
| 52 | + layoutType = {layoutType} |
| 53 | + mazeType = {mazeType} |
| 54 | + selectedPoint = {selectedPoint} |
| 55 | + onSelectPoint = {setSelectedPoint} |
| 56 | + /> |
| 57 | + <div className = "point-desc"> |
| 58 | + {selectedPoint && ( |
| 59 | + <p>Cell: |
| 60 | + #<span className = "point-select">{selectedPoint.id}</span> |
| 61 | + </p> |
| 62 | + )} |
| 63 | + </div> |
| 64 | + |
| 65 | + <div className = "control-group-one"> |
| 66 | + <h2 className = "control-header">Display <br/> Strategy</h2> |
| 67 | + <button |
| 68 | + onClick = {() => setLayout('standard')} |
| 69 | + className = {layoutType === 'standard' ? 'active' : undefined} |
| 70 | + > |
| 71 | + Standard Grid |
| 72 | + </button> |
| 73 | + {/* <button */} |
| 74 | + {/* onClick = {() => setLayout('circular')} */} |
| 75 | + {/* className = {layoutType === 'circular' ? 'active' : undefined} */} |
| 76 | + {/* > */} |
| 77 | + {/* Circular */} |
| 78 | + {/* </button> */} |
| 79 | + |
| 80 | + <button className = "reset-button" onClick = {handleResetCamera}> |
| 81 | + View Reset |
| 82 | + </button> |
| 83 | + </div> |
| 84 | + |
| 85 | + <div className = "control-group-two"> |
| 86 | + <h2 className = "control-header">Generate Maze</h2> |
| 87 | + <div className = "maze-toggle-group" > |
| 88 | + <button |
| 89 | + onClick = {() => { |
| 90 | + if (mazeType === '_none_') { |
| 91 | + setMazeType('_BinaryTree_'); |
| 92 | + } |
| 93 | + }} |
| 94 | + className = {`maze-toggle ${mazeType !== '_none_' ? 'active' : undefined}`} |
| 95 | + > |
| 96 | + ON |
| 97 | + </button> |
| 98 | + |
| 99 | + <button |
| 100 | + onClick = {() => setMazeType('_none_')} |
| 101 | + className = {`maze-toggle ${mazeType === '_none_' ? 'active' : undefined}`} |
| 102 | + > |
| 103 | + OFF |
| 104 | + </button> |
| 105 | + |
| 106 | + </div> |
| 107 | + <button |
| 108 | + onClick = {() => setMazeType('_BinaryTree_')} |
| 109 | + className = {mazeType === '_BinaryTree_' ? 'active' : undefined} |
| 110 | + > |
| 111 | + Binary Tree |
| 112 | + </button> |
| 113 | + <button |
| 114 | + onClick = {() => setMazeType('_GrowingTree_')} |
| 115 | + className = {mazeType === '_GrowingTree_' ? 'active' : undefined} |
| 116 | + > |
| 117 | + Growing Tree |
| 118 | + </button> |
| 119 | + <button |
| 120 | + onClick = {() => setMazeType('_BFS_')} |
| 121 | + className = {mazeType === '_BFS_' ? 'active' : undefined} |
| 122 | + > |
| 123 | + Breath First Search |
| 124 | + </button> |
| 125 | + <button className = "reset-button" onClick = {handleResetBoard}> |
| 126 | + Board Reset |
| 127 | + </button> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + </> |
| 131 | + ); |
| 132 | +} |
0 commit comments