84 lines
No EOL
3.1 KiB
JavaScript
84 lines
No EOL
3.1 KiB
JavaScript
import { userInput } from "./functions.js";
|
|
import "./variables.js";
|
|
|
|
// inventoryMenuM()
|
|
// When the user asks to see thier inventory, this is called.
|
|
// Shows a list of options from which the player can choose
|
|
// If they choose to view, viewInventory() is called
|
|
// If they want to equip an armor or weapon, they are shown a list of all items with the specified type (weapon or armor)
|
|
// from there they can select the item and it replaces the item currently in the respective variable.
|
|
export function inventoryMenuM(){
|
|
console.clear();
|
|
console.log("INVENTORY");
|
|
console.log("---------");
|
|
console.log("1) View");
|
|
console.log("2) Equip Weapon");
|
|
console.log("3) Equip Armor");
|
|
console.log("4) Exit");
|
|
let invChoice = userInput("Enter: ");
|
|
switch(invChoice){
|
|
case "1":
|
|
viewInventory();
|
|
break;
|
|
case "2":
|
|
console.log("Weapons");
|
|
console.log("---------");
|
|
for(var a = 0; a < inventory.length;){
|
|
if (inventory[a].type == "weapon") {
|
|
console.log((a + 1) + ") " + inventory[a].name);
|
|
a++;
|
|
}
|
|
while (true) {
|
|
console.log("-----------------");
|
|
let equipInput = userInput("What would you like to equip?");
|
|
if (equipInput <= a) {
|
|
equippedWeapon = inventory[equipInput - 1];
|
|
console.log("You have equipped: " + equippedWeapon.name);
|
|
return;
|
|
} else {
|
|
console.log("Invalid Input. Please enter a valid number.");
|
|
}
|
|
}
|
|
}
|
|
case "3":
|
|
console.log("Armor");
|
|
console.log("---------");
|
|
for(var a = 0; a < inventory[1].length;){
|
|
if (inventory[a].type == "armor" || inventory[a].type == "parmor") {
|
|
console.log((a + 1) + ") " + inventory[a].name);
|
|
a++;
|
|
}
|
|
while (true) {
|
|
console.log("-----------------");
|
|
let equipInput = parseInt(userInput("What would you like to equip?"), 10);
|
|
if (equipInput <= a) {
|
|
equippedArmor = inventory[equipInput - 1];
|
|
console.log("You have equipped: " + equippedArmor.name);
|
|
return;
|
|
} else {
|
|
console.log("Invalid Input. Please enter a valid number.");
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "4":
|
|
break;
|
|
default:
|
|
console.log("Invalid Input");
|
|
}
|
|
}
|
|
|
|
// viewInventory()
|
|
// Lists all items in the inventory array.
|
|
function viewInventory(){
|
|
console.clear();
|
|
console.log("Inventory");
|
|
console.log("---------");
|
|
for(var a = 0; a < inventory.length;){
|
|
console.log((a + 1) + ") " + inventory[a].name);
|
|
a++;
|
|
}
|
|
userInput("[Enter to return]");
|
|
console.clear();
|
|
inventoryMenuM();
|
|
} |