Esempio n. 1
0
        /// <summary>
        /// Generates a menu for the player to manage their inventory. Submenus are generated based on what type of item is selected (i.e. wieldable, equippable, consumable) as
        /// different options are available to each. For example, a player can wield or drop a weapon, or use/drop a potion.
        /// </summary>
        /// <returns>True if the player performs a valid action with an item </returns>
        private bool inventoryMenu()
        {
            while (true)
            {
                view.FormattedOutput("Manage your inventory.");
                string format = "[{0}] : {1}";
                for (int i = 0; i < _player.Inventory.Count; i++)
                {
                    view.FormattedOutput(String.Format(format, i + 1, _player.Inventory[i].Name)); //list the inventory to the player with the corresponding selection number
                }

                view.FormattedOutput("[0] : Return");
                view.FormattedOutput("Specify the number of the item you would like to select.");
                int input = view.Input() - 1; //Since we present the inventory starting at 1, we need to subtract one to access the inventory at the correct index
                if (input == -1)              // if the user enters 0, back out of the menu.
                {
                    return(false);
                }

                if (input > -1 && input < _player.Inventory.Count)
                {
                    AbstractItem item = _player.Inventory[input];
                    if (item is InfWieldable)
                    {
                        while (true)
                        {
                            view.FormattedOutput($"What would you like to do with &blu{item.Name}?");
                            //output the name of the weapon and its description
                            view.FormattedOutput($"&blu{item.Name}. {item.Desc}");
                            //list available actions that the user can perform on the weapon
                            view.FormattedOutput(string.Format(format, 1, "Wield"));
                            view.FormattedOutput(string.Format(format, 2, "Drop"));
                            view.FormattedOutput(string.Format(format, 0, "Return"));
                            switch (view.Input())
                            {
                            case 0: {
                                //return to outer menu
                                return(false);
                            }

                            case 1: {
                                //wield the weapon
                                ((InfWieldable)item).Wield(_player);      //set the player's weapon to the new one
                                view.FormattedOutput($"You are now wielding &blu{item.Name}.");
                                return(true);
                            }

                            case 2: {
                                //drop the weapon
                                _currentRoom.Contents.Add(_player.DropItem(_player.Inventory.IndexOf(item)));
                                //if the item dropped is the weapon the player is currently holding, set the player's current weapon to null
                                if (_player.Weapon == item)
                                {
                                    _player.Weapon = null;
                                }

                                view.FormattedOutput($"You drop &blu{item.Name}.");
                                return(true);
                            }

                            default: {
                                view.FormattedOutput($"You want to do what with &blu{item.Name}?");     //tell the player they entered an invalid command in a passive aggressive fashion
                                break;
                            }
                            }
                        }
                    }
                    else if (item is InfEquippable)
                    {
                        while (true)
                        {
                            view.FormattedOutput($"What would you like to do with &blu{item.Name}?");
                            // Output item name and description
                            view.FormattedOutput($"&blu{item.Name}. {item.Desc}");

                            view.FormattedOutput(string.Format(format, 1, "Equip"));
                            view.FormattedOutput(string.Format(format, 2, "Drop"));
                            view.FormattedOutput(string.Format(format, 0, "Return"));

                            switch (view.Input())
                            {
                            case 0: {
                                //return to outer menu
                                return(false);
                            }

                            case 1: {
                                ((InfEquippable)item).Equip(_player);      // Equip the armor to the player
                                view.FormattedOutput($"You are now wearing &blu{item.Name}.");
                                return(true);
                            }

                            case 2: {
                                _currentRoom.Contents.Add(_player.DropItem(_player.Inventory.IndexOf(item)));     // remove the dropped item from the players inventory and add it to the room's contents
                                //if the item dropped is the weapon the player is currently holding, set the player's current weapon to null
                                if (_player.Weapon == item)
                                {
                                    _player.Weapon = null;
                                }

                                view.FormattedOutput($"You drop &blu{item.Name}.");
                                return(true);
                            }

                            default: {
                                view.FormattedOutput($"You want to do what with &blu{item.Name}?");
                                break;
                            }
                            }
                        }
                    }
                    else if (item is InfConsumable)
                    {
                        while (true)
                        {
                            view.FormattedOutput($"What would you like to do with &blu{item.Name}?");
                            // Output item name and description
                            view.FormattedOutput($"&blu{item.Name}. {item.Desc}");

                            view.FormattedOutput(string.Format(format, 1, "Use"));
                            view.FormattedOutput(string.Format(format, 2, "Drop"));
                            view.FormattedOutput(string.Format(format, 0, "Return"));

                            switch (view.Input())
                            {
                            case 0: {
                                //return to outer menu
                                return(false);
                            }

                            case 1: {
                                item.Use(_player);     // Player use's the item
                                view.FormattedOutput($"You use &blu{item.Name}.");
                                return(true);
                            }

                            case 2: {
                                _currentRoom.Contents.Add(_player.DropItem(_player.Inventory.IndexOf(item)));
                                //if the item dropped is the weapon the player is currently holding, set the player's current weapon to null
                                if (_player.Weapon == item)
                                {
                                    _player.Weapon = null;
                                }

                                view.FormattedOutput($"You drop {item.Name}.");
                                return(true);
                            }

                            default: {
                                view.FormattedOutput(String.Format("You want to do what with {0}?", item.Name));
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        view.FormattedOutput("You have... &drdw &dgnh &dbla &dylt?");
                    }
                }
                else
                {
                    view.FormattedOutput("You're rather imaginative, aren't you?");
                }
            }
        }