12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- class Game {
- #tubes;
- #selectedTube;
-
- constructor(nbTubes, tubeLevel)
- {
- this.#tubes = [];
- this.#selectedTube = null;
-
- for (let i = 0; i < nbTubes; i++)
- {
- this.#tubes.push(new Tube(tubeLevel));
- }
- }
-
- tubeAt(tubeIndex)
- {
- if (!this.isInRange(tubeIndex)) return null;
-
- return this.#tubes[tubeIndex];
- }
-
- selectedTube()
- {
- return this.#selectedTube;
- }
-
- selectTubeAt(index)
- {
- if (this.isInRange(index))
- {
- this.#selectedTube = this.#tubes[index];
- }
- }
-
- removeTube(tube)
- {
- let tubeIndex = this.#tubes.indexOf(tube);
-
- if (tubeIndex != -1)
- {
- let removed = this.#tubes.splice(tubeIndex, 1)[0];
- if (removed = this.#selectedTube) this.unselectTube();
- }
- }
-
- clean()
- {
- this.#tubes = []
- this.unselectTube();
- }
-
- unselectTube()
- {
- this.#selectedTube = null;
- }
-
- tubesNumber()
- {
- return this.#tubes.length;
- }
-
- isInRange(index)
- {
- return index >= 0 && index < this.#tubes.length;
- }
- }
|