UNPKG

@runox-game/game-engine

Version:
147 lines (146 loc) 6.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandService = void 0; var commands_invoker_1 = require("./commands-invoker"); var build_deck_command_1 = require("./build-deck.command"); var start_game_command_1 = require("./start-game.command"); var add_players_command_1 = require("./add-players.command"); var play_card_command_1 = require("./play-card.command"); var take_deck_card_command_1 = require("./take-deck-card.command"); var finalize_turn_command_1 = require("./finalize-turn.command"); var yell_uno_command_1 = require("./yell-uno.command"); var remove_player_command_1 = require("./remove-player.command"); var take_card_random_player_command_1 = require("./take-card-random-player.command"); var switch_hands_command_1 = require("./switch-hands.command"); /** * Class that serves as an entry point for invoking commands within the game */ var CommandService = /** @class */ (function () { /** * Class that serves as an entry point for invoking commands within the game */ function CommandService() { } /** * Invokes the necessary commands to start the game * * @param currentState - current game state * @param gameModes - different game modes * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.startGame = function (currentState, gameModes) { var invoker = new commands_invoker_1.CommandsInvoker([ new build_deck_command_1.BuildDeckCommand(), new start_game_command_1.StartGameCommand(gameModes), ]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to reset the game * * @param currentState - current game state * @param gameModes - different game modes * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.resetGame = function (currentState, gameModes) { var invoker = new commands_invoker_1.CommandsInvoker([ new build_deck_command_1.BuildDeckCommand(), new start_game_command_1.StartGameCommand(gameModes), ]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to add players to the game * * @param currentState - current game state * @param players - players to add into the game * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.addPlayers = function (currentState, players) { var invoker = new commands_invoker_1.CommandsInvoker([new add_players_command_1.AddPlayersCommand(players)]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to remove a player from the game * * @param currentState - current game state * @param player - player to remove from the game * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.removePlayer = function (currentState, player) { var invoker = new commands_invoker_1.CommandsInvoker([new remove_player_command_1.RemovePlayerCommand(player)]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to play a card * * @param currentState - current game state * @param playerId - identifier of the player who wants to play a card * @param card - card to be played * @param toPlayerId - identifier of the player who will receive the card * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.playCard = function (currentState, playerId, card, toPlayerId) { var invoker = new commands_invoker_1.CommandsInvoker([ new play_card_command_1.PlayCardCommand(playerId, card, toPlayerId), new finalize_turn_command_1.FinalizeTurnCommand(), ]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to take a card from the deck * * @param currentState - current game state * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.takeCard = function (currentState) { var invoker = new commands_invoker_1.CommandsInvoker([ new take_deck_card_command_1.TakeDeckCardCommand(), new finalize_turn_command_1.FinalizeTurnCommand(), ]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to take a card from the deck and assign it to a random player * * @param currentState - current game state * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.takeCardToRandomPlayer = function (currentState) { var invoker = new commands_invoker_1.CommandsInvoker([new take_card_random_player_command_1.TakeCardRandomPlayerCommand()]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to yell Uno * * @param currentState - current game state * @param playerId - identifier of the player who wants to yell Uno * @returns observable with the intention of being able to track the success or failure * of the command group invocation */ CommandService.prototype.yellUno = function (currentState, yellerId) { var invoker = new commands_invoker_1.CommandsInvoker([new yell_uno_command_1.YellUnoCommand(yellerId)]); return invoker.invoke(currentState); }; /** * Invokes the necessary commands to switch ahdnhands between players * @param currentState - current game state * @param player1 - player to switch his hand * @param player2 - player to switch his hand */ CommandService.prototype.switchHands = function (currentState, player1, player2) { var invoker = new commands_invoker_1.CommandsInvoker([ new switch_hands_command_1.SwitchHandsCommand(player1, player2), ]); return invoker.invoke(currentState); }; return CommandService; }()); exports.CommandService = CommandService;