瀏覽代碼

Started working on more descriptive stomping

tags/v0.7.0
Fen Dweller 7 年之前
父節點
當前提交
5e25d6505c
共有 3 個文件被更改,包括 101 次插入0 次删除
  1. +76
    -0
      recursive-desc.js
  2. +24
    -0
      recursive-macro.js
  3. +1
    -0
      stroll.html

+ 76
- 0
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 "";
}

+ 24
- 0
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;
}



+ 1
- 0
stroll.html 查看文件

@@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Stroll</title>
<link rel="stylesheet" href="style.css">
<script src="recursive-desc.js"></script>
<script src="recursive-macro.js"></script>
<script src="game.js"></script>
</head>


Loading…
取消
儲存