Exemplo n.º 1
0
    /// <summary>
    /// check if we can move figure (left or right)
    /// </summary>
    /// <param name="oldPoints">old points of descending blocks</param>
    /// <param name="leftOrRightMove">the parameter which get information aboute move(left or right)</param>
    /// <returns>true if we can</returns>
    private static bool CheckForMoveLeftOrRight(Point[] oldPoints, LeftOrRightMove leftOrRightMove)
    {
        //for move left
        if (oldPoints.Min(point => point.LeftShift) == 0 && leftOrRightMove == LeftOrRightMove.Left)
        {
            return(false);
        }

        // for move right
        if (oldPoints.Max(point => point.LeftShift) + 1 == Program.ColumnGameFieldCount && leftOrRightMove == LeftOrRightMove.Right)
        {
            return(false);
        }

        //for move right and left
        if ((oldPoints.Max(point => point.TopShift) == -1) ||
            (GameField[oldPoints[0].TopShift, oldPoints[1].LeftShift + 1 * (int)leftOrRightMove] <= TypeOfCell.Static) ||
            (GameField[oldPoints[1].TopShift, oldPoints[1].LeftShift + 1 * (int)leftOrRightMove] <= TypeOfCell.Static) ||
            (GameField[oldPoints[2].TopShift, oldPoints[2].LeftShift + 1 * (int)leftOrRightMove] <= TypeOfCell.Static) ||
            (GameField[oldPoints[3].TopShift, oldPoints[3].LeftShift + 1 * (int)leftOrRightMove] <= TypeOfCell.Static))
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// reset array for move(left or right)
    /// </summary>
    /// <param name="oldPoints">old points of descending blocks</param>
    /// <param name="leftOrRightMove">the parameter which get information aboute move(left or right)</param>
    private static void FillArrayForMoveLeftOrRight(Point[] oldPoints, LeftOrRightMove leftOrRightMove)
    {
        //reset data
        GameField[oldPoints[0].TopShift, oldPoints[0].LeftShift + 1 * (int)leftOrRightMove] = TypeOfCell.CenterOfFigure;

        GameField[oldPoints[1].TopShift, oldPoints[1].LeftShift + 1 * (int)leftOrRightMove] = TypeOfCell.Descending;
        GameField[oldPoints[2].TopShift, oldPoints[2].LeftShift + 1 * (int)leftOrRightMove] = TypeOfCell.Descending;
        GameField[oldPoints[3].TopShift, oldPoints[3].LeftShift + 1 * (int)leftOrRightMove] = TypeOfCell.Descending;
    }
Exemplo n.º 3
0
    /// <summary>
    /// reset console for move(left or right)
    /// </summary>
    /// <param name="oldPoints">old points of descending blocks</param>
    /// <param name="leftOrRightMove">the parameter which get information aboute move(left or right)</param>
    private static void FillConsoleForMoveLeftOrRight(Point[] oldPoints, LeftOrRightMove leftOrRightMove)
    {
        //set new foreground color
        Console.ForegroundColor = _currentFigure.ConsoleColor;

        //reset data
        foreach (var point in oldPoints)
        {
            Console.SetCursorPosition(point.LeftShift + Constants.LeftShiftOfGameFieldStartPoint + 1 * (int)leftOrRightMove,
                                      point.TopShift + Constants.TopShiftOfGameFieldStartPoint);
            Console.Write(Constants.Squere);
        }

        //reset old parameters
        Console.SetCursorPosition(0, 0);
        Console.ForegroundColor = Constants.MainColor;
    }
Exemplo n.º 4
0
    /// <summary>
    /// move current figure left or right
    /// </summary>
    /// <param name="leftOrRightMove">the parameter which get information aboute move(left or right)</param>
    private static void MoveLeftOrRight(LeftOrRightMove leftOrRightMove)
    {
        var oldPoints = FindOldPoints();

        var canMoveDown = CheckForMoveLeftOrRight(oldPoints, leftOrRightMove);

        //save blocks as static one and exit the method
        if (canMoveDown == false)
        {
            return;
        }

        ResetOldDataInGameFieldInArray(oldPoints);

        ResetOldDataInGameFieldInConsole(oldPoints);

        FillArrayForMoveLeftOrRight(oldPoints, leftOrRightMove);

        FillConsoleForMoveLeftOrRight(oldPoints, leftOrRightMove);
    }