diff --git a/src/index.html b/src/index.html index 9704a97..a8bd83e 100644 --- a/src/index.html +++ b/src/index.html @@ -7,53 +7,7 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file diff --git a/src/js/Constants.js b/src/js/Constants.js new file mode 100644 index 0000000..fbf90ec --- /dev/null +++ b/src/js/Constants.js @@ -0,0 +1,13 @@ +/** + * Provides constants for the project. + */ +export class Constants +{ + /** + * The IDs of the players. + */ + static PLAYER_NAMES = [ + "red", + "blue" + ]; +} diff --git a/src/js/board.js b/src/js/board.js new file mode 100644 index 0000000..aa9f132 --- /dev/null +++ b/src/js/board.js @@ -0,0 +1,40 @@ +import { Constants } from "./Constants.js"; +import { elt } from "./elt.js"; + +/** + * Initializes the game board. + * + * @param {string} id + * The id of the element to add the board to. + */ +export function initializeBoard(id) +{ + let board = document.getElementById(id); + + for (let i = 0; i < 6; i++) + { + for (let i = 0; i < 7; i++) + { + /** @type {Node[]} */ + let children = []; + let playerId = Math.floor(Math.random() * 3); + + if (playerId > 0) + { + children.push(elt( + "div", + { + class: `piece ${Constants.PLAYER_NAMES[playerId - 1]}` + })); + } + + board.appendChild( + elt( + "div", + { + class: "field" + }, + ...children)); + } + } +} diff --git a/src/js/main.js b/src/js/main.js index 97e3c49..7bfd889 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,3 +1,5 @@ +import { initializeBoard } from "./board.js"; import { elt } from "./elt.js"; -elt("a", { href: "https://startpage.com/" }, "This is a test"); +document.documentElement.appendChild(elt("a", { href: "https://startpage.com/" }, "This is a test")); +initializeBoard("board");