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.

historyHandler.js 685B

123456789101112131415161718192021222324252627282930313233343536373839
  1. class HistoryHandler
  2. {
  3. #history;
  4. constructor()
  5. {
  6. this.#history = [];
  7. }
  8. restore()
  9. {
  10. if (this.empty()) return;
  11. let lastAction = this.#history.pop();
  12. for (let i = 0; i < lastAction.times; i++)
  13. {
  14. let color = lastAction.targetTube.removeColorLayer();
  15. lastAction.sourceTube.addColorLayer(color);
  16. }
  17. }
  18. empty()
  19. {
  20. return this.#history.length == 0;
  21. }
  22. size()
  23. {
  24. return this.#history.length;
  25. }
  26. log(_source, _target, _times)
  27. {
  28. let historyItem = new HistoryItem(_source, _target, _times);
  29. this.#history.push(historyItem);
  30. }
  31. }