1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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;
- }
-
- isComplete()
- {
- return this.#tubes.every(
- tube => tube.isComplete() || tube.isEmpty()
- );
- }
- }
|