diff --git a/src/main.ts b/src/main.ts index 5e6e61e..ddcc415 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,20 +1,25 @@ /// +/// let globalStartTime = 0; -function gameLoop (config: GameConfig): void { +function gameLoop (state: GameState): void { // figure out how much actual time has passed const elapsedTime = globalStartTime > 0 ? (new Date()).getTime() - globalStartTime : 0; + state.advance(elapsedTime); + // run again in 1sec globalStartTime = (new Date()).getTime(); - setTimeout(() => gameLoop(config), 1000); + setTimeout(() => gameLoop(state), 1000); } // run with default config at startup (() => { const config = new GameConfig(); - if (document.readyState !== 'loading') gameLoop(config); - else document.addEventListener('DOMContentLoaded', () => gameLoop(config)); + const state = config.generateState(); + + if (document.readyState !== 'loading') gameLoop(state); + else document.addEventListener('DOMContentLoaded', () => gameLoop(state)); })(); diff --git a/src/model/GameConfig.ts b/src/model/GameConfig.ts index e5d751f..d461872 100644 --- a/src/model/GameConfig.ts +++ b/src/model/GameConfig.ts @@ -1,3 +1,4 @@ +/// /// /// @@ -14,5 +15,42 @@ class GameConfig { public relOtherShare:number = 0.02; public relNoneShare: number = 0.16; - constructor () {} + public generateState(): GameState { + const state = new GameState(); + + // create world religions + state.addResource('xtian', new Religion( + 'Christianity', 'God, Jesus, Bible, churches.', + this.relChristianityShare * this.worldPopulation)); + + state.addResource('islam', new Religion( + 'Islam', 'God, Muhammad, Quran, mosques.', + this.relIslamShare * this.worldPopulation)); + + state.addResource('hindu', new Religion( + 'Hinduism', 'Dogma-free spiritualism.', + this.relHinduismShare * this.worldPopulation)); + + state.addResource('buddh', new Religion( + 'Buddhism', 'The minimization of suffering.', + this.relBuddhismShare * this.worldPopulation)); + + state.addResource('sikhi', new Religion( + 'Sikhism', 'Meditation and ten Gurus', + this.relSikhismShare * this.worldPopulation)); + + state.addResource('judah', new Religion( + 'Judaism', 'God, Abraham, Torah, synagogues.', + this.relJudaismShare * this.worldPopulation)); + + state.addResource('other', new Religion( + 'Other', 'A variety of belief systems.', + this.relOtherShare * this.worldPopulation)); + + state.addResource('agnos', new Religion( + 'Non-Religious', 'Atheists and agnostics.', + this.relNoneShare * this.worldPopulation)); + + return state; + } } diff --git a/src/model/GameState.ts b/src/model/GameState.ts new file mode 100644 index 0000000..cdc7f27 --- /dev/null +++ b/src/model/GameState.ts @@ -0,0 +1,13 @@ +/// + +class GameState { + private _resources: {[key: string]: IResource} = {}; + + public addResource (key: string, resource: IResource): void { + this._resources[key] = resource; + } + + public advance (time: number): void { + console.log(`Advancing state by ${time}ms...`); + } +} diff --git a/src/model/IResource.ts b/src/model/IResource.ts index fc3e6a4..8523fbe 100644 --- a/src/model/IResource.ts +++ b/src/model/IResource.ts @@ -7,5 +7,6 @@ interface IResource { description: string, resourceType: ResourceType, value: number, - max: number + max?: number, + unlocked: boolean } diff --git a/src/model/resource/Religion.ts b/src/model/resource/Religion.ts index 4f22198..6fb32b5 100644 --- a/src/model/resource/Religion.ts +++ b/src/model/resource/Religion.ts @@ -1,20 +1,14 @@ -/// /// class Religion implements IResource { - public readonly description: string; - public readonly resourceType: ResourceType = ResourceType.Religion; - - public value: number; - public max: number; + public readonly resourceType = ResourceType.Religion; + public readonly max?: number = null; + public readonly unlocked = true; constructor ( - config: GameConfig, public readonly name: string, - populationShare: number + public readonly description: string, + public readonly value: number, ) { - this.description = name; - this.max = config.worldPopulation; - this.value = config.worldPopulation * populationShare; } }