public Settings(MachineType typ, ReflectorType refTyp, RotorName[] rotors, int[] ringPos, string[] plugs) : this(typ, refTyp) { MachineType = typ; ReflectorType = refTyp; if (MachineType == MachineType.M4K) { if (refTyp == ReflectorType.B_Dunn) { Rotors.Add(new RotorSetting(RotorName.Beta, 0)); } else { Rotors.Add(new RotorSetting(RotorName.Gamma, 0)); } } Rotors.Add(new RotorSetting(RotorName.I, 0)); Rotors.Add(new RotorSetting(RotorName.II, 0)); Rotors.Add(new RotorSetting(RotorName.III, 0)); Plugs.Clear(); for (int i = 0; i < rotors.Length; i++) { if (i <= Rotors.Count) { Rotors[i].Name = rotors[i]; if (i <= ringPos.Length) { Rotors[i].RingSetting = ringPos[i]; } } } for (int i = 0; i < 10; i++) { if (i <= plugs.Length) { Plugs.Add(new PlugSetting(plugs[i])); } } }
public Settings(MachineType typ, ReflectorType refTyp, params object[] args) : this(typ, refTyp) { MachineType = typ; ReflectorType = refTyp; if (MachineType == MachineType.M4K) { if (refTyp == ReflectorType.B_Dunn) { Rotors.Add(new RotorSetting(RotorName.Beta, 0)); } else { Rotors.Add(new RotorSetting(RotorName.Gamma, 0)); } } Rotors.Add(new RotorSetting(RotorName.I, 0)); Rotors.Add(new RotorSetting(RotorName.II, 0)); Rotors.Add(new RotorSetting(RotorName.III, 0)); Plugs.Clear(); List <RotorName> rotorNames = new List <RotorName>(); List <int> ringSettings = new List <int>(); List <string> plugSettings = new List <string>(); foreach (var item in args) { if (item is RotorName) { rotorNames.Add((RotorName)item); continue; } if (item is int) { ringSettings.Add((int)item); continue; } if (item is string) { plugSettings.Add((string)item); continue; } } for (int i = 0; i < rotorNames.Count; i++) { if (i <= Rotors.Count) { Rotors[i].Name = rotorNames[i]; if (i <= ringSettings.Count) { Rotors[i].RingSetting = ringSettings[i]; } } } for (int i = 0; i < 10; i++) { if (i <= plugSettings.Count) { Plugs.Add(new PlugSetting(plugSettings[i])); } } }