From e7536ea037e987719292887202348c9080e32aeb Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 9 Mar 2018 10:29:21 -0500 Subject: [PATCH] Made the player a Creature. Better action logic, no more duplicates --- feast.html | 1 + feast.js | 43 +++++++++++++++++++++++++++++-------------- vore.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 vore.js diff --git a/feast.html b/feast.html index f993994..66af074 100644 --- a/feast.html +++ b/feast.html @@ -6,6 +6,7 @@ Feast + diff --git a/feast.js b/feast.js index e05a817..03f72ca 100644 --- a/feast.js +++ b/feast.js @@ -6,14 +6,7 @@ let actions = []; let time = 9*60; let newline = " "; -let player = { - name: "Fen", - height: 1.55, - health: 75, - maxHealth: 100, - fullness: 35, - maxFullness: 200 -}; +let player = new Player(); function Object(name="Potato") { this.name = name; @@ -31,7 +24,7 @@ function Burger() { }); } -function updateExplore() { +function updateExploreCompass() { for (let i = 0; i < dirButtons.length; i++) { let button = dirButtons[i]; if (currentRoom.exits[i] == null) { @@ -46,12 +39,23 @@ function updateExplore() { button.innerHTML = currentRoom.exits[i].name; } } - - for (let i = 0; i < actionButtons.length && i < actions.length; i++) { - actionButtons[i].innerHTML = actions[i].name; - actionButtons[i].addEventListener("click", function() { actions[i].action(); }); +} +function updateExploreActions() { + for (let i = 0; i < actionButtons.length; i++) { + if (i < actions.length) + actionButtons[i].innerHTML = actions[i].name; + else + actionButtons[i].innerHTML = ""; } } +function updateExplore() { + + updateExploreCompass(); + + updateExploreActions(); + + +} function updateCombat() { @@ -117,8 +121,8 @@ function moveTo(room) { } window.addEventListener('load', function(event) { + loadActions(); loadCompass(); - actionButtons = Array.from( document.querySelectorAll(".action-button")); currentRoom = createWorld(); currentRoom.objects.push(new Burger()); moveTo(currentRoom); @@ -135,6 +139,17 @@ function update(lines=[]) { updateDisplay(); } +function actionClicked(index) { + actions[index].action(); +} + +function loadActions() { + actionButtons = Array.from( document.querySelectorAll(".action-button")); + for (let i = 0; i < actionButtons.length; i++) { + actionButtons[i].addEventListener("click", function() { actionClicked(i); }); + } +} + function loadCompass() { dirButtons[NORTH_WEST] = document.getElementById("compass-north-west"); dirButtons[NORTH_WEST].addEventListener("click", function() { diff --git a/vore.js b/vore.js new file mode 100644 index 0000000..c51f028 --- /dev/null +++ b/vore.js @@ -0,0 +1,33 @@ +function Creature(name = "Creature") { + this.name = name; + this.health = 100; + this.maxHealth = 100; + this.mass = 80; + this.stomach = Stomach(); +} + +function Player(name = "Player") { + Creature.call(this, name); + + this.fullness = 100; + this.maxFullness = 200; +} +function Container(name = "stomach") { + this.name = name; + this.contents = []; + this.digest = function() { + + }; +} + +function Stomach() { + Container.call(this, "stomach"); + + this.digest = function() { + let lines = []; + this.contents.forEach(function (prey) { + lines.push("Something is digesting!"); + }); + return lines; + } +}