示例#1
0
        public void MerchantMenu(string plumbusSelect, string goldSelect, string ammoSelect, string weaponsSelect, string waterSelect, int menuItems)
        {
            Planet planet = new Planet();
            Story  story  = new Story();

            int index = 0;

            string[] menu = new string[] { plumbusSelect, goldSelect, ammoSelect, weaponsSelect, waterSelect };

            ConsoleKeyInfo ckey;
            string         selection;

            Console.CursorVisible = false;
            do
            {
                for (int i = 0; i < menuItems; i++)
                {
                    if (i == index)
                    {
                        Console.BackgroundColor = ConsoleColor.Gray;
                        Console.ForegroundColor = ConsoleColor.Black;

                        Console.WriteLine(menu[i]);
                    }

                    else
                    {
                        Console.WriteLine(menu[i]);
                    }
                    Console.ResetColor();
                    selection = menu[i];
                }

                ckey = Console.ReadKey();

                if (ckey.Key == ConsoleKey.DownArrow)
                {
                    if (index == menu.Length - 1)
                    {
                        index = 0;

                        // Console.BackgroundColor = ConsoleColor.Blue;
                    }
                    else
                    {
                        index++;
                    }
                }

                if (ckey.Key == ConsoleKey.UpArrow)
                {
                    if (index == 0)
                    {
                        index = menu.Length - 1;
                    }
                    else
                    {
                        index--;
                    }
                }
                if (ckey.Key == ConsoleKey.Enter && menu[index] == "Plumbus")
                {
                    Inventory(0);
                }
                else if (ckey.Key == ConsoleKey.Enter && menu[index] == "Gold")
                {
                    Inventory(0);
                }
                else if (ckey.Key == ConsoleKey.Enter && menu[index] == "Ammo")
                {
                    Inventory(0);
                }
                else if (ckey.Key == ConsoleKey.Enter && menu[index] == "Weapons")
                {
                    Inventory(0);
                }
                else if (ckey.Key == ConsoleKey.Enter && menu[index] == "Water")
                {
                    Inventory(0);
                }
                else if (ckey.Key == ConsoleKey.Backspace)
                {
                    ;
                }
                choice.ClearLine();
            } while (ckey.Key != ConsoleKey.Escape);
        }