Erste Version

This commit is contained in:
2026-04-04 15:09:32 +02:00
commit b8e8554464
12 changed files with 843 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import test from "node:test";
import assert from "node:assert/strict";
import {
LEVELS,
WORLD,
createBottleTypes,
createLevelState,
createSeededRandom,
tryPickBottle,
tryDropBottle,
} from "../src/gameLogic.js";
test("Level-Skalierung stimmt", () => {
assert.deepEqual(LEVELS, [
{ types: 2, bottles: 10 },
{ types: 4, bottles: 20 },
{ types: 8, bottles: 40 },
{ types: 16, bottles: 80 },
]);
});
test("Flaschensorten sind eindeutig", () => {
const types = createBottleTypes(16);
const ids = new Set(types.map((t) => t.id));
assert.equal(types.length, 16);
assert.equal(ids.size, 16);
});
test("Level wird mit korrekter Anzahl und ohne ungueltige Positionen erzeugt", () => {
const rng = createSeededRandom(1234);
const state = createLevelState(2, rng);
assert.equal(state.bottles.length, 40);
assert.equal(state.types.length, 8);
state.bottles.forEach((b) => {
assert.ok(b.x > 0 && b.x < WORLD.cols - 1);
assert.ok(b.y > 0 && b.y < WORLD.rows - 1);
});
});
test("Falsches Ablegen wird erkannt", () => {
const rng = createSeededRandom(2);
const state = createLevelState(0, rng);
const firstBottle = state.bottles[0];
state.player = { x: firstBottle.x, y: firstBottle.y };
const pick = tryPickBottle(state);
assert.equal(pick.ok, true);
const wrongCrate = state.crates.find((c) => c.typeId !== state.carrying.typeId);
state.player = { x: wrongCrate.x, y: wrongCrate.y };
const drop = tryDropBottle(state);
assert.equal(drop.ok, false);
assert.equal(drop.reason, "falsch");
});