Пример #1
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);
            }
        }
    }
Пример #2
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;
        }
    }