Changes
This commit is contained in:
		
							parent
							
								
									7e9fdb3af5
								
							
						
					
					
						commit
						4d40c7df59
					
				
					 4 changed files with 109 additions and 34 deletions
				
			
		
							
								
								
									
										6
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								index.js
									
									
									
									
									
								
							|  | @ -56,3 +56,9 @@ function isgameOver() { | |||
|         document.getElementById("userInput").disabled = true; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function listCommands() { | ||||
|     if (userInput.value.toLowerCase() === "commands") { | ||||
|         printBold(Object.keys(locations[currentLocation].visibleVerbs).join(", ")) | ||||
| } | ||||
| } | ||||
							
								
								
									
										16
									
								
								inventory.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								inventory.js
									
									
									
									
									
								
							|  | @ -1,7 +1,7 @@ | |||
| inventory = [] | ||||
| 
 | ||||
| function checkInventory() { | ||||
|     if (userInput.value.toLowerCase() === "inventory"){ | ||||
|   if (userInput.value.toLowerCase() === "inventory") { | ||||
|     if (inventory.length === 0) { | ||||
|       printBold("You have nothing.") | ||||
|     } else { | ||||
|  | @ -12,5 +12,17 @@ function checkInventory() { | |||
| 
 | ||||
| 
 | ||||
| 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": { | ||||
|         "objects": { | ||||
|             "Computer": { | ||||
|                 "interactable": true | ||||
|             }, | ||||
|             "Northern Door": { | ||||
|                 "interactable": true, | ||||
|                     "gotoroom": "hallway" | ||||
|                 "open": false | ||||
|             } | ||||
|         }, | ||||
|         "verbs": { | ||||
|             "go north": function(inventory, currentLocation, etc) { | ||||
|               printBold("uwu"); | ||||
|             }, | ||||
|             "go east": function(inventory, currentLocation, etc) { | ||||
|               printBold("uwuwu"); | ||||
|         "visibleVerbs": { | ||||
|             "go north": function () { | ||||
|                 if (locations[currentLocation].objects["Northern Door"].open) { | ||||
|                     currentLocation = "Hallway" | ||||
|                     printBold(locations["Hallway"].onEntry) | ||||
|                 } else { | ||||
|                     printBold("The door is closed.") | ||||
|                 } | ||||
|             }, | ||||
|         "onEntry": "You are in a dark room. With only a COMPUTER, and a monitor dimly illuminating the room. Type LOOK to see your surroundings." | ||||
|             "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.") | ||||
|             } | ||||
|         }, | ||||
|         "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 | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -8,15 +8,32 @@ 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.") | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue