From 8ec779ed65ce22ebcd0947e29a0105a3809c794c Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 9 Mar 2018 10:06:45 -0500 Subject: [PATCH] Added time and newlines --- feast.html | 1 + feast.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/feast.html b/feast.html index 2a4b0eb..f993994 100644 --- a/feast.html +++ b/feast.html @@ -22,6 +22,7 @@ Welcome to Feast v0.0.3
+
Time: to get a watch
Vim: 15
Pulchritude: 44
Imagination: 97
diff --git a/feast.js b/feast.js index 4659d57..e05a817 100644 --- a/feast.js +++ b/feast.js @@ -3,6 +3,8 @@ let dirButtons = []; let actionButtons = []; let mode = "explore"; let actions = []; +let time = 9*60; +let newline = " "; let player = { name: "Fen", @@ -69,11 +71,27 @@ function updateDisplay() { break; } + document.getElementById("time").innerHTML = "Time: " + renderTime(time); document.getElementById("stat-name").innerHTML = "Name: " + player.name; document.getElementById("stat-health").innerHTML = "Health: " + player.health + "/" + player.maxHealth; document.getElementById("stat-fullness").innerHTML = "Fullness: " + player.fullness + "/" + player.maxFullness; } +function advanceTime(amount) { + time = (time + amount) % 1440; +} +function renderTime(time) { + let suffix = (time < 720) ? "AM" : "PM"; + let hour = Math.floor((time % 720) / 60); + if (hour == 0) + hour = 12; + let minute = time % 60; + if (minute < 9) + minute = "0" + minute; + + return hour + ":" + minute + " " + suffix; +} + function move(direction) { let target = currentRoom.exits[direction]; if (target == null) { @@ -87,6 +105,7 @@ function move(direction) { function moveTo(room) { actions = []; currentRoom = room; + advanceTime(1); currentRoom.objects.forEach(function (object) { object.actions.forEach(function (action) { @@ -94,9 +113,7 @@ function moveTo(room) { }) }) - update(["You move to " + currentRoom.name,currentRoom.description]); - - updateDisplay(); + update(["You move to " + currentRoom.name,currentRoom.description,newline]); } window.addEventListener('load', function(event) {