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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
12 |
|
13 | var _LevelLoader = require('./LevelLoader');
|
14 |
|
15 | var _LevelLoader2 = _interopRequireDefault(_LevelLoader);
|
16 |
|
17 | var _Logger = require('./Logger');
|
18 |
|
19 | var _Logger2 = _interopRequireDefault(_Logger);
|
20 |
|
21 | var MAX_TURNS = 1000;
|
22 |
|
23 | var Level = (function () {
|
24 | function Level() {
|
25 | _classCallCheck(this, Level);
|
26 |
|
27 | this._warrior = null;
|
28 | this._floor = null;
|
29 | this._timeBonus = 0;
|
30 | }
|
31 |
|
32 | _createClass(Level, [{
|
33 | key: 'loadLevel',
|
34 | value: function loadLevel(config, warrior) {
|
35 | new _LevelLoader2['default'](this).load(config, warrior);
|
36 | }
|
37 | }, {
|
38 | key: 'loadPlayer',
|
39 | value: function loadPlayer() {
|
40 | this.warrior.loadPlayer();
|
41 | }
|
42 | }, {
|
43 | key: 'play',
|
44 | value: function play() {
|
45 | var _this = this;
|
46 |
|
47 | var turns = arguments.length <= 0 || arguments[0] === undefined ? MAX_TURNS : arguments[0];
|
48 |
|
49 | var trace = [];
|
50 |
|
51 | var _loop = function (n) {
|
52 | if (_this._passed() || _this._failed()) return 'break';
|
53 |
|
54 | var steps = [];
|
55 |
|
56 | _this.floor.units.forEach(function (unit) {
|
57 | return unit.prepareTurn();
|
58 | });
|
59 | _this.floor.units.forEach(function (unit) {
|
60 |
|
61 | var initialFloor = _this.floor.toViewObject();
|
62 |
|
63 | unit.performTurn();
|
64 |
|
65 | var finalFloor = _this.floor.toViewObject();
|
66 |
|
67 | var log = _Logger2['default'].entries;
|
68 | _Logger2['default'].clear();
|
69 |
|
70 | steps.push({ initialFloor: initialFloor, finalFloor: finalFloor, log: log });
|
71 | });
|
72 |
|
73 | if (_this.timeBonus) _this.timeBonus -= 1;
|
74 |
|
75 | trace.push(steps);
|
76 | };
|
77 |
|
78 | for (var n = 0; n < turns; n++) {
|
79 | var _ret = _loop(n);
|
80 |
|
81 | if (_ret === 'break') break;
|
82 | }
|
83 |
|
84 | return {
|
85 | trace: trace,
|
86 | passed: this._passed(),
|
87 | points: {
|
88 | levelScore: this.warrior.score,
|
89 | timeBonus: this.timeBonus,
|
90 | clearBonus: this.clearBonus
|
91 | }
|
92 | };
|
93 | }
|
94 | }, {
|
95 | key: '_passed',
|
96 | value: function _passed() {
|
97 | return this.floor.stairsSpace.isWarrior();
|
98 | }
|
99 | }, {
|
100 | key: '_failed',
|
101 | value: function _failed() {
|
102 | return !this.floor.units.includes(this.warrior);
|
103 | }
|
104 | }, {
|
105 | key: 'warrior',
|
106 | get: function get() {
|
107 | return this._warrior;
|
108 | },
|
109 | set: function set(warrior) {
|
110 | this._warrior = warrior;
|
111 | }
|
112 | }, {
|
113 | key: 'floor',
|
114 | get: function get() {
|
115 | return this._floor;
|
116 | },
|
117 | set: function set(floor) {
|
118 | this._floor = floor;
|
119 | }
|
120 | }, {
|
121 | key: 'timeBonus',
|
122 | get: function get() {
|
123 | return this._timeBonus;
|
124 | },
|
125 | set: function set(timeBonus) {
|
126 | this._timeBonus = timeBonus;
|
127 | }
|
128 | }, {
|
129 | key: 'clearBonus',
|
130 | get: function get() {
|
131 | return !this.floor.otherUnits.length ? Math.round((this.warrior.score + this.timeBonus) * 0.2) : 0;
|
132 | }
|
133 | }]);
|
134 |
|
135 | return Level;
|
136 | })();
|
137 |
|
138 | exports['default'] = Level;
|
139 | module.exports = exports['default']; |
\ | No newline at end of file |