소스 검색

Change code box point to an object

It's much easier to keep track of which value means what when using an
object, even though an array could be more efficient code-wise.
ApisNecros 1 년 전
부모
커밋
3be2ab5e6b
1개의 변경된 파일10개의 추가작업 그리고 7개의 파일을 삭제
  1. 10 7
      starfish.js

+ 10 - 7
starfish.js

@@ -38,9 +38,12 @@ class CodeBox {
         this.maxBoxHeight = 0;
         /**
          * The coordinates of the currently executing instruction inside the code box
-         * @type {int[]}
+         * @type {Object}
          */
-        this.pointer = [0,0];
+        this.pointer = {
+            X: 0,
+            Y: 0,
+        };
         /**
          * Was the instruction last moving in the left direction
          * 
@@ -95,7 +98,7 @@ class CodeBox {
     ParseCodeBox() {
         // Reset some field for a clean run
         this.box = [];
-        this.pointer = [0, 0];
+        this.pointer = {X: 0, Y: 0};
         this.curr_direction = this.directions.EAST;
         this.outputDOM.value = "";
 
@@ -268,7 +271,7 @@ class CodeBox {
     }
 
     Swim() {
-        const instruction = this.box[this.pointer[0]][this.pointer[1]];
+        const instruction = this.box[this.pointer.Y][this.pointer.X];
 
         if(this.stringMode != 0 && instruction != this.stringMode) {
             this.stack.Push(dec(instruction));
@@ -287,8 +290,8 @@ class CodeBox {
     }
 
     Move() {
-        let newX = this.pointer[0] + this.curr_direction[0];
-        let newY = this.pointer[1] + this.curr_direction[1];
+        let newX = this.pointer.X + this.curr_direction[0];
+        let newY = this.pointer.Y + this.curr_direction[1];
 
         // Keep the X coord in the boxes bounds
         if(newX < 0) {
@@ -312,7 +315,7 @@ class CodeBox {
      * Implement C and .
      */
     SetPointer(x, y) {
-        this.pointer = [x, y];
+        this.pointer = {X: x, Y: y};
     }
 
     /**