소스 검색

Rooms have objects, and objects have actions, and actions can be executed. Too many burgers

tags/v0.2.8
Fen Dweller 7 년 전
부모
커밋
54586e4d5a
2개의 변경된 파일44개의 추가작업 그리고 4개의 파일을 삭제
  1. +43
    -4
      feast.js
  2. +1
    -0
      world.js

+ 43
- 4
feast.js 파일 보기

@@ -1,6 +1,8 @@
let currentRoom = null;
let dirButtons = [];
let actionButtons = [];
let mode = "explore";
let actions = [];

let player = {
name: "Fen",
@@ -11,6 +13,22 @@ let player = {
maxFullness: 200
};

function Object(name="Potato") {
this.name = name;
this.actions = [];
}

function Burger() {
Object.call(this, "Burger");
this.actions.push({
"name": "Punch Burger",
"action": function() {
player.health += 10;
update(["You punch the hamburger."]);
}
});
}

function updateExplore() {
for (let i = 0; i < dirButtons.length; i++) {
let button = dirButtons[i];
@@ -26,6 +44,11 @@ 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 updateCombat() {
@@ -56,16 +79,32 @@ function move(direction) {
if (target == null) {
alert("Tried to move to an empty room!");
return;
} else {
currentRoom = target;
update(["You move to " + currentRoom.name,currentRoom.description]);
updateDisplay();
}

moveTo(target);
}

function moveTo(room) {
actions = [];
currentRoom = room;

currentRoom.objects.forEach(function (object) {
object.actions.forEach(function (action) {
actions.push(action);
})
})

update(["You move to " + currentRoom.name,currentRoom.description]);

updateDisplay();
}

window.addEventListener('load', function(event) {
loadCompass();
actionButtons = Array.from( document.querySelectorAll(".action-button"));
currentRoom = createWorld();
currentRoom.objects.push(new Burger());
moveTo(currentRoom);
updateDisplay();
});



+ 1
- 0
world.js 파일 보기

@@ -71,6 +71,7 @@ function Location(name="Nowhere",desc="Nada") {
this.name = name;
this.description = desc;
this.exits = [null,null,null,null,null,null,null,null];
this.objects = [];
}

function opposite(direction) {


불러오는 중...
취소
저장