diff --git a/server/src/challenge-actions/challenge-actions.service.ts b/server/src/challenge-actions/challenge-actions.service.ts index c5db157..2a4ddd9 100644 --- a/server/src/challenge-actions/challenge-actions.service.ts +++ b/server/src/challenge-actions/challenge-actions.service.ts @@ -6,6 +6,7 @@ import { PrismaService } from 'src/prisma/prisma.service' import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' import { paginate } from 'src/common/utils/pagination.utils' import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto' +import { Constants } from 'src/common/utils/constants.utils' @Injectable() export class ChallengeActionsService { @@ -87,7 +88,7 @@ export class ChallengeActionsService { active: false, end: now, penaltyStart: now, - penaltyEnd: new Date(now.getTime() + 30 * 60 * 1000), + penaltyEnd: new Date(now.getTime() + Constants.PENALTY_TIME * 60 * 1000), } } return await this.prisma.challengeAction.update({ diff --git a/server/src/common/utils/constants.utils.ts b/server/src/common/utils/constants.utils.ts new file mode 100644 index 0000000..2b33419 --- /dev/null +++ b/server/src/common/utils/constants.utils.ts @@ -0,0 +1,21 @@ +export const Constants = { + /** + * Nombre de points attribués au début de la partie + */ + INITIAL_MONEY: 2000, + + /** + * Nombre de points attribués lors d'une nouvelle tentative + */ + NEW_RUN_MONEY: 300, + + /** + * Nombre de points requis pour l'achat d'un train par kilomètre (arrondi au supérieur) + */ + PRICE_PER_KILOMETER: 10, + + /** + * Temps de pénalité en minutes en cas d'échec d'un défi + */ + PENALTY_TIME: 30, +} diff --git a/server/src/game/game.service.ts b/server/src/game/game.service.ts index e83330e..783256c 100644 --- a/server/src/game/game.service.ts +++ b/server/src/game/game.service.ts @@ -2,6 +2,7 @@ import { ConflictException, Injectable } from '@nestjs/common' import { Game, MoneyUpdate, MoneyUpdateType } from '@prisma/client' import { PrismaService } from 'src/prisma/prisma.service' import { RepairGame } from './dto/repair-game.dto' +import { Constants } from 'src/common/utils/constants.utils' @Injectable() export class GameService { @@ -23,7 +24,7 @@ export class GameService { await this.prisma.moneyUpdate.create({ data: { playerId: player.id, - amount: 2000, + amount: Constants.INITIAL_MONEY, reason: MoneyUpdateType.START, } }) @@ -87,7 +88,7 @@ export class GameService { await this.prisma.moneyUpdate.create({ data: { playerId: newRunnerId, - amount: 300, + amount: Constants.NEW_RUN_MONEY, reason: MoneyUpdateType.NEW_RUN, runId: newRun.id, } @@ -139,7 +140,7 @@ export class GameService { const trainMoneyUpdate = await this.prisma.moneyUpdate.create({ data: { playerId: train.playerId, - amount: -10 * Math.ceil(train.distance / 1000), + amount: -Constants.PRICE_PER_KILOMETER * Math.ceil(train.distance / 1000), reason: MoneyUpdateType.BUY_TRAIN, tripId: train.id, } diff --git a/server/src/trains/trains.service.ts b/server/src/trains/trains.service.ts index f000147..38cf3b3 100644 --- a/server/src/trains/trains.service.ts +++ b/server/src/trains/trains.service.ts @@ -9,6 +9,7 @@ import { ImportTrainDto } from './dto/import-train.dto' import { InterrailJourney, InterrailLegInfo, InterrailTravelInfo } from './dto/interrail-api.dto' import { distanceCoordinates } from 'src/common/utils/calculus.utils' import { PlayerFilterDto } from 'src/common/dto/player_filter.dto' +import { Constants } from 'src/common/utils/constants.utils' @Injectable() export class TrainsService { @@ -87,7 +88,7 @@ export class TrainsService { const oldCoordinates = legInfoJson.trainStopStations.at(index - 1).coordinates return distance + distanceCoordinates({ from: oldCoordinates, to: coordinates }) }, 0) - const cost = 10 * 10 * Math.ceil(distance / 1000) + const cost = Constants.PRICE_PER_KILOMETER * Math.ceil(distance / 1000) const train = await this.prisma.trainTrip.create({ data: {