js-knights-travails/src/gameBoard.js
2023-07-17 13:50:38 -07:00

32 lines
670 B
JavaScript

import { square } from "./square.js";
// game board containing squares
export const gameBoard = (size) => {
// makes board
const make = () => {
const arr = [];
for (let x = 0; x <= size; x++) {
const yarr = [];
for (let y = 0; y <= size; y++) {
yarr.push(square(x, y));
}
arr.push(yarr);
}
return arr.flat();
};
// assigns it to variable
const board = make();
// finds specified square
const find = (x, y) => {
for (let i = 0; i < board.length; i++) {
if (board[i].x === x && board[i].y === y) {
return board[i];
}
}
return null;
};
return {
board,
find,
};
};