예제 #1
0
        /// <summary>
        /// Displays vending machine inventory as a list. Items with no remaining
        /// stock are displayed as "SOLD OUT!"
        /// </summary>
        private void DisplayVendingItemsList()
        {
            Console.Clear();

            string[] slots = VendoMatic500.Slots;
            foreach (string slot in slots)
            {
                VendableItems item = VendoMatic500.GetItemAtSlot(slot);
                if (item.AmountRemaining > 0)
                {
                    Console.WriteLine($"{slot,-4} {item.Name,-19} ${item.Cost}");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine($"{slot,-4} {item.Name,-19} SOLD OUT!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            Console.WriteLine();
        }
예제 #2
0
        /// <summary>
        /// Displays vending machine inventory as a list. Items with no remaining
        /// stock are displayed as "SOLD OUT!"
        /// </summary>
        private void DisplayVendingItemsGrid()
        {
            Console.Clear();

            string[] slots = VendoMatic500.Slots;
            Console.WriteLine("----------------------------------------------------------------------------------------");
            foreach (char c in "ABCD".ToCharArray())
            {
                for (int s = 1; s < 5; s++)
                {
                    string address = c.ToString() + s.ToString();

                    VendableItems item = VendoMatic500.GetItemAtSlot(address);

                    if (item.AmountRemaining > 0)
                    {
                        Console.Write($"|   {address,-17}|");
                    }
                    else
                    {
                        Console.Write("|");
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write($"   {address,-17}");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("|");
                    }
                }
                Console.WriteLine();

                for (int s = 1; s < 5; s++)
                {
                    string address = c.ToString() + s.ToString();

                    VendableItems item = VendoMatic500.GetItemAtSlot(address);

                    if (item.AmountRemaining > 0)
                    {
                        Console.Write($"| {item.Name,-19}|");
                    }
                    else
                    {
                        Console.Write("|");
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write($" {item.Name,-19}");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("|");
                    }
                }
                Console.WriteLine();

                for (int s = 1; s < 5; s++)
                {
                    string address = c.ToString() + s.ToString();

                    VendableItems item = VendoMatic500.GetItemAtSlot(address);
                    if (item.AmountRemaining > 0)
                    {
                        Console.Write($"|  {item.Cost.ToString("C"),-18}|");
                    }
                    else
                    {
                        Console.Write("|");
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write($"    SOLD OUT!       ");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("|");
                    }
                }
                Console.WriteLine();
                Console.WriteLine("----------------------------------------------------------------------------------------");
            }

            Console.WriteLine();
        }