phase 1: refactor directory structure (value-objects, factions, characters)

This commit is contained in:
2026-06-14 11:36:37 +01:00
parent 3965aaf33b
commit fc260dc97c
13 changed files with 18 additions and 18 deletions
+34
View File
@@ -0,0 +1,34 @@
/**
* Level value object — constrained to 1..10.
*
* "I can't believe it's not Haskell": invalid states are unrepresentable.
* Level progression (next) and combat modifiers (diff) belong to later stories.
*/
export class Level {
#value: number;
private constructor(n: number) {
this.#value = n;
}
static create(n: number): Level {
if (n < 1 || n > 10) {
throw new Error(`Level must be between 1 and 10, got ${n}`);
}
return new Level(n);
}
get value(): number {
return this.#value;
}
/** Maximum health for this level: 1000 until level 6, 1500 from level 6 onward. */
static maxHealthForLevel(level: number): number {
return level >= 6 ? 1500 : 1000;
}
/** Signed level difference: this level minus target level. Positive = this is higher. */
diff(target: Level): number {
return this.value - target.value;
}
}