1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; })();
|
8 |
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
10 |
|
11 | 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); } }
|
12 |
|
13 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
14 |
|
15 | var _decoratorsViewObject = require('./decorators/viewObject');
|
16 |
|
17 | var _Position = require('./Position');
|
18 |
|
19 | var _Position2 = _interopRequireDefault(_Position);
|
20 |
|
21 | var _Space = require('./Space');
|
22 |
|
23 | var _Space2 = _interopRequireDefault(_Space);
|
24 |
|
25 | var _unitsWarrior = require('./units/Warrior');
|
26 |
|
27 | var _unitsWarrior2 = _interopRequireDefault(_unitsWarrior);
|
28 |
|
29 | var viewObjectShape = {
|
30 | size: {
|
31 | width: function width() {
|
32 | return this.width;
|
33 | },
|
34 | height: function height() {
|
35 | return this.height;
|
36 | }
|
37 | },
|
38 | stairs: {
|
39 | x: function x() {
|
40 | return this.stairsLocation[0];
|
41 | },
|
42 | y: function y() {
|
43 | return this.stairsLocation[1];
|
44 | }
|
45 | },
|
46 | units: function units() {
|
47 | return this.units;
|
48 | }
|
49 | };
|
50 |
|
51 | var Floor = (function () {
|
52 | function Floor(width, height) {
|
53 | _classCallCheck(this, _Floor);
|
54 |
|
55 | this._stairsLocation = [-1, -1];
|
56 | this._units = [];
|
57 |
|
58 | this._width = width;
|
59 | this._height = height;
|
60 | }
|
61 |
|
62 | _createClass(Floor, [{
|
63 | key: 'placeStairs',
|
64 | value: function placeStairs(x, y) {
|
65 | this._stairsLocation = [x, y];
|
66 | }
|
67 | }, {
|
68 | key: 'addUnit',
|
69 | value: function addUnit(unit, x, y, direction) {
|
70 | unit.position = new _Position2['default'](this, x, y, direction);
|
71 | this._units.push(unit);
|
72 | }
|
73 | }, {
|
74 | key: 'getSpaceAt',
|
75 | value: function getSpaceAt(x, y) {
|
76 | return new _Space2['default'](this, x, y);
|
77 | }
|
78 | }, {
|
79 | key: 'getUnitAt',
|
80 | value: function getUnitAt(x, y) {
|
81 | return this.units.find(function (unit) {
|
82 | return unit.position.isAt(x, y);
|
83 | });
|
84 | }
|
85 | }, {
|
86 | key: 'isOutOfBounds',
|
87 | value: function isOutOfBounds(x, y) {
|
88 | return x < 0 || y < 0 || x > this.width - 1 || y > this.height - 1;
|
89 | }
|
90 | }, {
|
91 | key: 'width',
|
92 | get: function get() {
|
93 | return this._width;
|
94 | },
|
95 | set: function set(width) {
|
96 | this._width = width;
|
97 | }
|
98 | }, {
|
99 | key: 'height',
|
100 | get: function get() {
|
101 | return this._height;
|
102 | },
|
103 | set: function set(height) {
|
104 | this._height = height;
|
105 | }
|
106 | }, {
|
107 | key: 'stairsLocation',
|
108 | get: function get() {
|
109 | return this._stairsLocation;
|
110 | }
|
111 | }, {
|
112 | key: 'stairsSpace',
|
113 | get: function get() {
|
114 | return this.getSpaceAt.apply(this, _toConsumableArray(this.stairsLocation));
|
115 | }
|
116 | }, {
|
117 | key: 'units',
|
118 | get: function get() {
|
119 | return this._units.filter(function (unit) {
|
120 | return unit.position;
|
121 | });
|
122 | }
|
123 | }, {
|
124 | key: 'otherUnits',
|
125 | get: function get() {
|
126 | return this.units.filter(function (unit) {
|
127 | return !(unit instanceof _unitsWarrior2['default']);
|
128 | });
|
129 | }
|
130 | }, {
|
131 | key: 'uniqueUnits',
|
132 | get: function get() {
|
133 | var uniqueUnits = [];
|
134 | this.units.forEach(function (unit) {
|
135 | if (!uniqueUnits.map(function (uniqueUnit) {
|
136 | return uniqueUnit.constructor;
|
137 | }).includes(unit.constructor)) {
|
138 | uniqueUnits.push(unit);
|
139 | }
|
140 | });
|
141 |
|
142 | return uniqueUnits;
|
143 | }
|
144 | }]);
|
145 |
|
146 | var _Floor = Floor;
|
147 | Floor = (0, _decoratorsViewObject.viewObject)(viewObjectShape)(Floor) || Floor;
|
148 | return Floor;
|
149 | })();
|
150 |
|
151 | exports['default'] = Floor;
|
152 | module.exports = exports['default']; |
\ | No newline at end of file |