public Component(ComponentType componentType, ComponentHitbox hitbox, uint thickness = 3, float xIndent = 3, float yIndent = 3)
        {
            Color       = Color.Black;
            XIndent     = xIndent;
            YIndent     = yIndent;
            this.hitbox = hitbox;
            Thickness   = thickness;

            switch (componentType)
            {
            case ComponentType.AND:
                inputs    = new List <Component> [2];
                inputs[0] = new List <Component>(0);
                inputs[1] = new List <Component>(0);
                break;

            case ComponentType.OR:
                inputs    = new List <Component> [2];
                inputs[0] = new List <Component>(0);
                inputs[1] = new List <Component>(0);
                break;

            case ComponentType.XOR:
                inputs    = new List <Component> [2];
                inputs[0] = new List <Component>(0);
                inputs[1] = new List <Component>(0);
                break;

            case ComponentType.NOT:
                inputs    = new List <Component> [1];
                inputs[0] = new List <Component>(0);
                break;

            case ComponentType.Wire:
                inputs    = new List <Component> [1];
                inputs[0] = new List <Component>(0);
                break;

            case ComponentType.Switch:
                inputs = new List <Component> [0];
                break;

            case ComponentType.Button:
                inputs = new List <Component> [0];
                break;

            case ComponentType.Clock:
                inputs = new List <Component> [0];
                break;

            case ComponentType.Light:
                inputs    = new List <Component> [1];
                inputs[0] = new List <Component>(0);
                break;

            default:
                throw new ArgumentException("No such component type registered in enumeration.");
            }
        }
Exemplo n.º 2
0
        public Wire(Scene scene, Line wire, Component input, Component output) : // TODO: Need to add two more checks for appropriate missing output or input.
            base(ComponentType.Wire, null, 3)
        {
            inHitboxes = new InHitbox[inputs.Length];
            hitbox     = new ComponentHitbox();

            Scene = scene;

            if (input != null && output != null)
            {
                inputs[0] = new List <Component>(1)
                {
                    input
                };

                input.outputs.Add(this);

                outputs = new List <Component>(1)
                {
                    output
                };

                OutConnected = scene.WireOutputHitbox;
                InConnected  = scene.WireInputHitbox;
                output.inputs[InConnected.AttachedInputIndex].Add(this);

                inHitboxes[0] = new InHitbox(OutConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(InConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
            }

            if (input != null && output == null)
            {
                inputs[0] = new List <Component>(1)
                {
                    input
                };

                input.outputs.Add(this);
                OutConnected = scene.WireOutputHitbox;

                inHitboxes[0] = new InHitbox(OutConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(wire.points[1], this, (int)(scene.ScaleFactor * 5f), 0);
            }

            if (input == null && output != null)
            {
                outputs = new List <Component>(1)
                {
                    output
                };

                InConnected = scene.WireInputHitbox;
                output.inputs[InConnected.AttachedInputIndex].Add(this);

                inHitboxes[0] = new InHitbox(wire.points[0], this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(InConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
            }

            lines     = new Line[1];
            lines[0]  = wire;
            startLine = new Line((1 / scene.ScaleFactor) * wire.points[0], (1 / scene.ScaleFactor) * wire.points[1]);

            scene.Update();
            Process(scene);
        }