diff --git a/feast.css b/feast.css index 78b5b94..8cf91d7 100644 --- a/feast.css +++ b/feast.css @@ -42,16 +42,21 @@ button { } .dialog-button { - width: 100px; - height: 100px; + width: 300px; + height: 75px; font-size: 18px;s } +#dialog { + list-style-type: none; +} + #log { background: #222; width: 100%; height: 100%; flex: 3; + overflow: auto; } #stats { diff --git a/feast.html b/feast.html index 37f712c..ccecf2e 100644 --- a/feast.html +++ b/feast.html @@ -5,6 +5,7 @@ Feast + @@ -21,7 +22,7 @@
- Welcome to Feast v0.0.3 + Welcome to Feast v0.0.1
Time: to get a watch
@@ -125,21 +126,10 @@
-
- - - - - - -
- - - - - -
-
+ + +
diff --git a/feast.js b/feast.js index 7311b17..a4763c6 100644 --- a/feast.js +++ b/feast.js @@ -3,44 +3,18 @@ let currentDialog = null; let dirButtons = []; let actionButtons = []; -let dialogButtons = []; let mode = "explore"; let actions = []; -let time = 9*60; +let time = 9*60*60; let newline = " "; let player = new Player(); -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 Nerd() { - Object.call(this, "Nerd"); - this.actions.push({ - "name": "Eat Nerd", - "action": function() { - startDialog(new EatDude()); - } - }); -} - function startDialog(dialog) { mode = "dialog"; currentDialog = dialog; + update([currentDialog.visit()]); updateDisplay(); } @@ -87,18 +61,20 @@ function updateCombat() { } function updateDialog() { - for (let i = 0; i < dialogButtons.length; i++) { - if (i < currentDialog.choices.length) { - dialogButtons[i].disabled = false; - dialogButtons[i].innerHTML = currentDialog.choices[i].text; - dialogButtons[i].classList.remove("inactive-button"); - dialogButtons[i].classList.add("active-button"); - } else { - dialogButtons[i].disabled = true; - dialogButtons[i].innerHTML = ""; - dialogButtons[i].classList.remove("active-button"); - dialogButtons[i].classList.add("inactive-button"); - } + let list = document.getElementById("dialog"); + + while(list.firstChild) { + list.removeChild(list.firstChild); + } + + for (let i = 0; i < currentDialog.choices.length; i++) { + let li = document.createElement("li"); + let button = document.createElement("button"); + button.classList.add("dialog-button"); + button.innerHTML = currentDialog.choices[i].text; + button.addEventListener("click", function() { dialogClicked(i); }); + li.appendChild(button); + list.appendChild(li); } } @@ -115,6 +91,7 @@ function updateDisplay() { document.getElementById("selector-combat").style.display = "flex"; document.getElementById("selector-dialog").style.display = "none"; updateCombat(); + break; case "dialog": document.getElementById("selector-explore").style.display = "none"; document.getElementById("selector-combat").style.display = "none"; @@ -130,14 +107,15 @@ function updateDisplay() { } function advanceTime(amount) { - time = (time + amount) % 1440; + time = (time + amount) % 86400; } + function renderTime(time) { - let suffix = (time < 720) ? "AM" : "PM"; - let hour = Math.floor((time % 720) / 60); + let suffix = (time < 43200) ? "AM" : "PM"; + let hour = Math.floor((time % 43200) / 3600); if (hour == 0) hour = 12; - let minute = time % 60; + let minute = Math.floor(time / 60) % 60; if (minute < 9) minute = "0" + minute; @@ -151,21 +129,21 @@ function move(direction) { return; } - moveTo(target); + moveTo(target,currentRoom.exitDescs[direction]); } -function moveTo(room) { +function moveTo(room,desc="You go places lol") { actions = []; currentRoom = room; - advanceTime(1); + advanceTime(30); currentRoom.objects.forEach(function (object) { object.actions.forEach(function (action) { actions.push(action); - }) - }) + }); + }); - update(["You move to " + currentRoom.name,currentRoom.description,newline]); + update([desc,newline]); } window.addEventListener('load', function(event) { @@ -173,8 +151,6 @@ window.addEventListener('load', function(event) { loadCompass(); loadDialog(); currentRoom = createWorld(); - currentRoom.objects.push(new Burger()); - currentRoom.objects.push(new Nerd()); moveTo(currentRoom); updateDisplay(); }); @@ -186,6 +162,8 @@ function update(lines=[]) { div.innerHTML = lines[i]; log.appendChild(div); } + + log.scrollTop = log.scrollHeight; updateDisplay(); } diff --git a/objects.js b/objects.js new file mode 100644 index 0000000..836d661 --- /dev/null +++ b/objects.js @@ -0,0 +1,67 @@ +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 Nerd() { + Object.call(this, "Nerd"); + this.actions.push({ + "name": "Eat Nerd", + "action": function() { + startDialog(new EatDude()); + } + }); +} + +function Toilet() { + Object.call(this, "Toilet"); + this.actions.push({ + "name": "Admire toilet", + "action": function() { + update(["You admire the toilet."]); + } + }); +} + +function TV() { + Object.call(this, "TV"); + this.actions.push({ + "name": "Watch TV", + "action": function() { + update(["Reruns, again."]); + } + }); +} + +function Phone() { + Object.call(this, "Phone"); + this.actions.push({ + "name": "Headbutt phone", + "action": function() { + startDialog(new PhoneCall()); + } + }); +} + +function Bed() { + Object.call(this, "Bed"); + this.actions.push({ + "name": "Sleep", + "action": function() { + update(["You take a nap."]); + advanceTime(2700); + updateDisplay(); + } + }); +} diff --git a/world.js b/world.js index 9d4c940..15a86a7 100644 --- a/world.js +++ b/world.js @@ -19,23 +19,35 @@ let locations = {}; let locationsSrc = [ { "name": "Bedroom", - "desc": "A bedroom", + "desc": "A bedroom. It has a bed in it.", "conn": [ { "name": "Bathroom", - "dir": EAST + "dir": EAST, + "desc": "You step into your bathroom." }, { "name": "Living Room", - "dir": NORTH + "dir": NORTH, + "desc": "You walk into the living room." } + ], + "objs": [ + Bed ] }, { "name": "Bathroom", - "desc": "The bathroom", + "desc": "Your modest bathroom.", "conn": [ - + { + "name": "Bedroom", + "dir": WEST, + "desc": "You walk back into your bedroom." + } + ], + "objs": [ + Toilet ] }, { @@ -44,8 +56,18 @@ let locationsSrc = [ "conn": [ { "name": "Street", - "dir": NORTH + "dir": NORTH, + "desc": "You step outside." + }, + { + "name": "Bedroom", + "dir": SOUTH, + "desc": "You walk into your bedroom." } + ], + "objs": [ + TV, + Phone ] }, { @@ -54,14 +76,30 @@ let locationsSrc = [ "conn": [ { "name": "Alley", - "dir": WEST + "dir": WEST, + "desc": "You wander into the dark alley." + }, + { + "name": "Living Room", + "dir": SOUTH, + "desc": "You step back into your apartment." } + ], + "objs": [ + Nerd ] }, { "name": "Alley", "desc": "A suspicious alley", "conn": [ + { + "name": "Street", + "dir": EAST, + "desc": "You hurry back into the open street." + } + ], + "objs": [ ] } @@ -71,6 +109,7 @@ function Location(name="Nowhere",desc="Nada") { this.name = name; this.description = desc; this.exits = [null,null,null,null,null,null,null,null]; + this.exitDescs = [null,null,null,null,null,null,null,null]; this.objects = []; } @@ -78,17 +117,16 @@ function opposite(direction) { return (direction + 4) % 8; } -function connectLocations(loc1,loc2,loc1Exit) { - if (loc1.exits[loc1Exit] != null) { - alert(loc1.name + " is already connected to " + loc1.exits[loc1Exit].name); - return; - } else if (loc2.exits[opposite(loc1Exit)] != null) { - alert(loc2.name + " is already connected to " + loc2.exits[opposite(loc1Exit)].name); +function connectLocations(loc1,loc2,dir,desc) { + if (loc1.exits[dir] != null) { + alert(loc1.name + " is already connected to " + loc1.exits[dir].name); return; } else { - if (loc1Exit >= 0 && loc1Exit <= 7) { - loc1.exits[loc1Exit] = loc2; - loc2.exits[opposite(loc1Exit)] = loc1; + if (dir >= 0 && dir <= 7) { + loc1.exits[dir] = loc2; + loc1.exitDescs[dir] = desc; + } else { + alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir); } } } @@ -98,6 +136,9 @@ function createWorld() { let src = locationsSrc[i]; let location = new Location(src.name,src.desc); locations[src.name] = location; + src.objs.forEach(function (obj) { + location.objects.push(new obj()); + }); } for (let i = 0; i < locationsSrc.length; i++) { @@ -105,7 +146,7 @@ function createWorld() { let from = locations[src.name]; for (let j = 0; j < src.conn.length; j++) { let to = locations[src.conn[j].name]; - connectLocations(from, to, src.conn[j].dir); + connectLocations(from, to, src.conn[j].dir, src.conn[j].desc); } }