Example #1
0
 public Player(string name, int level, int job)
 {
     _name = name;
     _level = level;
     _job = job;
     _inventory = new Inventory(this, 20);
     _questLog = new QuestLog();
 }
Example #2
0
        protected void ShowRemoveFromInventory(Inventory inventory)
        {
            bool exit = false;
            while (!exit)
            {
                if (inventory.IsEmpty())
                {
                    Console.WriteLine("This inventory is empty.");
                    return;
                }

                ListInventoryItems(inventory);

                Console.WriteLine("Type 'done' when you are finished removing.");
                int itemId = GetIntInput("Enter item id> ", "done");
                if (itemId > 0)
                {
                    if (inventory.HasItem(itemId))
                    {
                        Console.WriteLine("Type 'all' to remove all.");
                        int amount = GetIntInput("Enter the amount to remove> ", "all");
                        if (amount > 0)
                        {
                            if (inventory.GainItem(itemId, -amount))
                                Console.WriteLine("{0} of item {1} has been removed.", amount, itemId);
                            else
                                Console.WriteLine("Could not remove {0} of item {1}.", amount, itemId);
                        }
                        else if (amount == -1)
                        {
                            amount = inventory.Count(itemId);
                            if (inventory.GainItem(itemId, -amount))
                                Console.WriteLine("All {0} of item {1} has been removed.", amount, itemId);
                            else
                                Console.WriteLine("Could not remove all of item {0}.", itemId);
                        }
                        else
                        {
                            Console.WriteLine("That is an invalid amount.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("This inventory does not contain any {0}.", itemId);
                    }
                }
                else if (itemId == -1)
                {
                    exit = true;
                }
                else
                {
                    Console.WriteLine("Incorrect item id.");
                }
                Console.WriteLine();
            }
        }
Example #3
0
 protected void ShowInventory(Inventory inventory)
 {
     bool exit = false;
     while (!exit)
     {
         Console.WriteLine("Modify Inventory");
         int selection = ShowMenu("List Items",
                 "Add Items",
                 "Remove Items",
                 "Clear Items",
                 "Return to Modify Player");
         switch (selection)
         {
             case 1:
                 ListInventoryItems(inventory);
                 break;
             case 2:
                 ShowAddToInventory(inventory);
                 break;
             case 3:
                 ShowRemoveFromInventory(inventory);
                 break;
             case 4:
                 ShowClearFromInventory(inventory);
                 break;
             case 5:
                 exit = true;
                 break;
         }
         Console.WriteLine();
     }
 }
Example #4
0
        protected void ShowClearFromInventory(Inventory inventory)
        {
            bool exit = false;
            while (!exit)
            {
                if (inventory.IsEmpty())
                {
                    Console.WriteLine("This inventory is empty.");
                    return;
                }
                ListInventoryItems(inventory);

                Console.WriteLine("Type 'done' when you are finished clearing.");
                int itemId = GetIntInput("Enter an item id> ", "done");
                if (itemId > 0)
                {
                    if (inventory.HasItem(itemId))
                    {
                        int count = inventory.Count(itemId);
                        inventory.ClearItem(itemId);
                        Console.WriteLine("All {0} of item {1} have been cleared.", count, itemId);
                    }
                    else
                    {
                        Console.WriteLine("This inventory does not contain any {0}.", itemId);
                    }
                }
                else if (itemId == -1)
                {
                    exit = true;
                }
                else
                {
                    Console.WriteLine("Incorrect item id.");
                }
                Console.WriteLine();
            }
        }
Example #5
0
        protected void ShowAddToInventory(Inventory inventory)
        {
            int itemId = 0;
            while (itemId != -1)
            {
                ListInventoryItems(inventory);

                Console.WriteLine("Type 'done' when you are finished adding.");
                itemId = GetIntInput("Enter an item id> ", "done");
                if (itemId > 0)
                {
                    bool getAmount = true;
                    while (getAmount)
                    {
                        int amount = GetIntInput("Enter an amount for (" + itemId + ")> ", "done");
                        if (amount > 0)
                        {
                            if(inventory.GainItem(itemId, amount))
                                Console.WriteLine("{0} of item {1} has been added.", amount, itemId);
                            else
                                Console.WriteLine("Could not add {0} of item {1}.", amount, itemId);
                            getAmount = false;
                        }
                        else if (amount == -1)
                        {
                            if (inventory.GainItem(itemId, 1))
                                Console.WriteLine("1 of item {0} has been added.", itemId);
                            else
                                Console.WriteLine("Could not add 1 of item {0}.", itemId);

                            getAmount = false;
                            itemId = -1;
                        }
                        else
                        {
                            Console.WriteLine("That is an incorrect amount.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("That is an incorrect item id.");
                }
            }
        }
Example #6
0
        protected void ListInventoryItems(Inventory inventory)
        {
            Console.WriteLine("Inventory Items");

            int columns = 4;
            int colWidth = 19;

            for (int row = 0; row < inventory.Items.Length / columns; row++)
            {
                for (int column = 0; column < columns; column++)
                {
                    int index = (row * columns) + column;
                    Item item = inventory.Items[index];
                    Console.Write(Width(string.Format("{0})", index + 1), 4));
                    if (item != null)
                    {
                        Console.Write(Width(string.Format("{0} x {1}", item.ID, item.Amount), colWidth - 4));
                    }
                    else
                    {
                        Console.Write(Width("[Empty]", colWidth - 4));
                    }
                }
                Console.WriteLine();
            }
        }