UNPKG

@runox-game/game-engine

Version:
71 lines (70 loc) 3.41 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BuildDeckCommand = void 0; var game_command_1 = require("./game.command"); var card_model_1 = require("../models/card.model"); var color_model_1 = require("../models/color.model"); var values_model_1 = require("../models/values.model"); var command_result_1 = require("./command-result"); var log_levels_enum_1 = require("../log/log-levels.enum"); /** * Class that allows cards creation and add them to the game deck */ var BuildDeckCommand = /** @class */ (function (_super) { __extends(BuildDeckCommand, _super); /** * Class that allows cards creation and add them to the game deck */ function BuildDeckCommand() { return _super.call(this) || this; } BuildDeckCommand.prototype.execute = function (state) { state.deck.cards = []; state.log("Construyendo tablero", log_levels_enum_1.LogLevel.USER); /* Traditional deck contains: - +4 x2 - wildcard x2 - color cards x2 */ var specialCards = [values_model_1.Value.PLUS_FOUR, values_model_1.Value.WILDCARD]; state.log("Cartas especiales " + JSON.stringify(specialCards), log_levels_enum_1.LogLevel.USER); state.log("Agregando cartas", log_levels_enum_1.LogLevel.USER); state.deck.addCards(__spreadArrays(specialCards.map(function (specialCard) { return new card_model_1.Card(specialCard); }), specialCards.map(function (specialCard) { return new card_model_1.Card(specialCard); }))); color_model_1.COLORS.forEach(function (color) { values_model_1.VALUES.filter(function (card) { return card !== values_model_1.Value.WILDCARD && card !== values_model_1.Value.PLUS_FOUR; }).forEach(function (card) { var newCard1 = new card_model_1.Card(card, color); var newCard2 = new card_model_1.Card(card, color); state.deck.addCards([newCard1, newCard2]); }); }); state.log("Agregando cartas", log_levels_enum_1.LogLevel.USER); state.log("Barajando", log_levels_enum_1.LogLevel.USER); state.deck.shuffle(); }; BuildDeckCommand.prototype.validate = function (state) { return new command_result_1.CommandValidation(true); }; return BuildDeckCommand; }(game_command_1.GameCommand)); exports.BuildDeckCommand = BuildDeckCommand;