Advertisement
Guest User

Untitled

a guest
Nov 15th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. "use strict"
  2.  
  3. let core = {
  4.  
  5. _field: [
  6. [0,0,0,0,1,0,0,0,0,0],
  7. [0,0,0,0,0,0,0,0,0,0,0],
  8. [0,0,0,0,0,0,0,0,0,0],
  9. [0,0,0,0,0,0,0,0,0,0],
  10. [0,0,0,0,0,0,0,0,0,0],
  11. [0,0,0,0,0,0,0,0,0,0],
  12. [0,0,0,0,0,0,0,0,0,0],
  13. [0,0,0,0,0,0,0,0,0,0],
  14. [0,0,0,0,0,0,0,0,0,0],
  15. [0,0,0,0,0,0,0,0,0,0],
  16. ],
  17. _counterX: 4,
  18. _counterY: 0,
  19.  
  20. get field(){
  21. console.log(this._field);
  22. console.log("X: " + this._counterX);
  23. console.log("Y: " + this._counterY);
  24. },
  25.  
  26. goRight() {
  27. let interval = setInterval(function(){
  28. if (this._counterX == this._field[this._counterY].length - 1) {
  29. return false;
  30. } else {
  31. this._field[this._counterY][this._counterX] = 0;
  32. this._field[this._counterY][this._counterX + 1] = 1;
  33.  
  34. this._counterX++;
  35. }
  36.  
  37. this.field;
  38. }, 500);
  39. },
  40.  
  41. goLeft() {
  42. if (this._counterX <= 0) {
  43. return false;
  44. } else {
  45. this._field[this._counterY][this._counterX] = 0;
  46. this._field[this._counterY][this._counterX - 1] = 1;
  47.  
  48. this._counterX--;
  49. }
  50.  
  51. this.field;
  52. },
  53.  
  54. goDown() {
  55. if (this._counterY == this._field.length - 1) {
  56. return false;
  57. } else {
  58. if ( this._field[this._counterY].length > this._field[this._counterY + 1].length) {
  59. this._field[this._counterY][this._counterX] = 0;
  60. this._field[this._counterY + 1][this._counterX -1] = 1;
  61.  
  62. this._counterY++;
  63. this._counterX--;
  64.  
  65. } else {
  66. this._field[this._counterY][this._counterX] = 0;
  67. this._field[this._counterY + 1][this._counterX] = 1;
  68.  
  69. this._counterY++;
  70. }
  71. }
  72.  
  73. this.field;
  74. }
  75.  
  76. }
  77.  
  78. core.field;
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement