Exemplo n.º 1
0
    /// <summary>
    /// Insert a tile into the order stack.
    /// </summary>
    /// <param name="tile"></param>
    public void AddToStack(TileBase tile)
    {
        if (!canAdd)
        {
            return;
        }
        //If the list is empty, add anything
        if (order.Count == 0)
        {
            order.AddLast(tile);
        }
        else
        {
            //Only add if they are the same type and if it's not already here and it's ajacent
            bool isAdjacent = (tile.row <= (order.Last.Value.row + 1) && tile.row >= (order.Last.Value.row - 1)) &&
                              (tile.col <= (order.Last.Value.col + 1) && tile.col >= (order.Last.Value.col - 1));
            if (order.Last.Value.type == tile.type && !order.Contains(tile) && isAdjacent)
            {
                //DISPLAY CONNECTION
                //draw line renderer to here
                TileBase prev = order.Last.Value;
                int      y    = tile.row - prev.row;
                int      x    = tile.col - prev.col;

                prev.SetLine(x, y);

                //Insert
                order.AddLast(tile);
            }
            //if the tile we are trying to add is the same as the second to last, remove the last one
            //a.k.a. retracing
            else if (order.Last.Previous != null && tile == order.Last.Previous.Value)
            {
                //reset lines
                order.Last.Value.ResetLine();
                order.Last.Previous.Value.ResetLine();
                order.RemoveLast();
            }
        }
    }