Skip to content

Commit

Permalink
Merge pull request #11 from Ba6ySHark/Ba6ySHark-patch-10.1
Browse files Browse the repository at this point in the history
Patch 10.1
  • Loading branch information
Ba6ySHark authored Sep 23, 2023
2 parents fb45609 + 3ed74f8 commit 51d8d7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React from "react";

import {createNode, PAVnode} from "./components/PAVnode.js";
import PAVcanvas from "./components/PAVcanvas.js";
import NavBar from "./components/NavBar.js";

import dijkstraAlgorithm from "./algorithms/dijkstra.js";
import astarAlgorithm from "./algorithms/astar.js";
import bfsAlgorithm from "./algorithms/bfs.js";
import dfsAlgorithm from "./algorithms/dfs.js";

import createRandomMaze from "./mazes/random.js";

export default function App() {
let [featured_algorithm, setFeaturedAlgorithm] = React.useState("Dijkstra");
let [animationSpeed, setAnimationSpeed] = React.useState(25); // in ms (fast by default)
let [mazeType, setMazeType] = React.useState("random"); // set to random by default

const rows = (window.innerHeight / 20) / (1.5);
const columns = ((window.screen.width - 150) / 20);
Expand Down Expand Up @@ -144,7 +149,11 @@ export default function App() {
function selectAlgorithm(value) {
setFeaturedAlgorithm(value);
console.log(featured_algorithm);
};
}

function selectMazeType(value) {
setMazeType(value);
}

function selectAnimationSpeed(value) {
if (value === "fast") {
Expand Down Expand Up @@ -199,6 +208,7 @@ export default function App() {
<div className="App">
<NavBar
selectAlgorithm={selectAlgorithm}
selectMazeType={selectMazeType}
selectAnimationSpeed={selectAnimationSpeed}
currentAnimationSpeed={animationSpeed}
visualizeSelectedAlgorithm={() => visualizeSelectedAlgorithm()}
Expand Down
4 changes: 2 additions & 2 deletions src/components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default function NavBar(props) {
<div className="wall--patterns">
<h3>Wall Patterns</h3>
<ul className="patterns--list">
<li><button>Random Maze</button></li>
<li><button>Recursive Maze</button></li>
<li><button onClick={() => props.selectMazeType("random")}>Random Maze</button></li>
<li><button onClick={() => props.selectMazeType("recursive")}>Recursive Maze</button></li>
</ul>
</div>
<button className="test">Add Bomb</button>
Expand Down
15 changes: 15 additions & 0 deletions src/mazes/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default function createRandomMaze(nodes) {
const newNodes = nodes.slice();
for (let i=0; i<nodes.length; i++) {
for (let j=0; j<nodes[i].length; j++) {
const randomValue = Math.floor(Math.random() * 10);
if (randomValue < 3) {
newNodes[i][j].isWall = true;
}
else {
continue;
}
}
}
return newNodes;
}

0 comments on commit 51d8d7f

Please sign in to comment.