|
@@ -25,6 +25,17 @@ class CodeBox {
|
|
|
* @type {Array|Array[]}
|
|
|
*/
|
|
|
this.box = [];
|
|
|
+ /**
|
|
|
+ * The farthest right the box goes
|
|
|
+ * @type {int}
|
|
|
+ */
|
|
|
+ this.maxBoxWidth = 0;
|
|
|
+ /**
|
|
|
+ * The bottom of the box
|
|
|
+ *
|
|
|
+ * @type {int}
|
|
|
+ */
|
|
|
+ this.maxBoxHeight = 0;
|
|
|
/**
|
|
|
* The coordinates of the currently executing instruction inside the code box
|
|
|
* @type {int[]}
|
|
@@ -103,6 +114,9 @@ class CodeBox {
|
|
|
}
|
|
|
|
|
|
this.EqualizeBoxWidth(maxRowLength);
|
|
|
+
|
|
|
+ this.maxBoxWidth = maxRowLength - 1;
|
|
|
+ this.maxBoxHeight = this.box.length - 1;
|
|
|
|
|
|
let fin = null;
|
|
|
|
|
@@ -243,8 +257,23 @@ class CodeBox {
|
|
|
}
|
|
|
|
|
|
Move() {
|
|
|
- const newX = this.pointer[0] + this.curr_direction[0];
|
|
|
- const newY = this.pointer[1] + this.curr_direction[1];
|
|
|
+ let newX = this.pointer[0] + this.curr_direction[0];
|
|
|
+ let newY = this.pointer[1] + this.curr_direction[1];
|
|
|
+
|
|
|
+ // Keep the X coord in the boxes bounds
|
|
|
+ if(newX < 0) {
|
|
|
+ newX = this.maxBoxWidth;
|
|
|
+ }
|
|
|
+ else if(newX > this.maxBoxWidth) {
|
|
|
+ newX = 0;
|
|
|
+ }
|
|
|
+ // Keep the Y coord in the boxes bounds
|
|
|
+ if(newY < 0) {
|
|
|
+ newY = this.maxBoxHeight;
|
|
|
+ }
|
|
|
+ else if(newY > this.maxBoxHeight) {
|
|
|
+ newY = 0;
|
|
|
+ }
|
|
|
|
|
|
this.SetPointer(newX, newY);
|
|
|
}
|