Beispiel #1
0
        /// <summary>
        /// Initializes the form
        /// </summary>
        public EnigmaMachineUI()
        {
            InitializeComponent();
            this.KeyPreview = true; // makes the form the starting point for key presses

            // sets the sizes
            this.MaximumSize = this.Size;
            this.MinimumSize = this.Size;
            this.MaximizeBox = false;
            this.MinimizeBox = false;

            // sets the Rotor defaults
            Rotors.SetRotorDefaults = FileManagement.GetInformationFromFile(FileNames.Rotors);
            // initializes three rotors
            Rotors[] rotors = new Rotors[3];

            // runs through each control in the rotor panel
            for (int i = 0; i < pnRotorNumbers.Controls.Count; i++)
            {
                // attempts to convert the control to a combobox
                ComboBox cb = pnRotorNumbers.Controls[i] as ComboBox;

                // if successful
                if (cb != null)
                {
                    // sets the rotor information
                    rotors[i] = new Rotors(i);
                    RotorLoad(cb, rotors[i]);
                    cb.SelectedIndex = i;
                }
            }

            // loads the reflector combo box
            ReflectorLoad();
            // initializes a new machine
            machine = new Machine(rotors, Reflector.GetReflectorString(cbReflector.SelectedIndex), "");

            // adds the labels to the three letter panels
            AddLabels(pnLamps);
            AddLabels(pnKeys);
            AddLabels(pnPlugboard);

            // counts the number of rotors on the form and sets the offset controls
            int num = pnRotorNumbers.Controls.Count;

            for (int i = 0; i < num; i++)
            {
                OffsetLoad(i);
            }

            // initializes the colours used array
            colourUsed = new bool[colours.Length];

            // sets the plugboard header to the default foreground colour
            lbPlugboardHeader.ForeColor = DEFAULT_LETTER_FG_COLOUR;

            // centers the clear button
            btnClearPlugboard.Location = new Point(this.Width / 2 - btnClearPlugboard.Width / 2, 595);
        }
Beispiel #2
0
        /// <summary>
        /// Checks the index information for the reflector
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ReflectorIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = sender as ComboBox;   // converts the object to a combobox

            // if the conversion was successful and the machine is not null
            if (cb != null && machine != null)
            {
                machine.Reflector = Reflector.GetReflectorString(cb.SelectedIndex);
            }
        }