Repeatedly update game board
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
f36b60b2e4
commit
9c9504363d
1 changed files with 66 additions and 1 deletions
|
@ -1,3 +1,68 @@
|
||||||
import { initializeBoard } from "./board.js";
|
import { initializeBoard } from "./board.js";
|
||||||
|
import { State } from "./State.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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++;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
Loading…
Reference in a new issue