Exemple #1
0
        /// <summary>
        /// Method that drops the chosen item by the player.
        /// </summary>
        /// <param name="grid">Game grid.</param>
        /// <param name="count">Maximum number possible to input.</param>
        public void DropItems(GridManager grid, int count)
        {
            // Varible to hold player input
            string choice = "";

            // Variable index
            int i = 0;

            // Do cyce while input is invalid
            do
            {
                // Ask and save player input
                Console.Write("\n> ");
                choice = Console.ReadLine();

                // If input is a number convert string input to int
                if (choice != "")
                {
                    i = Convert.ToInt32(choice);
                }
            } while (i < 0 || i > count - 1 || choice == "");

            // If input is 0
            if (i == 0)
            {
                // Go back to grid screen without losing a turn
                Health++;
                return;
            }
            // If input is not 0
            else
            {
                // Define game object in inventory
                // Initially, i = player input
                IGameObject go = Inventory[i - 1];

                // If game object is an Item
                if (go is Item)
                {
                    // Add game object to grid
                    grid.GameGrid[PlayerPos.X, PlayerPos.Y].AddObject(go);

                    // Remove game object from player inventory
                    Inventory.RemoveAt(i - 1);

                    // Remove item weight from player weight
                    Weight -= (go as Item).Weight;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Method that uses the chosen item by the player.
        /// </summary>
        /// <param name="count">Maximum number possible to input.</param>
        public void UseItems(int count)
        {
            // Varible to hold player input
            string choice = "";

            // Variable index
            int i = 0;

            // Do cyce while input is invalid
            do
            {
                // Ask and save player input
                Console.Write("\n> ");
                choice = Console.ReadLine();

                // If input is a number convert string input to int
                if (choice != "")
                {
                    i = Convert.ToInt32(choice);
                }
            } while (i < 0 || i > count - 1 || choice == "");

            // If input is 0
            if (i == 0)
            {
                // Go back to grid screen without losing a turn
                Health++;
                return;
            }
            // If input is not 0
            else
            {
                // Define game object in inventory
                // Initially, i = player input
                IGameObject go = Inventory[i - 1];

                // If game object is Food
                if (go is Food)
                {
                    // Remove food from inventory
                    Inventory.RemoveAt(i - 1);

                    // Remove food item from player weight
                    Weight -= (go as Item).Weight;

                    // If player health is more than 100
                    if ((Health + (go as Food).HPIncrease) > 100)
                    {
                        // Health stays 100
                        Health = 100;
                    }
                    // If player health is less than 100
                    else
                    {
                        // Increase health by the respective HPIncrease of food
                        Health += (go as Food).HPIncrease;
                    }
                }
                // If game object is a weapon
                else if (go is Weapon)
                {
                    // Remove weapon from inventory
                    Inventory.RemoveAt(i - 1);

                    // If there is no equipped weapon
                    if (Equipped == null)
                    {
                        // Equipp chosen weapon
                        Equipped = (go as Weapon);
                    }
                    // If there is a equipped weapon
                    else
                    {
                        // Add previous weapon to inventory
                        Inventory.Add(Equipped as Weapon);

                        // Equipp chosen weapon
                        Equipped = (go as Weapon);
                    }
                }
            }
        }