UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6class Tower {
7 /**
8 * Creates a tower.
9 *
10 * @param {string} id The identifier of the tower.
11 * @param {string} name The name of the tower.
12 * @param {string} description The description of the tower.
13 * @param {Object[]} levels The levels of the tower.
14 */
15 constructor(id, name, description, levels) {
16 this.id = id;
17 this.name = name;
18 this.description = description;
19 this.levels = levels;
20 }
21
22 /**
23 * Checks if the tower has a level with the given number.
24 *
25 * @param {number} levelNumber The number of the level.
26 *
27 * @returns {boolean} Whether the tower has the level or not.
28 */
29 hasLevel(levelNumber) {
30 return !!this.getLevel(levelNumber);
31 }
32
33 /**
34 * Returns the level with the given number.
35 *
36 * @param {number} levelNumber The number of the level.
37 *
38 * @returns {Object} The level.
39 */
40 getLevel(levelNumber) {
41 return this.levels[levelNumber - 1];
42 }
43
44 /**
45 * Returns the string representation of this tower.
46 *
47 * @returns {string} The string representation.
48 */
49 toString() {
50 return this.name;
51 }
52}
53
54exports.default = Tower;
55module.exports = exports.default;
\No newline at end of file