Skip to content

gitflarePublicPartly agent-ready40

orbit-duel

Real-time two-player orbital combat game on Cloudflare Workers and Durable Objects.

main
Add the Apache-2.0 licence0413e56
JavaScript21 lines852 B
import { test } from 'node:test';import assert from 'node:assert/strict';import { encodeJoin, parseMessage } from '../public/shared/protocol.js';import { newBucket, checkBucket } from '../src/room-logic.ts'; test('join encodes watch flag', () => {  assert.deepEqual(encodeJoin('a', null, null, true), ['j', 'a', null, null, 1]);  assert.deepEqual(encodeJoin('a', 't', null), ['j', 'a', 't', null]);  assert.equal(parseMessage(JSON.stringify(encodeJoin('a', null, null, true)))[4], 1);}); test('constant 30 inputs/s + 10 Hz acks + pings for 3 min never strikes', () => {  const b = newBucket(0);  for (let ms = 0; ms < 180000; ms += 33) {    assert.ok(checkBucket(b, ms, 40).ok);    if (ms % 100 < 33) assert.ok(checkBucket(b, ms, 12).ok);    if (ms % 1000 < 33) assert.ok(checkBucket(b, ms, 20).ok);  }  assert.equal(b.strikes, 0);});