UNPKG

the-game-domain

Version:

Complete domain layer for 'The Game' card game with rich business entities, automatic persistence, action tracking, and advanced game mechanics. Features Game, Player, Card, Deck, Pile entities with repository pattern, turn management, victory/defeat dete

98 lines 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GameAction = void 0; const uuid_1 = require("../utils/uuid"); class GameAction { constructor(gameId, type, description, playerId, playerName, cardValue, pileNumber, id, timestamp) { this._id = id || (0, uuid_1.generateUUID)(); this._gameId = gameId; this._type = type; this._description = description; this._playerId = playerId; this._playerName = playerName; this._cardValue = cardValue; this._pileNumber = pileNumber; this._timestamp = timestamp || new Date(); } get id() { return this._id; } get gameId() { return this._gameId; } get type() { return this._type; } get description() { return this._description; } get playerId() { return this._playerId; } get playerName() { return this._playerName; } get cardValue() { return this._cardValue; } get pileNumber() { return this._pileNumber; } get timestamp() { return new Date(this._timestamp); } equals(other) { return this._id === other._id; } toString() { return `GameAction(${this._type}, ${this._description}, ${this._timestamp.toISOString()})`; } toJSON() { return { id: this._id, gameId: this._gameId, type: this._type, description: this._description, playerId: this._playerId, playerName: this._playerName, cardValue: this._cardValue, pileNumber: this._pileNumber, timestamp: this._timestamp }; } static fromJSON(data) { return new GameAction(data.gameId, data.type, data.description, data.playerId, data.playerName, data.cardValue, data.pileNumber, data.id, data.timestamp); } static gameCreated(gameId, numberOfPlayers) { return new GameAction(gameId, 'GAME_CREATED', `Jogo ${gameId} criado com ${numberOfPlayers} jogador${numberOfPlayers > 1 ? 'es' : ''}`); } static cardPlayed(gameId, playerId, playerName, cardValue, pileNumber) { return new GameAction(gameId, 'CARD_PLAYED', `${playerName} jogou a carta ${cardValue} na pilha ${pileNumber}`, playerId, playerName, cardValue, pileNumber); } static turnChanged(gameId, playerId, playerName) { return new GameAction(gameId, 'TURN_CHANGED', `Vez de ${playerName}`, playerId, playerName); } static gameFinished(gameId, winnerName) { const description = winnerName ? `Jogo finalizado! ${winnerName} venceu!` : `Jogo finalizado!`; return new GameAction(gameId, 'GAME_FINISHED', description); } static cardsDrawn(gameId, playerId, playerName, cardCount) { return new GameAction(gameId, 'CARDS_DRAWN', `${playerName} comprou ${cardCount} carta${cardCount > 1 ? 's' : ''}`, playerId, playerName, cardCount); } static playerNameChanged(gameId, playerId, oldName, newName) { return new GameAction(gameId, 'PLAYER_NAME_CHANGED', `${oldName} alterou o nome para ${newName}`, playerId, newName); } static gameWon(gameId) { return new GameAction(gameId, 'GAME_WON', 'VITÓRIA! Todos os jogadores descartaram suas cartas e o deck está vazio!'); } static gameLost(gameId, playerName) { return new GameAction(gameId, 'GAME_LOST', `DERROTA! ${playerName} não consegue jogar mais nenhuma carta!`, undefined, playerName); } static gameRestarted(gameId, numberOfPlayers) { return new GameAction(gameId, 'GAME_RESTARTED', `Jogo ${gameId} reiniciado com ${numberOfPlayers} jogador${numberOfPlayers > 1 ? 'es' : ''}`); } } exports.GameAction = GameAction; //# sourceMappingURL=GameAction.js.map