moving.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. class move_direction {
  2. static get add() {
  3. return 1;
  4. }
  5. static get stop() {
  6. return 0;
  7. }
  8. static get sub() {
  9. return -1;
  10. }
  11. static contains(target) {
  12. if (target === move_direction.add) return true;
  13. if (target === move_direction.stop) return true;
  14. if (target === move_direction.sub) return true;
  15. return false;
  16. }
  17. }
  18. class moving {
  19. #x;
  20. #y;
  21. #z;
  22. constructor() {
  23. this.#x = 0;
  24. this.#y = 0;
  25. this.#z = 0;
  26. }
  27. get x() {
  28. return this.#x;
  29. }
  30. get y() {
  31. return this.#y;
  32. }
  33. get z() {
  34. return this.#z;
  35. }
  36. set x(target) {
  37. if (!move_direction.contains(target)) {
  38. throw new TypeError("New direction must be from move direction.");
  39. }
  40. this.#x = target;
  41. }
  42. set y(target) {
  43. if (!move_direction.contains(target)) {
  44. throw new TypeError("New direction must be from move direction.");
  45. }
  46. this.#y = target;
  47. }
  48. set z(target) {
  49. if (!move_direction.contains(target)) {
  50. throw new TypeError("New direction must be from move direction.");
  51. }
  52. this.#z = target;
  53. }
  54. stop() {
  55. this.x = move_direction.stop;
  56. this.y = move_direction.stop;
  57. this.z = move_direction.stop;
  58. }
  59. }
  60. export { moving, move_direction }