MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / DrawMaze

Function DrawMaze

assets/js/maze.js:213–322  ·  view source on GitHub ↗
(Maze, ctx, cellsize, endSprite = null)

Source from the content-addressed store, hash-verified

211}
212
213function DrawMaze(Maze, ctx, cellsize, endSprite = null) {
214 var map = Maze.map();
215 var cellSize = cellsize;
216 var drawEndMethod;
217 ctx.lineWidth = cellSize / 40;
218
219 this.redrawMaze = function (size) {
220 cellSize = size;
221 ctx.lineWidth = cellSize / 50;
222 drawMap();
223 drawEndMethod();
224 };
225
226 function drawCell(xCord, yCord, cell) {
227 var x = xCord * cellSize;
228 var y = yCord * cellSize;
229
230 if (cell.n == false) {
231 ctx.beginPath();
232 ctx.moveTo(x, y);
233 ctx.lineTo(x + cellSize, y);
234 ctx.stroke();
235 }
236 if (cell.s === false) {
237 ctx.beginPath();
238 ctx.moveTo(x, y + cellSize);
239 ctx.lineTo(x + cellSize, y + cellSize);
240 ctx.stroke();
241 }
242 if (cell.e === false) {
243 ctx.beginPath();
244 ctx.moveTo(x + cellSize, y);
245 ctx.lineTo(x + cellSize, y + cellSize);
246 ctx.stroke();
247 }
248 if (cell.w === false) {
249 ctx.beginPath();
250 ctx.moveTo(x, y);
251 ctx.lineTo(x, y + cellSize);
252 ctx.stroke();
253 }
254 }
255
256 function drawMap() {
257 for (x = 0; x < map.length; x++) {
258 for (y = 0; y < map[x].length; y++) {
259 drawCell(x, y, map[x][y]);
260 }
261 }
262 }
263
264 function drawEndFlag() {
265 var coord = Maze.endCoord();
266 var gridSize = 4;
267 var fraction = cellSize / gridSize - 2;
268 var colorSwap = true;
269 for (let y = 0; y < gridSize; y++) {
270 if (gridSize % 2 == 0) {

Callers

nothing calls this directly

Calls 2

drawMapFunction · 0.85
clearFunction · 0.70

Tested by

no test coverage detected