Пример #1
0
        /// <summary>
        /// Connects a circuit component as an output/dependent of the
        /// invoking wire.
        /// </summary>
        /// <param name="component">The component to connect</param>
        public void ConnectDependent(CircuitComponent component)
        {
            // If we already made this connection, we're done!
            if (!_dependentComponents.Contains(component))
            {
                _dependentComponents.Add(component);
            }
            else
            {
                return;
            }

            if (Source != null)
            {
                component.ConnectInput(Source, SourceIndex);
            }

            // Make sure the circuit component also has this connection
            if (component is LogicGate)
            {
                ((LogicGate)component).ConnectInput(this);
            }
            else if (component is CircuitOutput)
            {
                ((CircuitOutput)component).Connect(this);
            }
            else if (component is CircuitInput)
            {
                ((CircuitInput)component).Connect(this);
            }
        }
Пример #2
0
        /// <summary>
        /// Connects a circuit component to the output of the
        /// invoking logic gate. In other words, the output of
        /// the invoking logic gate becomes directly tied with
        /// an input or value of a given circuit component.
        /// </summary>
        /// <param name="wire">The component to connect</param>
        public void ConnectOutput(CircuitComponent component, int index)
        {
            while (_outputComponents.Count < index + 1)
            {
                _outputComponents.Add(new List <CircuitComponent>());
            }

            // If we already made this connection, we're done!
            if (_outputComponents[index].Contains(component))
            {
                return;
            }

            // Make the connection.
            _outputComponents[index].Add(component);

            // Ensure that the given component also has this connection.
            component.ConnectInput(this, index);
        }