예제 #1
0
    //return the next connected neighbour in that direction that is NOT that element
    public Box getNextNonElementNeighbour(UtilityTools.Directions dir, Element el, ref int maxLoops)
    {
        maxLoops++;
        if (maxLoops > grid_ref.getWidth() && maxLoops > grid_ref.getHeight())
        {
            return(null);
        }

        Tile t = getNeighbourTile(dir);

        if (t == null)
        {
            return(null);
        }

        if (t.GetBox() == null || t.GetStatus() != Tile.Status.box)
        {
            return(null);
        }

        if (t.GetBox() != null && t.GetStatus() == Tile.Status.box)
        {
            if (t.GetBox().GetElement() != el)
            {
                return(t.GetBox());
            }
            else if (getNextNonElementNeighbour(dir, el, ref maxLoops) == null)
            {
                return(null);
            }
        }

        return(null);
    }
예제 #2
0
    public List <Box> getConnectedBoxes(UtilityTools.Directions dir)
    {
        List <Box> connectedBoxes = new List <Box>();

        _getConnectedBoxes(dir, connectedBoxes);

        return(connectedBoxes.Distinct().ToList());
    }
예제 #3
0
    public bool isMyNeighbourThisStatus(UtilityTools.Directions dir, Tile.Status s)
    {
        if (getNeighbourTile(dir) == null)
        {
            return(false);
        }

        return(getNeighbourTile(dir).GetStatus() == s);
    }
예제 #4
0
    public bool isMyNeighbourThisKind(UtilityTools.Directions dir, Tile.Kind k)
    {
        if (getNeighbourTile(dir) == null)
        {
            return(false);
        }

        return(getNeighbourTile(dir).GetKind() == k);
    }
예제 #5
0
    public Tile getNeighbourTile(UtilityTools.Directions dir)
    {
        if (grid_ref == null)
        {
            return(null);
        }

        return(grid_ref.GetTile(index.getNeighbourPoint(dir)));
    }
예제 #6
0
    public bool isBoxAtEdge(UtilityTools.Directions dir)
    {
        if (tribox == null || isCenterBox())
        {
            return(false);
        }

        //tribox.rearrangeBoxesArray();

        return(this == tribox.GetBoxes().First() || this == tribox.GetBoxes().Last());
    }
예제 #7
0
    public Box getDirectionMostBox(UtilityTools.Directions dir)
    {
        foreach (Box b in boxes)
        {
            if (b.isDirectionMost(dir))
            {
                return(b);
            }
        }

        return(null);
    }
예제 #8
0
    public static Vector3 getDirectionVector(UtilityTools.Directions dir)
    {
        switch (dir)
        {
        case UtilityTools.Directions.up:
            return(Vector3.up);

            break;

        case UtilityTools.Directions.upRight:

            return((Vector3.up + Vector3.right).normalized);

            break;

        case UtilityTools.Directions.right:
            return(Vector3.right);

            break;

        case UtilityTools.Directions.downRight:
            return((Vector3.down + Vector3.right).normalized);

            break;

        case UtilityTools.Directions.down:
            return(Vector3.down);

            break;

        case UtilityTools.Directions.downLeft:
            return((Vector3.down + Vector3.left).normalized);

            break;

        case UtilityTools.Directions.left:
            return(Vector3.left);

            break;

        case UtilityTools.Directions.upLeft:
            return((Vector3.up + Vector3.left).normalized);

            break;

        default:
            return(Vector3.zero);

            break;
        }
    }
예제 #9
0
    public Point getNeighbourPoint(UtilityTools.Directions dir)
    {
        Point p = new Point(x, y);

        switch (dir)
        {
        case UtilityTools.Directions.up:
            p.y--;
            break;

        case UtilityTools.Directions.upRight:
            p.y--;
            p.x++;

            break;

        case UtilityTools.Directions.right:
            p.x++;
            break;

        case UtilityTools.Directions.downRight:
            p.y++;
            p.x++;
            break;

        case UtilityTools.Directions.down:
            p.y++;
            break;

        case UtilityTools.Directions.downLeft:
            p.y++;
            p.x--;
            break;

        case UtilityTools.Directions.left:
            p.x--;
            break;

        case UtilityTools.Directions.upLeft:
            p.y--;
            p.x--;
            break;
        }

        return(p);
    }
예제 #10
0
    public static bool areAllConnected(UtilityTools.Directions dir, List <Box> boxList)
    {
        if (UtilityTools.horizontals.Contains(dir))
        {
            boxList = boxList.OrderBy(b => b.GetPoint().x).ToList();
        }
        else if (UtilityTools.verticals.Contains(dir))
        {
            boxList = boxList.OrderBy(b => b.GetPoint().y).ToList();
        }
        else
        {
            return(false);
        }

        for (int i = 0; i < boxList.Count; i++)
        {
            if (i < boxList.Count - 1)
            {
                if (UtilityTools.horizontals.Contains(dir))
                {
                    //if index difference is above one, they are not neighbours
                    if (Mathf.Abs(boxList[i].GetPoint().Clone().x - boxList[i + 1].GetPoint().Clone().x) > 1)
                    {
                        return(false);
                    }
                }
                else if (UtilityTools.verticals.Contains(dir))
                {
                    if (Mathf.Abs(boxList[i].GetPoint().Clone().y - boxList[i + 1].GetPoint().Clone().y) > 1)
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);
    }
예제 #11
0
    private void _getConnectedBoxes(UtilityTools.Directions dir, List <Box> connected)
    {
        Tile t = getNeighbourTile(dir);

        if (t == null)
        {
            return;
        }

        if (t.GetBox() != null && t.GetStatus() == Tile.Status.box)
        {
            if (!connected.Contains(t.GetBox()))
            {
                connected.Add(t.GetBox());
                if (!connected.Contains(this))
                {
                    connected.Add(this);
                }
            }

            t.GetBox()._getConnectedBoxes(dir, connected);
        }
    }
예제 #12
0
    public void Push(UtilityTools.Directions dir)
    {
        if (!isInTribox())
        {
            return;
        }

        bool   clockw = true;
        TriBox tri    = tribox;

        switch (dir)
        {
        case UtilityTools.Directions.up:
            if (tri.IsVertical())
            {
                //if im the lowest box
                if (isDirectionMost(UtilityTools.OppositeDirection(dir)))
                {
                    //if the upside is empty
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
            }
            else
            {
                if (isCenterBox())
                {
                    //try to move
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
                else
                {
                    //try to rotate
                    clockw = (isDirectionMost(UtilityTools.Directions.left));
                    tribox.Rotate(clockw);
                    return;
                }
            }

            break;

        case UtilityTools.Directions.upRight:

            break;

        case UtilityTools.Directions.right:

            if (!tri.IsVertical())
            {
                //if im the leftmost box
                if (isDirectionMost(UtilityTools.OppositeDirection(dir)))
                {
                    //if the side is empty
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
            }
            else
            {
                if (isCenterBox())
                {
                    //try to move
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
                else
                {
                    //try to rotate
                    clockw = (isDirectionMost(UtilityTools.Directions.up));
                    tribox.Rotate(clockw);
                    return;
                }
            }

            break;

        case UtilityTools.Directions.downRight:

            break;

        case UtilityTools.Directions.down:
            if (tri.IsVertical())
            {
                //need to move down
                //if im the toppest box
                if (isDirectionMost(UtilityTools.OppositeDirection(dir)))
                {
                    //if the downside is empty
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
            }
            else
            {
                if (isCenterBox())
                {
                    //try to move
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
                else
                {
                    //try to rotate
                    clockw = (isDirectionMost(UtilityTools.Directions.right));
                    tribox.Rotate(clockw);
                    return;
                }
            }

            break;

        case UtilityTools.Directions.downLeft:
            break;

        case UtilityTools.Directions.left:

            if (!tri.IsVertical())
            {
                //if im the leftmost box
                if (isDirectionMost(UtilityTools.OppositeDirection(dir)))
                {
                    //if the side is empty
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
            }
            else
            {
                if (isCenterBox())
                {
                    //try to move
                    if (tri.isSideEmpty(dir))
                    {
                        tribox.Move(dir);
                    }
                }
                else
                {
                    //try to rotate
                    clockw = (isDirectionMost(UtilityTools.Directions.down));
                    tribox.Rotate(clockw);
                    return;
                }
            }

            break;

        case UtilityTools.Directions.upLeft:
            break;

        default:
            return;
        }
    }
예제 #13
0
    public void Move(UtilityTools.Directions dir)
    {
        //after checkups

        if (isRotating || isMoving)
        {
            print("already moving/rotating");
            return;
        }

        if (!canMove(dir))
        {
            return;
        }

        Tile[] destinations = { null, null, null };

        bool shouldEmptyPreviousTile = false;

        switch (dir)
        {
        case UtilityTools.Directions.up:
            if (isVertical)
            {
                destinations[0] = getDirectionMostBox(dir).getNeighbourTile(dir); // the uppermost is gonna go to his up neighbour
                destinations[1] = getDirectionMostBox(dir).GetTile();             // the center is gonna go to current uppermost
                destinations[2] = getCenterBox().GetTile();                       // lowest is going to go to center

                shouldEmptyPreviousTile = true;
            }
            else
            {
                for (int i = 0; i < destinations.Length && i < boxes.Length; i++)
                {
                    destinations[i] = boxes[i].getNeighbourTile(dir);
                }
            }

            break;

        case UtilityTools.Directions.right:
            if (!isVertical)
            {
                destinations[0]         = getCenterBox().GetTile();                       // leftmost is going to go to center
                destinations[1]         = getDirectionMostBox(dir).GetTile();             // the center is gonna go to current rightmost
                destinations[2]         = getDirectionMostBox(dir).getNeighbourTile(dir); // the rightmost is gonna go to his right neighbour
                shouldEmptyPreviousTile = true;
            }
            else
            {
                for (int i = 0; i < destinations.Length && i < boxes.Length; i++)
                {
                    destinations[i] = boxes[i].getNeighbourTile(dir);
                }
            }

            break;

        case UtilityTools.Directions.down:
            if (isVertical)
            {
                destinations[0]         = getCenterBox().GetTile();                       // highest is going to go to center
                destinations[1]         = getDirectionMostBox(dir).GetTile();             // the center is gonna go to current downmost
                destinations[2]         = getDirectionMostBox(dir).getNeighbourTile(dir); // the downmost is gonna go to his down neighbour
                shouldEmptyPreviousTile = true;
            }
            else
            {
                for (int i = 0; i < destinations.Length && i < boxes.Length; i++)
                {
                    destinations[i] = boxes[i].getNeighbourTile(dir);
                }
            }

            break;

        case UtilityTools.Directions.left:
            if (!isVertical)
            {
                destinations[0]         = getDirectionMostBox(dir).getNeighbourTile(dir); // the leftmost is gonna go to his left neighbour
                destinations[1]         = getDirectionMostBox(dir).GetTile();             // the center is gonna go to current leftmost
                destinations[2]         = getCenterBox().GetTile();                       // rightmost is going to go to center
                shouldEmptyPreviousTile = true;
            }
            else
            {
                for (int i = 0; i < destinations.Length && i < boxes.Length; i++)
                {
                    destinations[i] = boxes[i].getNeighbourTile(dir);
                }
            }

            break;

        default:
            return;

            break;
        }

        // all destinations are ok
        if (!System.Array.FindAll(destinations, x => x == null).Any())
        {
            isMoving = true;

            transform.DOMove(transform.position + UtilityTools.getDirectionVector(dir) * 1, TheGrid.moveTime).OnComplete(() =>
            {
                isMoving = false;
                grid_ref.spawnTriBox();
                grid_ref.Match(getBoxMatches());
            });

            for (int i = 0; i < destinations.Length && i < boxes.Length; i++)
            {
                //move sprites

                //update tiles  isVertical && dir == UtilityTools.Directions.down && i > 0
                //fix when moving down it should not set previous tiles as empties
                if (shouldEmptyPreviousTile)
                {
                    boxes[i].setTile(destinations[i], Tile.Status.box);
                }
                else
                {
                    boxes[i].setTile(destinations[i]);
                }
            }
        }
        else
        {
            return;
        }

        //print("first box: " + boxes.First() + boxes.First().GetPoint().print() + " is moving to position" + destination1.GetPoint().Clone().print());
        rearrangeBoxesArray();
    }
예제 #14
0
 public bool canMove(UtilityTools.Directions dir)
 {
     return(isSideEmpty(dir));
 }
예제 #15
0
    public bool isSideEmpty(UtilityTools.Directions dir)
    {
        switch (dir)
        {
        case UtilityTools.Directions.up:
            if (isVertical)
            {
                if (getDirectionMostBox(dir).getNeighbourTile(dir) == null)
                {
                    return(false);
                }

                return(getDirectionMostBox(dir).getNeighbourTile(dir).isEmpty());
            }
            else
            {
                foreach (Box b in boxes)
                {
                    Tile neighbour = b.getNeighbourTile(dir);
                    if (neighbour == null)
                    {
                        return(false);
                    }

                    if (!neighbour.isEmpty())
                    {
                        return(false);
                    }
                }
                return(true);
            }

            break;

        case UtilityTools.Directions.right:
            if (!isVertical)
            {
                if (getDirectionMostBox(dir).getNeighbourTile(dir) == null)
                {
                    return(false);
                }

                return(getDirectionMostBox(dir).getNeighbourTile(dir).isEmpty());
            }
            else
            {
                foreach (Box b in boxes)
                {
                    Tile neighbour = b.getNeighbourTile(dir);
                    if (neighbour == null)
                    {
                        return(false);
                    }

                    if (!neighbour.isEmpty())
                    {
                        return(false);
                    }
                }
                return(true);
            }

            break;

        case UtilityTools.Directions.down:
            if (isVertical)
            {
                if (getDirectionMostBox(dir).getNeighbourTile(dir) == null)
                {
                    return(false);
                }

                return(getDirectionMostBox(dir).getNeighbourTile(dir).isEmpty());
            }
            else
            {
                foreach (Box b in boxes)
                {
                    Tile neighbour = b.getNeighbourTile(dir);
                    if (neighbour == null)
                    {
                        return(false);
                    }

                    if (!neighbour.isEmpty())
                    {
                        return(false);
                    }
                }
                return(true);
            }

            break;

        case UtilityTools.Directions.left:
            if (!isVertical)
            {
                if (getDirectionMostBox(dir).getNeighbourTile(dir) == null)
                {
                    return(false);
                }

                return(getDirectionMostBox(dir).getNeighbourTile(dir).isEmpty());
            }
            else
            {
                foreach (Box b in boxes)
                {
                    Tile neighbour = b.getNeighbourTile(dir);
                    if (neighbour == null)
                    {
                        return(false);
                    }

                    if (!neighbour.isEmpty())
                    {
                        return(false);
                    }
                }
                return(true);
            }

            break;

        default:
            return(false);

            break;
        }
    }
예제 #16
0
    //check if this box is at the direction-most position of tribox
    public bool isDirectionMost(UtilityTools.Directions dir)
    {
        if (!isBoxAtEdge(dir))
        {
            return(false);
        }

        //tribox.rearrangeBoxesArray();

        switch (dir)
        {
        case UtilityTools.Directions.up:
            if (tribox.IsVertical())
            {
                return(this == tribox.GetBoxes().First());
            }
            else
            {
                return(false);
            }

            break;

        case UtilityTools.Directions.right:
            if (!tribox.IsVertical())
            {
                return(this == tribox.GetBoxes().Last());
            }
            else
            {
                return(false);
            }

            break;

        case UtilityTools.Directions.down:
            if (tribox.IsVertical())
            {
                return(this == tribox.GetBoxes().Last());
            }
            else
            {
                return(false);
            }

            break;

        case UtilityTools.Directions.left:
            if (!tribox.IsVertical())
            {
                return(this == tribox.GetBoxes().First());
            }
            else
            {
                return(false);
            }

            break;

        default:
            return(false);

            break;
        }
    }
예제 #17
0
    private bool checkDestination(UtilityTools.Directions dir)
    {
        Tile destination = grid_ref.GetTile(index.getNeighbourPoint(dir));

        if (dir == UtilityTools.Directions.upLeft || dir == UtilityTools.Directions.upRight ||
            dir == UtilityTools.Directions.downRight || dir == UtilityTools.Directions.downLeft ||
            destination == null)
        {
            return(false);
        }
        else
        {
            if (destination.isEmpty())
            {
                //print("destination is empty: " + index.getNeighbourPoint (dir).print());
                return(true);
            }
            else if (destination.GetStatus() == Tile.Status.box && destination.GetBox().isInTribox()) //if destination has a box part of tribox is eligible to Move or Rotate
            {
                TriBox tri = destination.GetBox().GetTriBox();

                /*
                 * if (destination.GetBox ().isCenterBox ())
                 * {
                 *  print("tried to move center");
                 *  //need to check if can move, then move
                 *
                 *  return false;
                 * }
                 */

                //check if can rotate, then rotate (check already inside rotate)
                //or if can move from below edges

                bool clockw = true;
                switch (dir)
                {
                case UtilityTools.Directions.up:
                    if (tri.IsVertical())
                    {
                        //if moving from the lowest box, need to move up
                        if (destination.GetBox().isDirectionMost(UtilityTools.OppositeDirection(dir)))
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (destination.GetBox().isCenterBox())
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            //try to rotate
                            //print("trying to UP, colliding box " + destination.GetBox() + " vs actual First" + tri.GetBoxes ().First ());
                            clockw = (destination.GetBox().isDirectionMost(UtilityTools.Directions.left));
                            return(tri.canRotate(clockw));
                        }
                    }

                    break;

                case UtilityTools.Directions.upRight:

                    break;

                case UtilityTools.Directions.right:

                    if (!tri.IsVertical())
                    {
                        if (destination.GetBox().isDirectionMost(UtilityTools.OppositeDirection(dir)))
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (destination.GetBox().isCenterBox())
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            //try to rotate
                            //print("trying to Right, colliding box " + destination.GetBox() + " vs actual First" + tri.GetBoxes ().First ());
                            clockw = (destination.GetBox().isDirectionMost(UtilityTools.Directions.up));
                            return(tri.canRotate(clockw));
                        }
                    }

                    break;

                case UtilityTools.Directions.downRight:

                    break;

                case UtilityTools.Directions.down:
                    if (tri.IsVertical())
                    {
                        //need to move down
                        if (destination.GetBox().isDirectionMost(UtilityTools.OppositeDirection(dir)))
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (destination.GetBox().isCenterBox())
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            //try to rotate
                            //print("trying to DOWN, colliding box " + destination.GetBox() + " vs actual last" + tri.GetBoxes ().Last ());
                            clockw = (destination.GetBox().isDirectionMost(UtilityTools.Directions.right));
                            return(tri.canRotate(clockw));
                        }
                    }

                    break;

                case UtilityTools.Directions.downLeft:
                    break;

                case UtilityTools.Directions.left:

                    if (!tri.IsVertical())
                    {
                        //need to move left
                        if (destination.GetBox().isDirectionMost(UtilityTools.OppositeDirection(dir)))
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (destination.GetBox().isCenterBox())
                        {
                            return(tri.canMove(dir));
                        }
                        else
                        {
                            //try to rotate
                            //print("trying to LEFT, colliding box " + destination.GetBox() + " vs actual last" + tri.GetBoxes ().Last ());
                            clockw = (destination.GetBox().isDirectionMost(UtilityTools.Directions.down));
                            return(tri.canRotate(clockw));
                        }
                    }

                    break;

                case UtilityTools.Directions.upLeft:
                    break;

                default:
                    return(false);
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
    }
예제 #18
0
    private bool Move(UtilityTools.Directions dir)
    {
        if (isMoving == true || grid_ref.IsMatch3Phase())
        {
            return(false);
        }
        else if (isMoving == false && checkDestination(dir)) //move only if not already moving and if destination is available
        {
            //thren update player's and tile's new values/statuses
            isMoving = true;
            Tile destination = grid_ref.GetTile(index.getNeighbourPoint(dir));
            if (destination == null)
            {
                return(false);
            }

            if (destination.GetStatus() == Tile.Status.box) // need to move or rotate tribox
            {
                destination.GetBox().Push(dir);
            }

            Vector3 destinationPos = destination.transform.position;
            destinationPos.z = -1;
            transform.DOMove(destinationPos, TheGrid.moveTime).OnComplete(() =>
            {
                isMoving = false;
            });

            tile.setStatus(Tile.Status.empty);
            destination.setStatus(Tile.Status.player);
            tile = destination;
            lastIndex.Copy(index);
            setIndex(destination.GetPoint().Clone());

            lastNeighbourTriboxes = neighbourTriboxes;
            neighbourTriboxes     = GetAllNeighbourTriboxes();
            foreach (TriBox tri in neighbourTriboxes)
            {
                tri.Highlight(true);
            }

            foreach (TriBox tri in lastNeighbourTriboxes)
            {
                if (!neighbourTriboxes.Contains(tri))
                {
                    tri.Highlight(false);
                }
            }

            if (stepAudioClip)
            {
                audioSource.clip = stepAudioClip;
                audioSource.Play();
            }

            return(true);
        }
        else
        {
            Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

            if ((input.magnitude < 1 || input == Vector2.zero || input.magnitude > 1) == false)
            {
                if (missStepAudioClip)
                {
                    audioSource.clip = missStepAudioClip;
                    if (audioSource.clip == missStepAudioClip && canMissStepPlay)
                    {
                        canMissStepPlay = false;
                        audioSource.Play();
                    }
                }
            }
            else if (input == Vector2.zero)
            {
                canMissStepPlay = true;
            }

            return(false);
        }
    }
예제 #19
0
    public bool isMyNeighbourEmpty(UtilityTools.Directions dir)
    {
        Tile neighbour = getNeighbourTile(dir);

        return((neighbour == null) ? false : neighbour.isEmpty());
    }
예제 #20
0
    public List <Box> getConnectedMatches(UtilityTools.Directions axisDir)
    {
        Box.Element matchElement = this.element;
        List <Box>  result       = new List <Box>();

        int maxLoops = 0;

        if (matchElement == Box.Element.quintessential)
        {
            print("roxo!");
        }

        if (UtilityTools.horizontals.Contains(axisDir))
        {
            if (getNeighbourTile(UtilityTools.Directions.right) == null && getNeighbourTile(UtilityTools.Directions.left) == null)
            {
                return(result);
            }

            //get all connected ones left and right
            List <Box> mixedRight = (getConnectedBoxes(UtilityTools.Directions.right));
            List <Box> mixedLeft  = (getConnectedBoxes(UtilityTools.Directions.left));

            if (this.element == Element.quintessential)
            {
                Element leftElement  = Element.quintessential;
                Element rightElement = Element.quintessential;
                Box     neigh        = getNextNonElementNeighbour(UtilityTools.Directions.right, this.element, ref maxLoops);
                if (neigh != null)
                {
                    rightElement = neigh.GetElement();
                }

                neigh = getNextNonElementNeighbour(UtilityTools.Directions.left, this.element, ref maxLoops);

                if (neigh != null)
                {
                    leftElement = neigh.GetElement();
                }

                //if different, need to check for matches at the left and at the right
                if (leftElement != rightElement)
                {
                    mixedLeft  = mixedLeft.Distinct().OrderBy(x => x.GetPoint().x).ToList();
                    mixedRight = mixedRight.Distinct().OrderBy(x => x.GetPoint().x).ToList();

                    mixedLeft.RemoveAll(x => x.GetElement() != leftElement && x.GetElement() != Box.Element.quintessential);
                    mixedRight.RemoveAll(x => x.GetElement() != rightElement && x.GetElement() != Box.Element.quintessential);
                    mixedLeft  = getFirstConnectedMatches(mixedLeft);
                    mixedRight = getFirstConnectedMatches(mixedRight);

                    bool leftPass  = false;
                    bool rightPass = false;

                    //if (areAllConnected(axisDir, mixedLeft) && mixedLeft.Count >= TheGrid.matchSize)
                    //{
                    //    result.AddRange(mixedLeft);
                    //    leftPass = true;
                    //}
                    //if (areAllConnected(axisDir, mixedRight) && mixedRight.Count >= TheGrid.matchSize)
                    //{
                    //    rightPass = true;
                    //}

                    //if (rightPass)
                    //{
                    //    if ((leftPass && mixedRight.Count > mixedLeft.Count) || leftPass == false)
                    //    {
                    //        result.AddRange(mixedRight);
                    //    }
                    //}
                    //else if (leftPass)
                    //{
                    //    if ((rightPass && mixedRight.Count < mixedLeft.Count) || rightPass == false)
                    //    {
                    //        result.AddRange(mixedRight);
                    //    }
                    //}

                    if (mixedLeft.Count >= TheGrid.matchSize && mixedRight.Count < mixedLeft.Count)
                    {
                        result.AddRange(mixedLeft);
                    }
                    else if (mixedRight.Count >= TheGrid.matchSize && mixedRight.Count > mixedLeft.Count)
                    {
                        result.AddRange(mixedRight);
                    }

                    if (result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
                    {
                        result.Clear();
                    }

                    return(result);
                }
                else
                {
                    matchElement = rightElement;
                }
            }

            result.AddRange(mixedLeft.Distinct());
            result.AddRange(mixedRight.Distinct());

            //order them by left to right
            result = result.Distinct().OrderBy(x => x.GetPoint().x).ToList();

            //remove all elements that arent a match (itself or quint)
            result.RemoveAll(x => x.GetElement() != matchElement && x.GetElement() != Box.Element.quintessential);
            result = getFirstConnectedMatches(result);

            //not matches!!!
            if (!areAllConnected(axisDir, result) || result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
            {
                result.Clear();
            }

            return(result);
        }
        else if (UtilityTools.verticals.Contains(axisDir))
        {
            if (getNeighbourTile(UtilityTools.Directions.up) == null && getNeighbourTile(UtilityTools.Directions.down) == null)
            {
                return(result);
            }

            //get all connected ones left and right
            List <Box> mixedUp   = (getConnectedBoxes(UtilityTools.Directions.up));
            List <Box> mixedDown = (getConnectedBoxes(UtilityTools.Directions.down));

            if (this.element == Element.quintessential)
            {
                Element downElement = Element.quintessential;
                Element upElement   = Element.quintessential;
                Box     neigh       = getNextNonElementNeighbour(UtilityTools.Directions.up, this.element, ref maxLoops);
                if (neigh != null)
                {
                    upElement = neigh.GetElement();
                }

                neigh = getNextNonElementNeighbour(UtilityTools.Directions.down, this.element, ref maxLoops);

                if (neigh != null)
                {
                    downElement = neigh.GetElement();
                }

                //if different, need to check for matches at the left and at the right
                if (downElement != upElement)
                {
                    mixedDown = mixedDown.Distinct().OrderBy(x => x.GetPoint().y).ToList();
                    mixedUp   = mixedUp.Distinct().OrderBy(x => x.GetPoint().y).ToList();

                    mixedDown.RemoveAll(x => x.GetElement() != downElement && x.GetElement() != Box.Element.quintessential);
                    mixedUp.RemoveAll(x => x.GetElement() != upElement && x.GetElement() != Box.Element.quintessential);
                    mixedDown = getFirstConnectedMatches(mixedDown);
                    mixedUp   = getFirstConnectedMatches(mixedUp);

                    bool downPass = false;
                    bool upPass   = false;
                    //if (areAllConnected(axisDir, mixedDown) && mixedDown.Count >= TheGrid.matchSize)
                    //{
                    //    result.AddRange(mixedDown);
                    //    downPass = true;
                    //}
                    //if (areAllConnected(axisDir, mixedUp) && mixedUp.Count >= TheGrid.matchSize)
                    //{
                    //    upPass = true;
                    //}

                    //if (upPass)
                    //{
                    //    if ((downPass && mixedUp.Count > mixedDown.Count) || downPass == false)
                    //    {
                    //        result.AddRange(mixedUp);
                    //    }
                    //}
                    //else if (downPass)
                    //{
                    //    if ((upPass && mixedUp.Count < mixedDown.Count) || upPass == false)
                    //    {
                    //        result.AddRange(mixedUp);
                    //    }
                    //}

                    if (mixedUp.Count >= TheGrid.matchSize && mixedUp.Count > mixedDown.Count)
                    {
                        result.AddRange(mixedUp);
                    }
                    else if (mixedDown.Count >= TheGrid.matchSize && mixedDown.Count > mixedUp.Count)
                    {
                        result.AddRange(mixedDown);
                    }

                    if (result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
                    {
                        result.Clear();
                    }

                    return(result);
                }
                else
                {
                    matchElement = upElement;
                }
            }

            result.AddRange(mixedDown.Distinct());
            result.AddRange(mixedUp.Distinct());

            //order them by left to right
            result = result.Distinct().OrderBy(x => x.GetPoint().y).ToList();

            //remove all elements that arent a match (itself or quint)
            result.RemoveAll(x => x.GetElement() != matchElement && x.GetElement() != Box.Element.quintessential);
            result = getFirstConnectedMatches(result);

            //not matches!!!
            if (!areAllConnected(axisDir, result) || result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
            {
                result.Clear();
            }

            return(result);
        }
        else
        {
            return(result);
        }
    }