From 5e25d6505c843ea48c8244874a6cbbc143452264 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 18 Feb 2018 20:14:43 -0500 Subject: [PATCH] Started working on more descriptive stomping --- recursive-desc.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++ recursive-macro.js | 24 +++++++++++++++ stroll.html | 1 + 3 files changed, 101 insertions(+) create mode 100644 recursive-desc.js diff --git a/recursive-desc.js b/recursive-desc.js new file mode 100644 index 0000000..0f9336f --- /dev/null +++ b/recursive-desc.js @@ -0,0 +1,76 @@ +function subset(list1,list2) { + for (var i = 0; i < list1.length; i++) { + if (!list2.includes(list1[i])){ + return false; + } + } + return true; +} + +function seteq(list1,list2) { + return list1.length == list2.length && subset(list1,list2); +} + +function getPreyNames(contents) { + prey = []; + + for (var key in contents) { + if (contents.hasOwnProperty(key)) { + prey.push(contents[key].name); + } + } + return prey; +} + +function getPreyCounts(contents) { + prey = {}; + + for (var key in contents) { + if (contents.hasOwnProperty(key)) { + prey[contents[key].name] = contents[key].count; + } + } + + return prey; +} + +function containerEat(container) { + var preyNames = getPreyNames(container.contents); + var preyCounts = getPreyCounts(container.contents); + return ""; +} + +function personEat(person) { + if (person.count == 1) { + if (Math.random() > 0.5) + return "You hoist " + person.describe() + " into the air and stuff them down your gullet. Delicious!"; + } + else if (person.count <= 3) { + if (Math.random() > 0.5) + return "You reach down with both hands, snagging " + (person.count == 2 ? "two" : "three") + " meals. You savor their taste, " + person.describe() + " slipping past your lips and down your throat, one-by-one."; + } + else if (person.count < 5) { + if (Math.random() > 0.5) + return "You reach down and snatch up a fistful of snacks, stuffing " + person.count + " people into your maw and swallowing deeply."; + } + + return ""; +} + +function personStomp(person) { + if (person.count == 1) { + var choice = Math.random(); + if (choice < 0.2) + return "Your heavy paw smashes a " + person.describe() + " like a bug. Splat."; + else if (choice < 0.4) + return "A wayward step obliterates a " + person.describe(); + else if (choice < 0.6) + return "You lunge at a " + person.describe() + " with your toes outstretched, squashing them flat."; + } + else if (person.count <= 3) { + if (Math.random() > 0.5) + return "Your paw comes down on " + person.describe() + ". " + (person.count == 2 ? "Both" : "All three") + " crunch beneath your heavy toes."; + } + + return ""; +} diff --git a/recursive-macro.js b/recursive-macro.js index 61fb09b..bece3a4 100644 --- a/recursive-macro.js +++ b/recursive-macro.js @@ -363,6 +363,14 @@ function Container(contents = []) { return describe_all(this.contents,false) } + this.eat = function() { + var line = containerEat(this); + if (line == "") + return defaultEat(this)(); + else + return line; + }; + return this; } @@ -398,6 +406,22 @@ function Person(count = 1) { } } + + this.stomp = function() { + var line = personStomp(this); + if (line == "") + return defaultStomp(this)(); + else + return line; + }; + + this.eat = function() { + var line = personEat(this); + if (line == "") + return defaultEat(this)(); + else + return line; + }; return this; } diff --git a/stroll.html b/stroll.html index 3ca1e7a..a767a71 100644 --- a/stroll.html +++ b/stroll.html @@ -4,6 +4,7 @@ Stroll +