Example #1
0
        public static string SetMod()
        {
            int offset = 1;
            int select;

            do
            {
                Console.WriteLine("╔═╤╤═╡ SET MOD ╞════╗");
                Console.WriteLine("║0├┤ Cancel         ║");
                for (int i = 0; i < Mod.Count; i++)
                {
                    Console.WriteLine("║{0}├┤ {1,14} ║", i + offset, Mod.Mods[i].ToString().PadRight(14, ' '));
                }
                Console.WriteLine("╚═╧╧════════════════╝");
                Console.Write("> ");
                select = Formations.GetInt(Console.ReadLine());
                Console.Clear();

                if (select == 0)
                {
                    return(null);
                }
                else if (select >= offset && select < Mod.Count + offset)
                {
                    return(Mod.Mods[select - offset].Id);
                }
                else
                {
                    Formations.NotCorrect("Action");
                }
            }while (true);
        }
Example #2
0
        static bool EnterPassword()
        {
            Console.WriteLine("════╡ ENTER PASSWORD ╞════");
            Console.Write("> ");
            string password = Console.ReadLine();

            Console.Clear();

            if (password == "fox")
            {
                return(true);
            }
            else
            {
                Formations.NotCorrect("Password");
            }

            return(false);
        }
Example #3
0
        public static void Menu()
        {
            int offset = 3;
            int select;

            do
            {
                Console.WriteLine("╔═╤═╤═╡ MATERIAL MENU ╞═════╗");
                Console.WriteLine("║0├─┤ Exit                  ║");
                Console.WriteLine("║1├─┤ Insert                ║");
                Console.WriteLine("║2├─┤ Reset                 ║");
                Console.WriteLine("╚═╧═╧═══════════════════════╝");
                ShowAll(offset);

                Console.Write("> ");
                select = Formations.GetInt(Console.ReadLine());
                Console.Clear();

                if (select == 0)
                {
                    return;
                }
                else if (select == 2)
                {
                    Material.ResetAll();
                }
                else if (select >= offset && select < Material.Count + offset)
                {
                    Select(Material.Materials[select - offset]);
                }
                else if (select > 0)
                {
                    Select(new Material {
                        Id = Material.NextId
                    });
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #4
0
        public static void Menu()
        {
            int offset = 2;
            int select;

            do
            {
                Console.WriteLine("╔═╤═╤═╡ BUILDING MENU ╞═════╗");
                Console.WriteLine("║0├─┤Exit                   ║");
                Console.WriteLine("║1├─┤Insert                 ║");
                Console.WriteLine("╚═╧═╧═══════════════════════╝");
                ShowAll(offset);

                Console.Write("> ");
                select = Formations.GetInt(Console.ReadLine());
                Console.Clear();

                if (select == 0)
                {
                    return;
                }
                else if (select >= offset && select < General.Count + offset)
                {
                    Update(General.Generals[select - offset].Id);
                }
                else if (select > 0)
                {
                    string id = General.NextId;
                    ManageGeneral.Update(new General {
                        Id = id
                    });
                    Update(id);
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #5
0
        private static string SetInputOutput(InputOutput[] inputOutputs)
        {
            int offset = 2;
            int select;

            do
            {
                Console.WriteLine("╔═══╤╤═╡ SET ITEMS ╞══════╗");
                Console.WriteLine("║ 0 ├┤ Cancel             ║");
                Console.WriteLine("║ 1 ├┤ Set Null           ║");
                Console.WriteLine("╚═══╧╧════════════════════╝");

                for (int i = 0; i < inputOutputs.Length; i++)
                {
                    Console.WriteLine("║{0}├┤ {1}", i + offset, inputOutputs[i]);
                }

                Console.Write("> ");
                select = Formations.GetInt(Console.ReadLine());
                Console.Clear();

                if (select == 0)
                {
                    return("");
                }
                else if (select == 1)
                {
                    return(null);
                }
                else if (select >= offset && select < inputOutputs.Length + offset)
                {
                    return(inputOutputs[select - offset].Id);
                }
                else
                {
                    Formations.NotCorrect("Action");
                }
            }while (true);
        }
Example #6
0
        public static string SetType(string kind)
        {
            int offset = 1;
            int select;

            TypeItem[] typeItems = TypeItem.GetKind(kind);
            if (typeItems.Length == 0)
            {
                return(null);
            }

            do
            {
                Console.WriteLine("╔══╤╤═╡ SET MOD ╞═════╗");
                Console.WriteLine("║0 ├┤ Cancel          ║");
                for (int i = 0; i < typeItems.Length; i++)
                {
                    Console.WriteLine("║{0,2}├┤ {1,15} ║", (i + offset).ToString().PadRight(2, ' '), typeItems[i].ToString().PadRight(15, ' '));
                }
                Console.WriteLine("╚══╧╧═════════════════╝");
                Console.Write("> ");
                select = Formations.GetInt(Console.ReadLine());
                Console.Clear();

                if (select == 0)
                {
                    return(null);
                }
                else if (select >= offset && select < typeItems.Length + offset)
                {
                    return(typeItems[select - offset].Id);
                }
                else
                {
                    Formations.NotCorrect("Action");
                }
            }while (true);
        }
Example #7
0
        private static void Select(Material material)
        {
            char select;

            do
            {
                Console.WriteLine("╔═╤═╤═══╡ {0}. {1} ╞════════", material.Id, material.Name.ToUpper());
                Console.WriteLine("║0├─┤ Exit");
                Console.WriteLine("║1├─┤ Change name");
                Console.WriteLine("║2├─┤ Type: {0}", material.GetTypeMaterial);
                Console.WriteLine("║3├─┤ Mod: {0}", material.GetMod);
                Console.WriteLine("║4├─┤ Color: {0}", material.Color);

                string ProducedIn = string.Join(", ", General.Generals.Where(gen => InputOutput.InputsOutputs.Count(io => io.Outputs != null && io.GeneralId == gen.Id && io.Outputs.Count(it => it.Id == material.Id) != 0) != 0).Select(sel => sel.Name));
                Console.WriteLine("║ ├─┤ Produced in: {0}", ProducedIn);

                string RequiredFor = string.Join(", ", General.Generals.Where(gen => InputOutput.InputsOutputs.Count(io => io.Inputs != null && io.GeneralId == gen.Id && io.Inputs.Count(it => it.Id == material.Id) != 0) != 0).Select(sel => sel.Name));
                Console.WriteLine("║ ├─┤ Required for: {0}", RequiredFor);

                string UsedToBuild = string.Join(", ", General.Generals.Where(gen => gen.BuildCosts.Count(item => item.Id == material.Id) != 0).Select(sel => sel.Name));
                Console.WriteLine("║ ├─┤ Used to build: {0}", UsedToBuild);
                Console.WriteLine("║8├─┤ Delete");
                Console.WriteLine("║9├─┤ Save");
                Console.WriteLine("╚═╧═╧═════════════════{0}", "═".PadRight(material.Id.Length + material.Name.Length, '═'));

                Console.Write("> ");
                select = Console.ReadKey().KeyChar;
                Console.Clear();

                if (select == '0')
                {
                    return;
                }
                else if (select == '1')
                {
                    material.Name = Formations.GetValue("Name", "string");
                }
                else if (select == '2')
                {
                    string type = ManageType.SetType("Item");
                    if (type != null)
                    {
                        material.Type = type;
                    }
                }
                else if (select == '3')
                {
                    string mod = ManageMod.SetMod();
                    if (mod != null)
                    {
                        material.Mod = mod;
                    }
                }
                else if (select == '4')
                {
                    material.Color = Formations.GetValue("Color", "string");
                }
                else if (select == '8')
                {
                    Console.WriteLine("═════════╡ TO DELETE {0}? (Y - YES)╞═════════", material.Name.ToUpper());
                    Console.Write("> ");
                    select = Console.ReadKey().KeyChar;
                    Console.Clear();

                    if (select.ToString().ToLower() == "y")
                    {
                        material.Delete();
                        return;
                    }
                }
                else if (select == '9')
                {
                    material.Save(); return;
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #8
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);
        }
Example #9
0
        public static void Update(General general)
        {
            char select;

            do
            {
                Console.WriteLine("═════════╡ GENERAL ╞═════════");
                Console.WriteLine("ID: {0}", general.Id);
                Console.WriteLine("[1] Name: {0}", general.Name);
                Console.WriteLine("[2] Type: {0}", general.GetTypeMaterial);
                Console.WriteLine("[3] Description: {0}", general.Description);
                Console.WriteLine("[4] Health: {0}", general.Health);
                Console.WriteLine("[5] Size: {0}", general.Size);
                Console.WriteLine("[6] Build Time: {0}", general.BuildTime);
                Console.WriteLine("[7] Build Cost: {0}", general.BuildCosts);
                Console.WriteLine("[8] Mod: {0}", general.GetMod);
                Console.WriteLine("Weight: {0}", general.Weight);
                Console.WriteLine("[9] Save");
                Console.WriteLine("[0] Exit");

                Console.Write("> ");
                select = Console.ReadKey().KeyChar;
                Console.Clear();

                if (select == '0')
                {
                    bool allCorrect = true;

                    General targetGeneral = General.GetGeneral(general.Id);

                    if (targetGeneral != null && general.Name != targetGeneral.Name || general.Type != targetGeneral.Type || general.BuildCosts != targetGeneral.BuildCosts || general.Mod != targetGeneral.Mod)
                    {
                        allCorrect = false;
                    }
                    else if (general.Name != null || general.Type != null || general.BuildCosts != null || general.Mod != null)
                    {
                        allCorrect = false;
                    }

                    if (allCorrect)
                    {
                        return;
                    }
                    else
                    {
                        Console.WriteLine("═════════╡ YOU ARE SURE WANT TO EXIT? (Y - YES)╞═════════");
                        Console.Write("> ");
                        select = Console.ReadKey().KeyChar;
                        Console.Clear();

                        if (select.ToString().ToLower() == "y")
                        {
                            return;
                        }
                    }
                }
                else if (select == '1')
                {
                    string name = Formations.GetValue("name", "string");
                    if (name == null)
                    {
                        Formations.NotCorrect("Name");
                        continue;
                    }

                    if (General.Generals.Count(gen => gen.Name == name) != 0)
                    {
                        Console.WriteLine("═════════╡ THIS BUILDING ALREADY EXIST ╞═════════");
                        Console.WriteLine("1. Go to edit");
                        Console.WriteLine("0. Exit");

                        Console.Write("> ");
                        select = Console.ReadKey().KeyChar;
                        Console.Clear();

                        if (select == '1')
                        {
                            Update(General.Generals.Where(gen => gen.Name == name).First());
                            return;
                        }
                    }

                    general.Name = name;
                }
                else if (select == '2')
                {
                    string type = ManageType.SetType("Block");
                    if (type != null)
                    {
                        general.Type = type;
                    }
                }
                else if (select == '3')
                {
                    general.Description = Formations.GetValue("description", "string");
                }
                else if (select == '4')
                {
                    general.Health = Formations.GetValue("health", "int");
                }
                else if (select == '5')
                {
                    general.Size = Formations.GetValue("size", "size");
                }
                else if (select == '6')
                {
                    general.BuildTime = Formations.GetValue("build Time", "double");
                }
                else if (select == '7')
                {
                    Item[] buildCost = ManageMaterial.SetItems();
                    if (buildCost != null)
                    {
                        general.BuildCost = string.Join(";", buildCost.Select(inp => inp.Id + " " + inp.Amount));
                    }
                }
                else if (select == '8')
                {
                    string mod = ManageMod.SetMod();
                    if (mod != null)
                    {
                        general.Mod = mod;
                    }
                }
                else if (select == '9')
                {
                    bool allCorrect = true;

                    if (general.Name == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Name");
                    }
                    if (general.Type == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Type");
                    }
                    if (general.BuildCosts == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Build Cost");
                    }
                    if (general.Mod == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Mod");
                    }

                    if (allCorrect)
                    {
                        general.Save();
                        return;
                    }
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #10
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);
        }
Example #11
0
        static void Main(string[] args)
        {
            SqliteDataAccess.DataAccess();

            bool isAdministrator = false;
            char select;

            do
            {
                Console.WriteLine("╔════════╡ MENU ╞════════╗");
                Console.WriteLine("╟─┐ ┌────────────────────╢");
                Console.WriteLine("║0├─┤Exit                ║");
                Console.WriteLine("║1├─┤Calculator          ║");
                if (isAdministrator)
                {
                    Console.WriteLine("║2├─┤Manager Building    ║");
                    Console.WriteLine("║3├─┤Manager Material    ║");
                    Console.WriteLine("║4├─┤Log Out             ║");
                }
                else
                {
                    Console.WriteLine("║2├─┤Administrator       ║");
                }
                Console.WriteLine("╟─┘ └────────────────────╢");
                Console.WriteLine("╚════════════════════════╝");
                Console.Write("> ");
                select = Console.ReadKey().KeyChar;
                Console.Clear();

                if (select == '0')
                {
                    return;
                }
                else if (select == '1')
                {
                    ManageCalculator.Menu();
                }
                else if (isAdministrator)
                {
                    if (select == '2')
                    {
                        ManageBuilding.Menu();
                    }
                    else if (select == '3')
                    {
                        ManageMaterial.Menu();
                    }
                    else if (select == '4')
                    {
                        isAdministrator = false;
                    }
                    else
                    {
                        Formations.NotFound("Action");
                    }
                }
                else
                {
                    if (select == '2')
                    {
                        isAdministrator = EnterPassword();
                    }
                    else
                    {
                        Formations.NotFound("Action");
                    }
                }
            }while (true);
        }
Example #12
0
        private static void Update(string id)
        {
            string[] select;

            do
            {
                General general = General.GetGeneral(id);
                if (general == null)
                {
                    return;
                }

                InputOutput[] inputsOutputs = general.GetInputOutputs;
                Power[]       powers        = general.GetPowers;

                ShowInfo(id);

                Console.WriteLine("╔═══╤╤╡ UPDATE BUILDING ╞═════╗");
                Console.WriteLine("║ 0 ├┤ Exit                   ║");
                Console.WriteLine("║ 1 ├┤ Edit general           ║");
                Console.WriteLine("╠═══╪╪════════════════════════╝");

                //Power
                Console.WriteLine("║2 0├┤ Add Power");
                for (int i = 0; i < powers.Length; i++)
                {
                    Console.WriteLine("║2 {0}├┤ Edit {1}", i + 1, powers[i]);
                }

                //Input/Output
                Console.WriteLine("║5 0├┤ Add Input/Output");
                for (int i = 0; i < inputsOutputs.Length; i++)
                {
                    Console.WriteLine("║5 {0}├┤ Edit {1}", i + 1, inputsOutputs[i]);
                }

                Console.WriteLine("╠═══╪╪════════════════════════╗");
                Console.WriteLine("║ 8 ├┤ Delete                 ║");
                Console.WriteLine("╚═══╧╧════════════════════════╝");

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

                if (select.First() == "0")
                {
                    return;
                }
                else if (select.First() == "1")
                {
                    ManageGeneral.Update(general);
                }
                else if (select.First() == "2")
                {
                    if (select.Length == 2)
                    {
                        int subaction = Formations.GetInt(select[1]) - 1;

                        if (subaction >= 0 && subaction < inputsOutputs.Length)
                        {
                            ManagePower.Update(powers[subaction]);
                        }
                        else if (subaction == -1)
                        {
                            ManagePower.Update(new Power {
                                Id = Power.NextId, GeneralId = general.Id
                            });
                        }
                        else
                        {
                            Formations.NotFound("SubAction");
                        }
                    }
                    else
                    {
                        Formations.NotFound("SubAction");
                    }
                }
                else if (select.First() == "5")
                {
                    if (select.Length == 2)
                    {
                        int subaction = Formations.GetInt(select[1]) - 1;

                        if (subaction >= 0 && subaction < inputsOutputs.Length)
                        {
                            ManageInputOutput.Update(inputsOutputs[subaction]);
                        }
                        else if (subaction == -1)
                        {
                            ManageInputOutput.Update(new InputOutput(general.Id));
                        }
                        else
                        {
                            Formations.NotFound("SubAction");
                        }
                    }
                    else
                    {
                        Formations.NotFound("SubAction");
                    }
                }
                else if (select.First() == "8")
                {
                    Delete(id);
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #13
0
        private static void ShowInfo(string id)
        {
            //===== GENERAL =====//
            General general = General.GetGeneral(id);

            Console.WriteLine("══════════════╡ {0}. {1} ({2}) ╞══════════════", general.Id, general.Name, general.GetTypeMaterial);
            Console.WriteLine("──────────────────────────────────────────────────\n{0}\n──────────────────────────────────────────────────", general.Description);
            Formations.Header("GENERAL");
            Console.WriteLine(" Health: {0}", general.Health);
            Console.WriteLine(" Size: {0}", general.Size);
            Console.WriteLine(" Build Time: {0}", general.BuildTime);
            Console.WriteLine(" Build Cost: {0}", string.Join(", ", general.BuildCosts.Select(sel => sel.ToString())));
            if (general.Weight != null)
            {
                Console.WriteLine(" Weight: {0}", general.Weight);
            }

            //===== POWER =====//
            Power[] powers = general.GetPowers;

            if (powers.Length != 0)
            {
                Power  powerPrev       = new Power();
                string powerUse        = string.Empty;
                string powerGeneration = string.Empty;
                string powerCapacity   = string.Empty;

                foreach (Power power in powers)
                {
                    if (power.PowerUse != null)
                    {
                        if (powerUse == string.Empty)
                        {
                            powerUse = power.PowerUse;
                        }
                        else if (power.PowerUse != powerPrev.PowerUse)
                        {
                            powerUse += " / " + power.PowerUse;
                        }
                    }
                    if (power.PowerGeneration != null)
                    {
                        if (powerGeneration == string.Empty)
                        {
                            powerGeneration = power.PowerGeneration;
                        }
                        else if (power.PowerGeneration != powerPrev.PowerGeneration)
                        {
                            powerGeneration += " / " + power.PowerGeneration;
                        }
                    }
                    if (power.PowerCapacity != null)
                    {
                        if (powerCapacity == string.Empty)
                        {
                            powerCapacity = power.PowerCapacity;
                        }
                        else if (power.PowerCapacity != powerPrev.PowerCapacity)
                        {
                            powerCapacity += " / " + power.PowerCapacity;
                        }
                    }

                    powerPrev = power;
                }

                Formations.Header("POWER");
                if (powerUse != string.Empty)
                {
                    Console.WriteLine(" Power Use: {0} power units/second", powerUse);
                }
                if (powerGeneration != string.Empty)
                {
                    Console.WriteLine(" Power Generation: {0} power units/second", powerGeneration);
                }
                if (powerCapacity != string.Empty)
                {
                    Console.WriteLine(" Power Capacity: {0} power units", powerCapacity);
                }
            }

            //===== INPUT/OUTPUT =====//
            InputOutput[] inputsOutputs = general.GetInputOutputs;

            if (inputsOutputs.Length != 0)
            {
                string input  = string.Empty;
                string output = string.Empty;

                for (int i = 0; i < inputsOutputs.Length; i++)
                {
                    if (inputsOutputs[i].Inputs != null)
                    {
                        if (input == string.Empty)
                        {
                            input = string.Join(", ", inputsOutputs[i].Inputs.Select(sel => sel.ToString()));
                        }
                        else if (inputsOutputs[i].Inputs != inputsOutputs[i - 1].Inputs)
                        {
                            input += " / " + string.Join(", ", inputsOutputs[i].Inputs.Select(sel => sel.ToString()));
                        }
                    }
                    if (inputsOutputs[i].Outputs != null)
                    {
                        if (output == string.Empty)
                        {
                            output = string.Join(", ", inputsOutputs[i].Outputs.Select(sel => sel.ToString()));
                        }
                        else if (inputsOutputs[i].Outputs != inputsOutputs[i - 1].Outputs)
                        {
                            output += " / " + string.Join(", ", inputsOutputs[i].Outputs.Select(sel => sel.ToString()));
                        }
                    }
                }

                Formations.Header("INPUT/OUTPUT");
                if (input != string.Empty)
                {
                    Console.WriteLine(" Input: {0}", input);
                }
                if (output != string.Empty)
                {
                    Console.WriteLine(" Output: {0}", output);
                }
                Console.WriteLine(" Production Time: {0} second", inputsOutputs[0].ProductionTime);
            }
        }
Example #14
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);
        }
        public static void Update(InputOutput inputOutput)
        {
            char select;

            do
            {
                Console.WriteLine("═════════╡ INPUT/OUTPUT ╞═════════");
                Console.WriteLine("ID: {0}", inputOutput.Id);
                Console.WriteLine("Owner: {0}", General.Generals.Where(gen => gen.Id == inputOutput.GeneralId).First().Name);
                Console.WriteLine("[1] Input: {0}", inputOutput.Inputs == null ? "null" : string.Join(", ", inputOutput.Inputs.Select(sel => sel.ToString())));
                Console.WriteLine("[2] Output: {0}", inputOutput.Outputs == null ? "null" : string.Join(", ", inputOutput.Outputs.Select(sel => sel.ToString())));
                Console.WriteLine("[3] Production Time: {0}", inputOutput.ProductionTime);
                Console.WriteLine("Weight: {0}", inputOutput.Weight);
                Console.WriteLine("[8] Delete");
                Console.WriteLine("[9] Save");
                Console.WriteLine("[0] Exit");

                Console.Write("> ");
                select = Console.ReadKey().KeyChar;
                Console.Clear();

                if (select == '0')
                {
                    bool allCorrect = true;

                    if (inputOutput.ProductionTime != null || inputOutput.Inputs != null || inputOutput.Outputs != null)
                    {
                        allCorrect = false;
                    }

                    if (allCorrect)
                    {
                        return;
                    }
                    else
                    {
                        Console.WriteLine("═════════╡ YOU ARE SURE WANT TO EXIT? (Y - YES)╞═════════");
                        Console.Write("> ");
                        select = Console.ReadKey().KeyChar;
                        Console.Clear();

                        if (select.ToString().ToLower() == "y")
                        {
                            return;
                        }
                    }
                }
                else if (select == '1')
                {
                    Item[] input = ManageMaterial.SetItems();
                    if (input != null)
                    {
                        inputOutput.Input = string.Join(";", input.Select(inp => inp.Id + " " + inp.Amount));
                    }
                }
                else if (select == '2')
                {
                    Item[] output = ManageMaterial.SetItems(true);
                    if (output != null)
                    {
                        inputOutput.Output = string.Join(";", output.Select(inp => inp.Id + " " + inp.Amount));
                    }
                }
                else if (select == '3')
                {
                    inputOutput.ProductionTime = Formations.GetValue("Production Time", "double");
                }
                else if (select == '8')
                {
                    Console.WriteLine("═════════╡ TO DELETE {0}? (Y - YES)╞═════════", inputOutput.ToString().ToUpper());
                    Console.Write("> ");
                    select = Console.ReadKey().KeyChar;
                    Console.Clear();

                    if (select.ToString().ToLower() == "y")
                    {
                        inputOutput.Delete();
                        return;
                    }
                }
                else if (select == '9')
                {
                    bool allCorrect = true;

                    if (inputOutput.ProductionTime == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Production Time");
                    }
                    if (inputOutput.Inputs == null && inputOutput.Outputs == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Input or Output");
                    }

                    if (allCorrect)
                    {
                        inputOutput.Save();
                        return;
                    }
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }
Example #16
0
        public static void Update(Power power)
        {
            char select;

            do
            {
                Console.WriteLine("═════════╡ UPDATE POWER ╞═════════");
                Console.WriteLine("ID: {0}", power.Id);
                Console.WriteLine("General: {0}", power.GetGeneral.Name);
                Console.WriteLine("[1] Input Output: {0}", power.InputOutputId);
                Console.WriteLine("[2] Power Use: {0}", power.PowerUse);
                Console.WriteLine("[3] Power Capacity: {0}", power.PowerCapacity);
                Console.WriteLine("[4] Power Generation: {0}", power.PowerGeneration);
                Console.WriteLine("[8] Delete");
                Console.WriteLine("[9] Save");
                Console.WriteLine("[0] Exit");

                Console.Write("> ");
                select = Console.ReadKey().KeyChar;
                Console.Clear();

                if (select == '0')
                {
                    bool allCorrect = true;

                    if (power.PowerUse != null || power.PowerCapacity != null || power.PowerGeneration != null)
                    {
                        allCorrect = false;
                    }

                    if (allCorrect)
                    {
                        return;
                    }
                    else
                    {
                        Console.WriteLine("═════════╡ YOU ARE SURE WANT TO EXIT? (Y - YES)╞═════════");
                        Console.Write("> ");
                        select = Console.ReadKey().KeyChar;
                        Console.Clear();

                        if (select.ToString().ToLower() == "y")
                        {
                            return;
                        }
                    }
                }
                else if (select == '1')
                {
                    string id = SetInputOutput(power.GetGeneral.GetInputOutputs);

                    if (id != "")
                    {
                        power.InputOutputId = id;
                    }
                }
                else if (select == '2')
                {
                    power.PowerUse = Formations.GetValue("Power Use", "double");
                }
                else if (select == '3')
                {
                    power.PowerCapacity = Formations.GetValue("Power Capacity", "double");
                }
                else if (select == '4')
                {
                    power.PowerGeneration = Formations.GetValue("Power Generation", "double");
                }
                else if (select == '8' && Delete(power))
                {
                    return;
                }
                else if (select == '9')
                {
                    bool allCorrect = true;

                    if (power.PowerUse == null && power.PowerCapacity == null && power.PowerGeneration == null)
                    {
                        allCorrect = false;
                        Formations.NotCorrect("Power Use or Capacity or Generation");
                    }

                    if (allCorrect)
                    {
                        power.Save();
                        return;
                    }
                }
                else
                {
                    Formations.NotFound("Action");
                }
            }while (true);
        }