Selaa lähdekoodia

Add ability to set computers memory to a new stack

Added the SetMemory function, which allows you to set the computer's
memory to an entirely new stack.
ApisNecros 1 vuosi sitten
vanhempi
säilyke
9896b63595
1 muutettua tiedostoa jossa 13 lisäystä ja 0 poistoa
  1. 13 0
      IntComp/Computer.js

+ 13 - 0
IntComp/Computer.js

@@ -152,6 +152,19 @@ module.exports = class Computer {
     Reset() {
         this.stack = new Stack(this._initialMemory);
     }
+
+    /**
+     * Sets the computer's memory to a new stack
+     *
+     * Note: This resets the computer's initial memory, so `Reset` will use this value
+     *
+     * @param {number[]} stack The new memory stack for the computer
+     * @returns {void}
+     */
+    SetMemory(stack) {
+        this._initialMemory = DeepClone(stack);
+        this.stack = new Stack(stack);
+    }
 };
 
 /**