diff --git a/src/game/tick.service.ts b/src/game/tick.service.ts index a12c45220f38fad268d0ca4ab86932f69aa54668..b6ba273588a4b706ebf3b5b929d8ff49946251c0 100644 --- a/src/game/tick.service.ts +++ b/src/game/tick.service.ts @@ -1,9 +1,13 @@ import { Injectable, Logger } from '@nestjs/common'; import { ScoreService } from '../score/score.service'; +import { GameService } from './game.service'; @Injectable() export class TickService { - constructor(private scoreService: ScoreService) { + constructor( + private scoreService: ScoreService, + private gameService: GameService, + ) { // whenever Tickservice is called, it will start ticktimer /* WARNING: multiple calls start multiple timers, @@ -21,6 +25,14 @@ export class TickService { async startTimer() { this.logger.log('Started timer'); setInterval(this.Tick, this.tickInterval); + + // get games with STARTED value + let games = await this.gameService.listGames('STARTED'); + + // add STARTED games to dictionary + games.map(game => { + this.ongoingGames[game.id] = Date.now(); + }); } // add the game to tick queue