Преглед на файлове

Made the player a Creature. Better action logic, no more duplicates

tags/v0.2.8
Fen Dweller преди 7 години
родител
ревизия
e7536ea037
променени са 3 файла, в които са добавени 63 реда и са изтрити 14 реда
  1. +1
    -0
      feast.html
  2. +29
    -14
      feast.js
  3. +33
    -0
      vore.js

+ 1
- 0
feast.html Целия файл

@@ -6,6 +6,7 @@
<title>Feast</title>
<link rel="stylesheet" href="feast.css">
<script src="world.js"></script>
<script src="vore.js"></script>
<script src="feast.js"></script>
<meta name="theme-color" content="#000000" />
<meta name="description" content="A vore text adventure" />


+ 29
- 14
feast.js Целия файл

@@ -6,14 +6,7 @@ let actions = [];
let time = 9*60;
let newline = "&nbsp;";

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() {


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

Loading…
Отказ
Запис