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.

drawer.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. class Drawer
  2. {
  3. #tubeDrawObjects;
  4. #scale;
  5. constructor(_padding, _scale, _game)
  6. {
  7. this.#tubeDrawObjects = []
  8. this.#scale = _scale;
  9. this.#initializeTubeDrawObjects(_game, _padding);
  10. this.#computeCanvasSize(_padding);
  11. }
  12. applySelectedEffect(index)
  13. {
  14. this.#tubeDrawObjects[index].y -= this.#scale;
  15. }
  16. removeSelectedEffect(index)
  17. {
  18. this.#tubeDrawObjects[index].y += this.#scale;
  19. }
  20. #initializeTubeDrawObjects(_game, _padding)
  21. {
  22. let _tubeX = _padding;
  23. let _tubeY = _padding + this.#scale;
  24. for (let tbIndex = 0; tbIndex < _game.tubesNumber(); tbIndex++)
  25. {
  26. let tubeDrawObject = new TubeDrawObject(_tubeX, _tubeY, _game.tubeAt(tbIndex), this.#scale);
  27. this.#tubeDrawObjects.push(tubeDrawObject);
  28. _tubeX += this.#scale + _padding;
  29. }
  30. }
  31. #computeCanvasSize(_padding)
  32. {
  33. let w = this.#tubeDrawObjects.reduce((res, value) => res + value.width + _padding, _padding);
  34. let h = this.#tubeDrawObjects[0].height + 2 * _padding + this.#scale;
  35. createCanvas(w, h);
  36. }
  37. draw()
  38. {
  39. clear();
  40. background('orange');
  41. this.#tubeDrawObjects.forEach(obj => obj.draw());
  42. }
  43. getTubeIdAt(x, y)
  44. {
  45. for (let i = 0; i < this.#tubeDrawObjects.length; i++)
  46. {
  47. if (this.#tubeDrawObjects[i].inbounds(x, y)) return i;
  48. }
  49. return -1;
  50. }
  51. }