예제 #1
0
        private static void FindItem()
        {
            Item           targetItem = ManageMaterial.SetItems(true).First();   //TODO заменить функцию выбора предмета.
            List <Summary> summaries  = new List <Summary> {
                new Summary
                {
                    Id      = targetItem.Id,
                    Outcome = targetItem.Amount,
                    Name    = Material.GetMaterial(targetItem.Id).Name          //TODO добавить в Item функцию получения материала.
                }
            };

            List <Factory> factories = new List <Factory>();

            bool repeat;

            do
            {
                repeat = false;

                for (int s = 0; s < summaries.Count; s++)
                {
                    if (summaries[s].Blocked || summaries[s].Conveyor)
                    {
                        continue;
                    }

                    Summary summary = summaries[s];
                    double  ratio   = summary.Income - summary.Outcome;

                    if (ratio < 0)
                    {
                        repeat = true;

                        //===== INPUT/OUTPUT BLOCK =====//
                        int           inputOutputsIndex = 0;
                        InputOutput[] inputOutputs      = InputOutput.InputsOutputs.Where(io => io.Outputs != null && io.Outputs.Count(it => it.Id == summary.Id) != 0).ToArray();

                        if (inputOutputs.Length == 0)
                        {
                            inputOutputsIndex = -1;
                        }
                        else if (inputOutputs.Length > 0)
                        {
                            int offset = 2;
                            int select;

                            do
                            {
                                Console.WriteLine("╔═╤═╤═╡ SELECT FACTORY ({0}) ╞═════", summary.Name.ToUpper());
                                Console.WriteLine("║0├─┤ Exit");
                                Console.WriteLine("║1├─┤ Conveyor");
                                for (int io = 0; io < inputOutputs.Length; io++)
                                {
                                    Console.WriteLine("║{0}├─┤ {1}", io + offset, inputOutputs[io].ToString());
                                }
                                Console.WriteLine("╚═╧═╧════════════════════════");
                                Console.Write("> ");
                                select = Formations.GetInt(Console.ReadKey().KeyChar.ToString());
                                Console.Clear();

                                if (select == 0)
                                {
                                    return;
                                }
                                else if (select == 1)
                                {
                                    inputOutputsIndex = -1;
                                    break;
                                }
                                else if (select >= offset && select <= inputOutputs.Length + offset)
                                {
                                    inputOutputsIndex = select - offset;
                                    break;
                                }
                                else
                                {
                                    Formations.NotFound("Action");
                                }
                            }while (true);
                        }

                        if (inputOutputsIndex == -1)
                        {
                            double select = 0;

                            Console.WriteLine("═════╡ ENTER AMOUNT OF {0} ╞═════", summary.Name.ToUpper());
                            Console.Write("> ");
                            select = Formations.GetDouble(Console.ReadLine());
                            Console.Clear();

                            if (select <= 0)
                            {
                                return;
                            }

                            summary.Income   = select;
                            summary.Conveyor = true;

                            continue;
                        }

                        InputOutput inputOutput = inputOutputs[inputOutputsIndex];
                        General     general     = inputOutput.GetGeneral;

                        //===== FACTORY BLOCK =====//
                        Factory factory = new Factory {
                            Id     = general.Id,
                            Name   = general.Name,
                            Amount = Math.Ceiling(Math.Abs(ratio) / inputOutput.OutputsPerSecond.Where(ops => ops.Id == summary.Id).First().Amount),
                            Input  = inputOutput.InputsPerSecond,
                            Output = inputOutput.OutputsPerSecond,
                            Ratio  = 1
                        };

                        summaries = EditSummaries(summaries, factory);

                        if (factories.Count(fc => fc.Id == factory.Id) != 0)
                        {
                            Factory existFactory = factories.Where(fc => fc.Id == factory.Id).First();

                            existFactory.Amount += factory.Amount;
                        }
                        else
                        {
                            factories.Add(factory);
                        }
                    }
                }
            }while (repeat);

            CorrectSchematic(summaries, factories);
        }
예제 #2
0
        public static Item[] SetItems(bool onlyOne = false)
        {
            int offset = 3;

            string[]    input;
            double      amount;
            int         select;
            List <Item> items = new List <Item>();

            Material[] materials = Material.Materials;

            do
            {
                Console.WriteLine("╔═╤═╤═╡ SET ITEMS ╞═════╗");
                Console.WriteLine("║0├─┤ Cancel            ║");
                Console.WriteLine("║1├─┤ Set Null          ║");
                Console.WriteLine("║2├─┤ Done              ║");
                Console.WriteLine("╠═╧═╧═══════════════════╝");
                Console.WriteLine("║Result: {0}", string.Join(", ", items)); //show result
                Console.WriteLine("╚════════════════════════");
                ShowAll(offset, materials);                                  //Show items

                Console.Write("> ");
                input = Console.ReadLine().Split(' ');
                Console.Clear();

                select = Formations.GetInt(input.First());

                if (input.Length == 2)
                {
                    amount = Formations.GetDouble(input.Last());
                }
                else
                {
                    amount = 0;
                }

                if (select == 0)
                {
                    return(null);                             //Cancel
                }
                else if (select == 1)
                {
                    return(null);                                  //Set Null
                }
                else if (select == 2)
                {
                    return(items.ToArray());                                  //Done
                }
                else if (select >= offset && select < materials.Length + offset)
                {
                    bool repeat;                     //If result have error
                    do
                    {
                        repeat  = false;                        //No repeat do_while
                        select -= offset;                       //delete offset

                        if (amount == 0)
                        {
                            Console.WriteLine("══════╡ ENTER {0} ╞══════", materials[select].Name.ToUpper());
                            Console.Write("> ");
                            amount = Formations.GetDouble(Console.ReadLine());                             //Get amount of items
                            Console.Clear();
                        }

                        if (amount > 0)
                        {
                            items.Add(new Item {
                                Id = materials[select].Id, Amount = amount
                            });
                        }
                        else if (amount == 0)
                        {
                            break;
                        }
                        else
                        {
                            Formations.NotCorrect("Amount");
                            repeat = true;                             //Repeat do_while
                        }
                    }while (repeat);
                }                 //Select item
                else
                {
                    Formations.NotCorrect("Action");                  //Error
                }
                if (onlyOne && items != null)
                {
                    return(items.ToArray());
                }
            }while (true);
        }
예제 #3
0
        //REFACTORING
        public static string SetItems()
        {
            int offset = 3;

            string[] input;
            double   amount;
            int      select;
            string   items = string.Empty;

            General[] generals = General.Generals;

            do
            {
                Console.WriteLine("╔═╤═╤═╡ SET ITEMS ╞═════╗");
                Console.WriteLine("║0├─┤ Cancel            ║");
                Console.WriteLine("║1├─┤ Set Null          ║");
                Console.WriteLine("║2├─┤ Done              ║");
                Console.WriteLine("╠═╧═╧═══════════════════╝");
                ShowAll(offset);                 //Show items

                Console.Write("> ");
                input = Console.ReadLine().Split(' ');
                Console.Clear();

                select = Formations.GetInt(input.First());
                amount = Formations.GetDouble(input.Last());

                if (select == 0)
                {
                    return("");                             //Cancel
                }
                else if (select == 1)
                {
                    return(null);                                  //Set Null
                }
                else if (select == 2)
                {
                    return(items == string.Empty ? null : items);                                  //Done
                }
                else if (select >= offset && select < generals.Length + offset)
                {
                    bool repeat;                     //If result have error
                    do
                    {
                        repeat  = false;                        //No repeat do_while
                        select -= offset;                       //delete offset

                        if (amount == 0)
                        {
                            Console.WriteLine("══════╡ ENTER {0} ╞══════", generals[select].Name.ToUpper());
                            Console.Write("> ");
                            amount = Formations.GetDouble(Console.ReadLine());                             //Get amount of items
                        }

                        Console.Clear();

                        if (amount > 0)
                        {
                            if (items != string.Empty)
                            {
                                items += ";";
                            }
                            items += generals[select].Id + " " + amount.ToString();
                        }
                        else if (amount == 0)
                        {
                            break;
                        }
                        else
                        {
                            Formations.NotCorrect("Amount");
                            repeat = true;                             //Repeat do_while
                        }
                    }while (repeat);
                }                 //Select item
                else
                {
                    Formations.NotCorrect("Action");                  //Error
                }
                if (items != string.Empty)
                {
                    return(items);
                }
            }while (true);
        }