diff --git a/index.js b/index.js index 7a1a8e2..a315edd 100644 --- a/index.js +++ b/index.js @@ -55,4 +55,10 @@ function isgameOver() { printBold("Game Over. Refresh to play again!") document.getElementById("userInput").disabled = true; } +} + +function listCommands() { + if (userInput.value.toLowerCase() === "commands") { + printBold(Object.keys(locations[currentLocation].visibleVerbs).join(", ")) +} } \ No newline at end of file diff --git a/inventory.js b/inventory.js index 5f3dd0c..74539c5 100644 --- a/inventory.js +++ b/inventory.js @@ -1,16 +1,28 @@ inventory = [] function checkInventory() { - if (userInput.value.toLowerCase() === "inventory"){ - if (inventory.length === 0) { - printBold("You have nothing.") - } else { - printBold(inventory.join(", ")); - } - } + if (userInput.value.toLowerCase() === "inventory") { + if (inventory.length === 0) { + printBold("You have nothing.") + } else { + printBold(inventory.join(", ")); + } + } } function pickUp() { - + let target; + if (userInput.value.toLowerCase().startsWith("pick up ")) { + target = userInput.value.substring("pick up ".length) + } else if (userInput.value.toLowerCase().startsWith("grab ")) { + target = userInput.value.substring("grab ".length) + } + if (locations[currentLocation].collectables[target]) { + inventory.push(target) + printBold("You pick up the " + target) + delete locations[currentLocation].collectables[target] + } else { + printBold("Nothing to pick up!") + } } \ No newline at end of file diff --git a/locations.js b/locations.js index e19dd90..dcf29dc 100644 --- a/locations.js +++ b/locations.js @@ -3,43 +3,83 @@ let locations = "Computer Room": { "objects": { "Computer": { - "interactable": true }, "Northern Door": { - "interactable": true, - "gotoroom": "hallway" + "open": false } }, - "verbs": { - "go north": function(inventory, currentLocation, etc) { - printBold("uwu"); + "visibleVerbs": { + "go north": function () { + if (locations[currentLocation].objects["Northern Door"].open) { + currentLocation = "Hallway" + printBold(locations["Hallway"].onEntry) + } else { + printBold("The door is closed.") + } }, - "go east": function(inventory, currentLocation, etc) { - printBold("uwuwu"); + "open door": function () { + locations[currentLocation].objects["Northern Door"].open = true + printBold("The door is now open.") + }, + "use computer": function () { + printBold("Nothing displays on the monitor but a blue screen of death.") } - }, - "onEntry": "You are in a dark room. With only a COMPUTER, and a monitor dimly illuminating the room. Type LOOK to see your surroundings." + }, + "hiddenVerbs": { + + }, + "collectables": { + + }, + "onEntry": "You are in a dark room. With only a COMPUTER, and a monitor dimly illuminating the room. There is also a closed DOOR to your NORTH. Type LOOK to see your surroundings. Type COMMANDS to see a list of commands you can use in your current location." }, - "hallway": { + "Hallway": { "objects": { - "Northern Door": { - "interactable": true + "North Door": { + "locked": true }, - "Western Door": { - "interactable": false + "West Door": { }, "Vase": { - "interactable": true, - "contains": { - "key": { - "grabable": true - } - } } }, - "onEntry": "You have entered a brightly lit hallway. In the hallway you notice a VASE and two doors. One to the east and one to the north." + "visibleVerbs": { + "go north": function () { + printBold("The Door is closed.") + }, + "open door": function () { + printBold("West door or North Door?") + }, + "open north door": function () { + if (locations["Hallway"].objects["North Door"].locked === true) { + printBold("This door appears to be locked.") + } + }, + "open west door": function () { + currentLocation = "Western Hallway" + printBold("The door opens.") + printBold(locations["Western Hallway"].onEntry) + + }, + }, + "hiddenVerbs": { + "use vase": function () { + if (locations[currentLocation].collectables["key"] != undefined) { + printBold("You find a key inside the vase.") + locations[currentLocation].collectables["key"] = true + } else { + printBold("The vase is empty.") + } + }, + }, + "interact vase": "use vase", + + "onEntry": "You have entered a brightly lit hallway. In the hallway you notice a VASE and two doors. One to the east and one to the north.", + "collectables": { + "key": false + } } } \ No newline at end of file diff --git a/verbhandler.js b/verbhandler.js index dec11ec..71bfc5d 100644 --- a/verbhandler.js +++ b/verbhandler.js @@ -8,16 +8,33 @@ function commandInput() { listLocation() } else if (input === 'win') { win() + } else if (input === 'commands') { + listCommands() + } else if (input.startsWith("pick up ") || input.startsWith("grab ")) { + pickUp() } else { verbHandler() } } function verbHandler() { - let verbs = Object.keys(locations[currentLocation].verbs) - if (verbs.includes(userInput.value.toLowerCase())) { - // Something + let visibleVerbs = Object.keys(locations[currentLocation].visibleVerbs) + let hiddenVerbs = Object.keys(locations[currentLocation].hiddenVerbs) + if (visibleVerbs.includes(userInput.value.toLowerCase())) { + let verb = locations[currentLocation].visibleVerbs[userInput.value.toLowerCase()] + if (typeof verb === "string") { + locations[currentLocation].visibleVerbs[verb]() + } else { + verb() + } + } else if (hiddenVerbs.includes(userInput.value.toLowerCase())) { + let verb = locations[currentLocation].hiddenVerbs[userInput.value.toLowerCase()] + if (typeof verb === "string") { + locations[currentLocation].hiddenVerbs[verb]() + } else { + verb() + } } else { - printBold("Invalid Action.") + printBold("Invalid Action.") } }