diff --git a/game.js b/game.js index 87fcc05..03e3be3 100644 --- a/game.js +++ b/game.js @@ -4,6 +4,9 @@ var scale = 1; var strolling = false; +var stomachDigesting = 0; +var bowelsDigesting = 0; + victims = {}; function toggle_auto() @@ -25,6 +28,9 @@ function initVictims() }; }; +var stomach = [] +var bowels = [] + function getOnePrey(area) { var potential = ["Person", "Car", "Bus", "House", "Train", "Parking Garage", "Tide Pod"]; @@ -89,6 +95,13 @@ function feed() scale = scaleAddMass(scale, baseMass, preyMass); + stomach.push(prey); + + if (stomachDigesting == 0) + setTimeout(function() { doDigest("stomach"); }, 15000); + + ++stomachDigesting; + updateVictims("stomach",prey); update([line]); } @@ -104,7 +117,6 @@ function stomp() updateVictims("stomped",prey); update([line]); - } function anal_vore() @@ -117,6 +129,13 @@ function anal_vore() scale = scaleAddMass(scale, baseMass, preyMass); + bowels.push(prey); + + if (bowelsDigesting == 0) + setTimeout(function() { doDigest("bowels"); }, 15000); + + ++bowelsDigesting; + updateVictims("bowels",prey); update([line]); } @@ -184,6 +203,47 @@ function grow() update(); } +// pop the list and digest that object + +function doDigest(containerName) +{ + var digestType = containerName == "stomach" ? stomach : bowels; + var count = 0; + + if (containerName == "stomach") { + count = stomachDigesting; + stomachDigesting = 0; + } else if (containerName == "bowels") { + count = bowelsDigesting; + bowelsDigesting = 0; + } + + var container = new Container(); + + while (count > 0) { + --count; + var toDigest = digestType.shift(); + if (toDigest.name != "Container") + toDigest = new Container([toDigest]); + container.merge(toDigest); + } + + var digested = container.sum(); + + for (var key in victims[digestType]) { + if (victims[containerName].hasOwnProperty(key)) { + victims["digested"][key] += digested[key]; + victims["stomach"][key] -= digested[key]; + } + } + + if (containerName == "stomach") + update(["Your stomach gurgles as it digests " + container.describe()]); + else if (containerName == "bowels") + update(["Your bowels churn as they absorb " + container.describe()]); + +} + function digest() { var newlyDigested = initVictims(); @@ -239,7 +299,6 @@ window.addEventListener('load', function(event) { document.getElementById("button-stroll").addEventListener("click",toggle_auto); setTimeout(pick_move, 2000); - setTimeout(digest, 5000); update(); }); diff --git a/recursive-macro.js b/recursive-macro.js index 1b9e66d..d12d562 100644 --- a/recursive-macro.js +++ b/recursive-macro.js @@ -263,6 +263,22 @@ function Container(contents = []) { return describe_all(this.contents) } + // put another container into this one + + this.merge = function(container) { + for (var key in container.contents) { + if (container.contents.hasOwnProperty(key)) { + if (this.contents.hasOwnProperty(key)) { + this.count += container.contents[key].count; + this.contents[key] = new things[container.contents[key].name](container.contents[key].count + this.contents[key].count); + } else { + this.count += container.contents[key].count; + this.contents[key] = new things[container.contents[key].name](container.contents[key].count); + } + } + } + } + return this; } @@ -293,7 +309,6 @@ function Person(count = 1) { return this.count + " people" } } - return this; }