示例#1
0
        protected override void PerformLogic()
        {
            for (int i = 0; i < this.InputIDS.Length; i++)
            {
                string        id = this.InputIDS[i];
                MinimalSwitch ms = this.InputDictionary[id];

                ms.SetValue(base.Inputs[i].Value);
            }

            foreach (CircuitComponent cc in Components)
            {
                cc.UpdateInputsAndLogic();
            }

            foreach (CircuitComponent cc in Components)
            {
                cc.UpdateOutputs();
            }

            for (int i = 0; i < this.OutputIDS.Length; i++)
            {
                string      id = this.OutputIDS[i];
                MinimalLamp ml = this.OutputDictionary[id];

                base.Outputs[i].Value = ml.GetValue();
            }
        }
示例#2
0
        public List <CircuitComponent> GenerateComponents()
        {
            CircuitComponent[] components = new CircuitComponent[Descriptions.Count];

            for (int i = 0; i < Descriptions.Count; i++)
            {
                ICComponentDescription iccd = Descriptions[i];
                CircuitComponent       dc   = null;
                switch (iccd.Type)
                {
                case "ANDGateLogic":
                    dc = new MinimalLogicGate(new ANDGateLogic());
                    break;

                case "NANDGateLogic":
                    dc = new MinimalLogicGate(new NANDGateLogic());
                    break;

                case "ORGateLogic":
                    dc = new MinimalLogicGate(new ORGateLogic());
                    break;

                case "NORGateLogic":
                    dc = new MinimalLogicGate(new NORGateLogic());
                    break;

                case "XORGateLogic":
                    dc = new MinimalLogicGate(new XORGateLogic());
                    break;

                case "XNORGateLogic":
                    dc = new MinimalLogicGate(new XNORGateLogic());
                    break;

                case "NOTGateLogic":
                    dc = new MinimalLogicGate(new NOTGateLogic());
                    break;

                case "Switch":
                    //CircuitSwitch cs = new CircuitSwitch(Vector2.Zero);
                    //cs.SetID(iccd.ID);
                    dc = new MinimalSwitch()
                    {
                        ID = iccd.ID
                    };
                    break;

                case "Lamp":
                    //CircuitLamp cl = new CircuitLamp(Vector2.Zero);
                    //cl.SetID(iccd.ID);
                    dc = new MinimalLamp()
                    {
                        ID = iccd.ID
                    };
                    break;

                default:
                    // It is not a built in thing - look for it in the IC files folder
                    ICDescription icd = iccd.Description;
                    dc = new DrawableIC(Vector2.Zero, icd.Name, icd, false);
                    break;
                }
                components[i] = dc;
            }

            for (int i = 0; i < Descriptions.Count; i++)
            {
                ICComponentDescription iccd = Descriptions[i];

                foreach (ICConnectionDescription connection in iccd.To)
                {
                    CircuitWire cw = new CircuitWire();

                    components[i].AddOutputWire(connection.OutIndex, cw);
                    components[connection.To].SetInputWire(connection.InIndex, cw);
                }
            }

            return(components.ToList());
        }