Esempio n. 1
0
    // Randomly picks items from the list and adds them to the inventory.
    private void RandomAdd(List <ItemContainer> itemToAdd, int howMany)
    {
        int random = Random.Range(0, itemToAdd.Count);

        for (int i = 0; i < howMany; i++)
        {
            //  Picks a random item
            ItemContainer temp = itemToAdd[random];

            /*
             *  If the item is already in the inventory, then randomly pick another item
             *  until its an item that doesn't exist in the inventory already.
             */
            while (inv.FindItemByContainer(temp) != null)
            {
                random = Random.Range(0, itemToAdd.Count);
                temp   = itemToAdd[random];
                if (inv.FindItemByContainer(temp) == null)
                {
                    break;
                }
            }

            //  Adds the item to the inventory.
            inv.AddItem(itemToAdd[random]);
        }
    }
    // parsing the text entered into the input fields then cloning the item from the player inventory.
    // the cloned items quantity is changed to the input amount and then its added to the items to sell
    // inventory.
    private bool ParseAndAdd(int index, string text)
    {
        // Clear the HUD output warning.
        outputWarning.text = "";

        ItemContainer item = currInv.GetItemFromIndex(index);

        if (text == "" || text == "0")
        {
            return(false);
        }

        if (item == null)
        {
            outputWarning.text = "ERROR: Item doesn't exist?";
            return(false);
        }

        if (item.Price == 0)
        {
            outputWarning.text = string.Format("Item {0} cannot be sold.\n", item.Name);
            return(false);
        }
        else
        {
            int i;

            if (int.TryParse(text, out i))
            {
                if (i > 0)
                {
                    ItemContainer clone = new ItemContainer(item)
                    {
                        Value = i
                    };
                    buyAndSellItems.AddItem(clone);
                    return(true);
                }
                outputWarning.text = string.Format("Invalid amount entered for: {0}", item.Name);
                return(false);
            }
            outputWarning.text = string.Format("Invalid input entered for: {0}", item.Name);
            return(false);
        }
    }
Esempio n. 3
0
    static void Main()
    {
        //declare necessary variables
        uint MenuSelect;
        bool Continue = true;
        //display menu
        InventoryManagement Inv = new InventoryManagement();

        // use the code below for setting up a test inventory
        ///*
        Inv.AddItem(323, "Green Pens", 1.50m, 20, 0.75m, 30m);
        Inv.AddItem(657, "Red Pens", 1.50m, 20, 0.75m, 30m);
        Inv.AddItem(846, "Orange Pens", 1.50m, 30, 0.75m, 45m);
        Inv.AddItem(325, "Purple Pens", 1.50m, 45, 0.75m, 67.5m);
        Inv.AddItem(987, "Yellow Pens", 1.50m, 33, 0.75m, 49.5m);
        Inv.AddItem(654, "Black Pens", 1.00m, 100, 0.50m, 100m);
        //*/

        while (Continue)
        {
            Inv.DisplayMenu();
            //read input for menu selection
            string MenuStr = Console.ReadLine();
            MenuSelect = uint.Parse(MenuStr);

            //set cases to call appropriate frunction from InventoryManagement
            switch (MenuSelect)
            {
            case 1:                                                                     //Add an item
            {
                Console.Write("Please enter the item number(3 digits): ");              //intruction 1
                uint Inum = uint.Parse(Console.ReadLine());                             //take user input

                Console.Write("Please enter the item's description (20 characters): "); //intruction 2
                string IDesc = Console.ReadLine();                                      //take user input

                Console.Write("Please enter the item's sale price: ");                  //intruction 3
                decimal IPrice = decimal.Parse(Console.ReadLine());                     //take user input

                Console.Write("Please enter the quantity of items: ");                  //intruction 4
                uint IQuant = uint.Parse(Console.ReadLine());                           //take user input

                Console.Write("Please enter the cost per item: ");                      //intruction 5
                decimal ICost = decimal.Parse(Console.ReadLine());                      //take user input
                decimal IVal  = IPrice * IQuant;                                        //calculate the item value
                Inv.AddItem(Inum, IDesc, IPrice, IQuant, ICost, IVal);                  //store the item value
                break;
            }

            case 2:                                                                     //change an item
            {
                Console.Write("Please enter the item number(3 digits): ");              //intruction 1
                uint Inum = uint.Parse(Console.ReadLine());                             //take user input

                Console.Write("Please enter the item's description (20 characters): "); //intruction 2
                string IDesc = Console.ReadLine();                                      //take user input

                Console.Write("Please enter the item's sale price: ");                  //intruction 3
                decimal IPrice = decimal.Parse(Console.ReadLine());                     //take user input

                Console.Write("Please enter the quantity of items: ");                  //intruction 4
                uint IQuant = uint.Parse(Console.ReadLine());                           //take user input

                Console.Write("Please enter the cost per item: ");                      //intruction 5
                decimal ICost = decimal.Parse(Console.ReadLine());                      //take user input
                decimal IVal  = IPrice * IQuant;                                        //calculate the item value
                Inv.ChangeItem(Inum, IDesc, IPrice, IQuant, ICost, IVal);               //store the item value
                break;
            }

            case 3:                                                        //delete an item
            {
                Console.Write("Please enter the item number(3 digits): "); //intruction 1
                uint Inum = uint.Parse(Console.ReadLine());                //take user input
                Inv.DeleteItem(Inum);
                break;
            }

            case 4:     //list all items from inventory
            {
                //Display Entire Inventory
                Console.WriteLine("Item#  ItemID  Description           Price   QOH  Cost    Value     ");
                Console.WriteLine("-----  ------  --------------------  ------  ---  ------  ----------");
                Inv.PrintItems();
                Console.WriteLine("");
                break;
            }

            case 5:     //quit the application
            {
                //execute Menu item 5
                Continue = false;
                break;
            }

            default:
            {
                //Invalid selection handling
                Console.WriteLine("Please select a valid menu option...");
                break;
            }
            }
        }
    }