Browse Source

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 year ago
parent
commit
3be2ab5e6b
1 changed files with 10 additions and 7 deletions
  1. 10 7
      starfish.js

+ 10 - 7
starfish.js

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