123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- class Game {
- #tubes;
- #selectedTube;
-
- constructor(nbTubes, tubeLevel)
- {
- this.tubes = [];
- this.selectedTube = null;
- this.isCompleted = false;
-
- 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()
- );
- }
- }
|