UNPKG

warriorjs-engine

Version:
152 lines (132 loc) 4.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _decoratorsViewObject = require('./decorators/viewObject'); var _Position = require('./Position'); var _Position2 = _interopRequireDefault(_Position); var _Space = require('./Space'); var _Space2 = _interopRequireDefault(_Space); var _unitsWarrior = require('./units/Warrior'); var _unitsWarrior2 = _interopRequireDefault(_unitsWarrior); var viewObjectShape = { size: { width: function width() { return this.width; }, height: function height() { return this.height; } }, stairs: { x: function x() { return this.stairsLocation[0]; }, y: function y() { return this.stairsLocation[1]; } }, units: function units() { return this.units; } }; var Floor = (function () { function Floor(width, height) { _classCallCheck(this, _Floor); this._stairsLocation = [-1, -1]; this._units = []; this._width = width; this._height = height; } _createClass(Floor, [{ key: 'placeStairs', value: function placeStairs(x, y) { this._stairsLocation = [x, y]; } }, { key: 'addUnit', value: function addUnit(unit, x, y, direction) { unit.position = new _Position2['default'](this, x, y, direction); this._units.push(unit); } }, { key: 'getSpaceAt', value: function getSpaceAt(x, y) { return new _Space2['default'](this, x, y); } }, { key: 'getUnitAt', value: function getUnitAt(x, y) { return this.units.find(function (unit) { return unit.position.isAt(x, y); }); } }, { key: 'isOutOfBounds', value: function isOutOfBounds(x, y) { return x < 0 || y < 0 || x > this.width - 1 || y > this.height - 1; } }, { key: 'width', get: function get() { return this._width; }, set: function set(width) { this._width = width; } }, { key: 'height', get: function get() { return this._height; }, set: function set(height) { this._height = height; } }, { key: 'stairsLocation', get: function get() { return this._stairsLocation; } }, { key: 'stairsSpace', get: function get() { return this.getSpaceAt.apply(this, _toConsumableArray(this.stairsLocation)); } }, { key: 'units', get: function get() { return this._units.filter(function (unit) { return unit.position; }); } }, { key: 'otherUnits', get: function get() { return this.units.filter(function (unit) { return !(unit instanceof _unitsWarrior2['default']); }); } }, { key: 'uniqueUnits', get: function get() { var uniqueUnits = []; this.units.forEach(function (unit) { if (!uniqueUnits.map(function (uniqueUnit) { return uniqueUnit.constructor; }).includes(unit.constructor)) { uniqueUnits.push(unit); } }); return uniqueUnits; } }]); var _Floor = Floor; Floor = (0, _decoratorsViewObject.viewObject)(viewObjectShape)(Floor) || Floor; return Floor; })(); exports['default'] = Floor; module.exports = exports['default'];