diff --git a/front/src/lib/models/game.ts b/front/src/lib/models/game.ts new file mode 100644 index 0000000..48f9cc0 --- /dev/null +++ b/front/src/lib/models/game.ts @@ -0,0 +1,48 @@ +import {scoreStore} from "../stores/scoreStore"; + +export class Game { + + public name : string; + public result : number; + public state : GameState; + private readonly range : number; + + constructor() { + this.name = ""; + this.result = -1; + this.state = GameState.Unplayed; + this.range = 100 + } + + public async play() { + this.result = this.getRandomNumber(); + await scoreStore.add(this.name, this.result) + } + + public hasBeenPlayed() : boolean { + return this.state == GameState.Played; + } + + public isRunning() : boolean { + return this.state == GameState.Running; + } + + private getRandomNumber() : number{ + let unit = Math.floor(Math.random() * (this.range + 1)); + + if(unit === 100){ + let modifier = Math.floor(Math.random() * (this.range + 1)); + return unit*modifier; + } + + let dec = Math.floor(Math.random() * (this.range)); + return unit + (dec/100); + } + +} + +export enum GameState { + Unplayed, + Running, + Played, +} \ No newline at end of file diff --git a/front/src/routes/play/+page.svelte b/front/src/routes/play/+page.svelte index 41877b0..6eb41ee 100644 --- a/front/src/routes/play/+page.svelte +++ b/front/src/routes/play/+page.svelte @@ -1,54 +1,46 @@