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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
//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); }