Exemple #1
0
        static void Main(string[] args)
        {
            Workbench crafter = new Workbench();

            Material[] materials = crafter.GetMaterials();
            //    crafter.reciept = new Material[9] { materials[0], materials[0], materials[0], null, materials[0], null, null, materials[0], null };
            int  materialID  = 0;
            int  materialPos = 0;
            int  menu        = 0;
            bool parseResult = false;

            while (true)
            {
                Console.Clear();
                crafter.DrawWorkBench();
                switch (menu)
                {
                case 0:
                {
                    Console.WriteLine("Выберите действие:");
                    Console.WriteLine("1. Добавить в верстак материал.");
                    Console.WriteLine("2. Скрафтить.:");
                    Console.WriteLine("3. Очистить вестак:");
                    Console.Write("(root):>");
                    parseResult = int.TryParse(Console.ReadLine(), out menu);
                    break;
                }

                case 1:
                {
                    Console.WriteLine("Выберите материал:");
                    Console.WriteLine("0. Дерево");
                    Console.WriteLine("1. Камень");
                    Console.WriteLine("2. Мифрил");
                    Console.WriteLine("3. Золото");
                    Console.WriteLine("4. Метал");
                    Console.Write("(root):>");
                    parseResult = int.TryParse(Console.ReadLine(), out materialID);
                    if (!parseResult)
                    {
                        break;
                    }
                    if (materialID > 5)
                    {
                        break;
                    }

                    Console.WriteLine("Выберите позицию для материала: ");
                    Console.Write("(root):>");
                    parseResult = int.TryParse(Console.ReadLine(), out materialPos);
                    if (!parseResult)
                    {
                        break;
                    }
                    crafter.AddMaterial(materials[materialID], materialPos);
                    menu = 0;
                    break;
                }

                case 2:
                {
                    Tool newTool;
                    if (crafter.TryCraft(out newTool))
                    {
                        Console.WriteLine("Успешно: \n Получился: ");
                        Console.WriteLine(newTool.name);
                    }
                    else
                    {
                        Console.WriteLine("Неверный рецепт");
                    }
                    Console.ReadKey();
                    menu = 0;
                    break;
                }

                case 3:
                {
                    crafter.Reset();
                    menu = 0;
                    break;
                }

                default:
                    break;
                }
            }
        }
Exemple #2
0
        public void ShowCraftingTable()
        {
            int column = 3;
            int row    = 3;
            int zero   = 0;
            int one    = 1;
            int two    = 2;

            Workbench[,] workbench = new Workbench[row, column];
            ConsoleKey key;

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    workbench[i, j] = new Workbench();
                }
            }

            SetCursorPosition(0, 3);
            ForegroundColor = ConsoleColor.Green; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");
            ForegroundColor = ConsoleColor.Green; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.Green; Write($"#  {workbench[zero, zero].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; Write($"#  {workbench[zero, one].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; WriteLine($"#  {workbench[zero, two].ResourceNumber}   #");
            ForegroundColor = ConsoleColor.Green; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.Green; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");

            ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");
            ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.White; Write($"#  {workbench[one, zero].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; Write($"#  {workbench[one, one].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; WriteLine($"#  {workbench[one, two].ResourceNumber}   #");
            ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");

            ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");
            ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.White; Write($"#  {workbench[two, zero].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; Write($"#  {workbench[two, one].ResourceNumber}   #"); ForegroundColor = ConsoleColor.White; WriteLine($"#  {workbench[two, two].ResourceNumber}   #");
            ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; Write("#      #"); ForegroundColor = ConsoleColor.White; WriteLine("#      #");
            ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; Write("########"); ForegroundColor = ConsoleColor.White; WriteLine("########");

            do
            {
                key = ReadKey().Key;
                if (key == ConsoleKey.UpArrow && posY != 0)
                {
                    posY--;
                }

                else if (key == ConsoleKey.DownArrow && posY != 2)
                {
                    posY++;
                }

                else if (key == ConsoleKey.LeftArrow && posX != 0)
                {
                    posX--;
                }

                else if (key == ConsoleKey.RightArrow && posX != 2)
                {
                    posX++;
                }

                else if (key == ConsoleKey.Enter)
                {
                    resurse = ChoiceOfResource();
                    workbench[posY, posX] = workbench[posY, posX] + resurse;
                }

                SetCursorPosition(0, 3);
                ForegroundColor = posX == 0 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");
                ForegroundColor = posX == 0 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[zero, zero].ResourceNumber}   #"); ForegroundColor = posX == 1 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[zero, one].ResourceNumber}   #"); ForegroundColor = posX == 2 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; WriteLine($"#  {workbench[zero, two].ResourceNumber}   #");
                ForegroundColor = posX == 0 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 0 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");

                ForegroundColor = posX == 0 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");
                ForegroundColor = posX == 0 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[one, zero].ResourceNumber}   #"); ForegroundColor = posX == 1 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[one, one].ResourceNumber}   #"); ForegroundColor = posX == 2 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; WriteLine($"#  {workbench[one, two].ResourceNumber}   #");
                ForegroundColor = posX == 0 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 1 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");

                ForegroundColor = posX == 0 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");
                ForegroundColor = posX == 0 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[two, zero].ResourceNumber}   #"); ForegroundColor = posX == 1 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write($"#  {workbench[two, one].ResourceNumber}   #"); ForegroundColor = posX == 2 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; WriteLine($"#  {workbench[two, two].ResourceNumber}   #");
                ForegroundColor = posX == 0 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 1 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("#      #"); ForegroundColor = posX == 2 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("#      #");
                ForegroundColor = posX == 0 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 1 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; Write("########"); ForegroundColor = posX == 2 && posY == 2 ? ConsoleColor.Green : ConsoleColor.White; WriteLine("########");
            }while (key != ConsoleKey.Escape);
        }