Compare commits

..

No commits in common. "9c9504363d5ab5251db99e1a9916b76ccdbdf6fb" and "4717a6e4e97c5ee02d4d7158e0a61cbd2d0859c2" have entirely different histories.

6 changed files with 12 additions and 123 deletions

View file

@ -5,11 +5,9 @@ export class Constants
{ {
/** /**
* The IDs of the players. * The IDs of the players.
*
* @type {Partial<Record<CellOwner, string>>}
*/ */
static PLAYER_NAMES = { static PLAYER_NAMES = [
r: "red", "red",
b: "blue" "blue"
}; ];
} }

View file

@ -1,23 +0,0 @@
/**
* The state of the board.
*
* @type {Board}
*/
export const State = /** @type {Board} */ (
Array(6).fill("").map(
() => (Array(7).fill("").map(
() =>
{
let id = Math.floor(Math.random() * 3);
switch (id)
{
case 1:
return "r";
case 2:
return "b";
default:
return "";
}
})))
);

View file

@ -1,6 +1,5 @@
import { Constants } from "./Constants.js"; import { Constants } from "./Constants.js";
import { elt } from "./elt.js"; import { elt } from "./elt.js";
import { State } from "./State.js";
/** /**
* Initializes the game board. * Initializes the game board.
@ -11,22 +10,21 @@ import { State } from "./State.js";
export function initializeBoard(id) export function initializeBoard(id)
{ {
let board = document.getElementById(id); let board = document.getElementById(id);
board.innerHTML = "";
for (let i = 0; i < 6; i++) for (let i = 0; i < 6; i++)
{ {
for (let j = 0; j < 7; j++) for (let i = 0; i < 7; i++)
{ {
/** @type {Node[]} */ /** @type {Node[]} */
let children = []; let children = [];
let playerId = State[i][j]; let playerId = Math.floor(Math.random() * 3);
if (playerId !== "") if (playerId > 0)
{ {
children.push(elt( children.push(elt(
"div", "div",
{ {
class: `piece ${Constants.PLAYER_NAMES[playerId]}` class: `piece ${Constants.PLAYER_NAMES[playerId - 1]}`
})); }));
} }

View file

@ -1,68 +1,5 @@
import { initializeBoard } from "./board.js"; import { initializeBoard } from "./board.js";
import { State } from "./State.js"; import { elt } from "./elt.js";
/** document.documentElement.appendChild(elt("a", { href: "https://startpage.com/" }, "This is a test"));
* Initializes the board.
*/
function initialize()
{
initializeBoard("board"); initializeBoard("board");
}
initialize();
/**
* Sleeps for the specified number of milliseconds.
*
* @param {number} ms
* The number of milliseconds to sleep.
*/
async function sleep(ms)
{
return new Promise((resolve) => setTimeout(resolve, ms));
}
(
async () =>
{
let counter = 0;
let tick = 0;
// eslint-disable-next-line no-constant-condition
while (true)
{
await sleep(1000 * (1 / 5));
let cycle = counter % 24;
if ((cycle <= 11) || ((cycle % 2) === 0))
{
tick = (tick % 18) + 1;
let rowId = Math.floor(Math.random() * State.length);
let fieldId = Math.floor(Math.random() * State[rowId].length);
/**
* @type {CellOwner}
*/
let owner;
switch (Math.floor(Math.random() * 3))
{
case 1:
owner = "r";
break;
case 2:
owner = "b";
break;
default:
owner = "";
break;
}
State[rowId][fieldId] = owner;
console.log(tick);
initialize();
}
counter++;
}
})();

21
src/js/types.d.ts vendored
View file

@ -1,21 +0,0 @@
/**
* Represents the state of a field.
*/
type CellOwner = "" | "r" | "b";
/**
* Represents a row of the game field.
*/
type Row = [CellOwner, CellOwner, CellOwner, CellOwner, CellOwner, CellOwner, CellOwner];
/**
* Represents a game board.
*/
type Board = [
Row,
Row,
Row,
Row,
Row,
Row
];