Ejemplo n.º 1
0
    public void SwapGems(Gems source)
    {
        // if there is no last gem selected, set it to the source
        if(last == null)
        {
            last = source;
        }
        // but, if there is a source, then last gem should be nulled as the player is unselecting it.
        else if(last == source)
        {
            last = null;
        }
        // else, figure out if the gem is neighbor
        else
        {
            // if the last gem is a neighbor of the currently selected gem, then allow the swap
            if (last.NeighboredGem(source) && canSwap)
            {
                g1 = last;
                g2 = source;
                // the first gem's source position is the last gem selected's position
                firstGemSourcePosition = last.transform.position;
                neighborGemSourcePosition = source.transform.position;

                // the transform is swapped
                last.transform.position = neighborGemSourcePosition;
                source.transform.position = firstGemSourcePosition;

                last.image = source.image;
                source.image = last.image;

                source.toggleSelection();
                last.toggleSelection();

                // for swap control
                canSwap = false;

                last = null;

                matchPossible = true;
            }
            else
            {
                last = source;
                //last.toggleSelection();

                canSwap = true;
            }
        }
    }