import { Action, GameAction } from "../actions"; import { type GameRules } from "../rules"; import { ResourceGenerator } from "./ResourceGenerator"; import { ResourceSet } from "./ResourceSet"; export class Game { public readonly rules: GameRules; public readonly resources = new ResourceSet(); public readonly generators: ResourceGenerator[] = []; constructor( rules: GameRules, ) { this.rules = rules; this.initResources(); this.initGenerators(); } public initResources(): void { this.resources.setMany(ResourceSet.from(this.rules.startResources)); } public initGenerators(): void { this.generators.splice(0); this.generators.push(...this.rules.generators.map((rule) => new ResourceGenerator(this, rule))); } public *tick(time: number): Generator { yield* this.runResourceGenerators(time); } private *runResourceGenerators(time: number): Generator { for (const gen of this.generators) gen.tick(time); } }