Ejemplo n.º 1
0
    public override void Trigger(TriggerableContext context)
    {
        // Debug.Log($"Transistor shape triggered with {ClosestNeighbors.Count} neighbors!");

        foreach (Shape shape in ClosestNeighbors)
        {
            if (CanAbsorpToExplosion(shape))
            {
                context.WillExplode = true;
            }
            else if (CanAbsorp(shape))
            {
                Absorption absorption = new Absorption();
                absorption.Consumer = this;
                absorption.Consumee = shape;

                if (!context.Absorptions.Contains(absorption))
                {
                    context.Absorptions.Add(absorption);
                    context.Completed = false;
                    // Debug.Log("...and absorbed one of them!");
                }
            }
        }
    }
Ejemplo n.º 2
0
    // ckecks all types of shapes interactions upon placing them on tile map
    private void CheckoutShapeTriggers()
    {
        TriggerableContext context = new TriggerableContext();

        while (!context.Completed)
        {
            context.Completed = true;
            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    if (!m_Cells[row, col].IsEmpty)
                    {
                        m_Cells[row, col].shape.Trigger(context);
                    }
                }
            }
        }

        // check for infinity explosions
        if (context.WillExplode)
        {
            foreach (TileMapCell cell in m_Cells)
            {
                cell.RemoveShape();
            }
        }
        else
        {
            // create Absorption graph and execute it
            AbsorptionGraph absorptionGraph = AbsorptionGraph.FromContext(context);
            absorptionGraph.Execute();
        }

        // Debug.Log("Triggers executed!");
    }
Ejemplo n.º 3
0
 public virtual void Trigger(TriggerableContext context)
 {
 }