Changes
parent
7e9fdb3af5
commit
4d40c7df59
6
index.js
6
index.js
|
@ -55,4 +55,10 @@ function isgameOver() {
|
||||||
printBold("Game Over. Refresh to play again!")
|
printBold("Game Over. Refresh to play again!")
|
||||||
document.getElementById("userInput").disabled = true;
|
document.getElementById("userInput").disabled = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function listCommands() {
|
||||||
|
if (userInput.value.toLowerCase() === "commands") {
|
||||||
|
printBold(Object.keys(locations[currentLocation].visibleVerbs).join(", "))
|
||||||
|
}
|
||||||
}
|
}
|
28
inventory.js
28
inventory.js
|
@ -1,16 +1,28 @@
|
||||||
inventory = []
|
inventory = []
|
||||||
|
|
||||||
function checkInventory() {
|
function checkInventory() {
|
||||||
if (userInput.value.toLowerCase() === "inventory"){
|
if (userInput.value.toLowerCase() === "inventory") {
|
||||||
if (inventory.length === 0) {
|
if (inventory.length === 0) {
|
||||||
printBold("You have nothing.")
|
printBold("You have nothing.")
|
||||||
} else {
|
} else {
|
||||||
printBold(inventory.join(", "));
|
printBold(inventory.join(", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function pickUp() {
|
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!")
|
||||||
|
}
|
||||||
}
|
}
|
84
locations.js
84
locations.js
|
@ -3,43 +3,83 @@ let locations =
|
||||||
"Computer Room": {
|
"Computer Room": {
|
||||||
"objects": {
|
"objects": {
|
||||||
"Computer": {
|
"Computer": {
|
||||||
"interactable": true
|
|
||||||
},
|
},
|
||||||
"Northern Door": {
|
"Northern Door": {
|
||||||
"interactable": true,
|
"open": false
|
||||||
"gotoroom": "hallway"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"verbs": {
|
"visibleVerbs": {
|
||||||
"go north": function(inventory, currentLocation, etc) {
|
"go north": function () {
|
||||||
printBold("uwu");
|
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) {
|
"open door": function () {
|
||||||
printBold("uwuwu");
|
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": {
|
"objects": {
|
||||||
"Northern Door": {
|
"North Door": {
|
||||||
"interactable": true
|
"locked": true
|
||||||
},
|
},
|
||||||
"Western Door": {
|
"West Door": {
|
||||||
"interactable": false
|
|
||||||
},
|
},
|
||||||
"Vase": {
|
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,16 +8,33 @@ function commandInput() {
|
||||||
listLocation()
|
listLocation()
|
||||||
} else if (input === 'win') {
|
} else if (input === 'win') {
|
||||||
win()
|
win()
|
||||||
|
} else if (input === 'commands') {
|
||||||
|
listCommands()
|
||||||
|
} else if (input.startsWith("pick up ") || input.startsWith("grab ")) {
|
||||||
|
pickUp()
|
||||||
} else {
|
} else {
|
||||||
verbHandler()
|
verbHandler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function verbHandler() {
|
function verbHandler() {
|
||||||
let verbs = Object.keys(locations[currentLocation].verbs)
|
let visibleVerbs = Object.keys(locations[currentLocation].visibleVerbs)
|
||||||
if (verbs.includes(userInput.value.toLowerCase())) {
|
let hiddenVerbs = Object.keys(locations[currentLocation].hiddenVerbs)
|
||||||
// Something
|
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 {
|
} else {
|
||||||
printBold("Invalid Action.")
|
printBold("Invalid Action.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue