Ejemplo n.º 1
0
    /// <summary>
    /// This method is used everytime a cell has received the instruction of being "erased".
    /// Makes the respective action depending on the cell direction.
    /// </summary>
    /// <param name="cellToClear">The cell that has to be erased
    private void ClearPath(Cell cellToClear)
    {
        while (cellStack.Count > 1 && cellToClear != cellStack.Peek())
        {
            _lastActivatedCell = cellStack.Peek();
            cellStack.Peek().DeactivateCell();
            switch (cellStack.Peek().GetDirection())
            {
            //In case the direction of the cell that is gonna be erased:

            /*
             * LEFT: Deactivate any direction of any cell.
             */
            case Cell.DIRS.LEFT:
                cellStack.Peek().DeactivateDirectionLine();
                if (cellToClear.GetDirection() == Cell.DIRS.NONE)
                {
                    cellToClear.DeactivateDirectionLine();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.DOWN)
                {
                    cellToClear.ActivateVertical();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.UP)
                {
                    cellToClear.DeactivateVertical();
                }
                break;

            /*
             * RIGHT: Deactivate any direction of any cell and deactive direction of itself depending of its own direction
             */
            case Cell.DIRS.RIGHT:
                cellStack.Peek().DeactivateDirectionLine();
                if (cellToClear.GetDirection() == Cell.DIRS.DOWN)
                {
                    cellToClear.ActivateVertical();
                    cellToClear.DeactivateHorizontal();
                }
                else
                {
                    cellToClear.DeactivateHorizontal();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.NONE)
                {
                    cellToClear.DeactivateDirectionLine();
                }
                break;

            /*
             * UP: Deactivate vertical direction of itself and activate its horizontal direction depending of previous cell's direction
             */
            case Cell.DIRS.UP:
                cellToClear.DeactivateVertical();
                if (cellToClear.GetDirection() == Cell.DIRS.LEFT)
                {
                    cellToClear.ActivateHorizontal();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.NONE)
                {
                    cellToClear.DeactivateDirectionLine();
                }
                break;

            /*
             * DOWN: Deactivate any direction of any cell and activate or deactivate its own directions depending of previous cell's direction
             */
            case Cell.DIRS.DOWN:
                cellStack.Peek().DeactivateDirectionLine();
                if (cellToClear.GetDirection() == Cell.DIRS.LEFT)
                {
                    cellToClear.ActivateHorizontal();
                    cellToClear.DeactivateVertical();
                }
                else
                {
                    cellToClear.DeactivateHorizontal();
                    cellToClear.DeactivateVertical();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.DOWN || cellToClear.GetDirection() == Cell.DIRS.UP)
                {
                    cellToClear.ActivateVertical();
                }
                if (cellToClear.GetDirection() == Cell.DIRS.NONE)
                {
                    cellToClear.DeactivateDirectionLine();
                }
                break;

            /*
             * NONE: Deactivate everything
             */
            case Cell.DIRS.NONE:
                cellToClear.DeactivateDirectionLine();
                break;
            }
            cellStack.Pop();
            _cellsFilled--;
            currentCellCoordinates = cellToClear.GetCoordinates();
        }
    }