C'est le jeu des tubes de couleur dans les pubs la
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

game.js 949B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class Game {
  2. #tubes;
  3. #selectedTube;
  4. constructor(nbTubes, tubeLevel)
  5. {
  6. this.#tubes = [];
  7. this.#selectedTube = null;
  8. for (let i = 0; i < nbTubes; i++)
  9. {
  10. this.#tubes.push(new Tube(tubeLevel));
  11. }
  12. }
  13. tubeAt(tubeIndex)
  14. {
  15. if (!this.isInRange(tubeIndex)) return null;
  16. return this.#tubes[tubeIndex];
  17. }
  18. selectedTube()
  19. {
  20. return this.#selectedTube;
  21. }
  22. selectTubeAt(index)
  23. {
  24. if (this.isInRange(index))
  25. {
  26. this.#selectedTube = this.#tubes[index];
  27. }
  28. }
  29. removeTube(tube)
  30. {
  31. let tubeIndex = this.#tubes.indexOf(tube);
  32. if (tubeIndex != -1)
  33. {
  34. let removed = this.#tubes.splice(tubeIndex, 1)[0];
  35. if (removed = this.#selectedTube) this.unselectTube();
  36. }
  37. }
  38. clean()
  39. {
  40. this.#tubes = []
  41. this.unselectTube();
  42. }
  43. unselectTube()
  44. {
  45. this.#selectedTube = null;
  46. }
  47. tubesNumber()
  48. {
  49. return this.#tubes.length;
  50. }
  51. isInRange(index)
  52. {
  53. return index >= 0 && index < this.#tubes.length;
  54. }
  55. }