Пример #1
0
 /// <summary>
 /// Detects if the tetromino is placed in an allready occupied position.
 /// </summary>
 /// <returns><c>true</c>, if placed in occupied position, <c>false</c> otherwise.</returns>
 /// <param name="tetromino">Tetromino.</param>
 private bool IsPlacedInOccupiedPosition(Tetromino tetromino)
 {
     for (int row = 0; row < tetromino.GetRowCount(); ++row)
     {
         for (int column = 0; column < tetromino.GetColumnCount(); ++column)
         {
             if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && 0 <= tetromino.AnchorPosition.Column + column && tetromino.AnchorPosition.Column + column < GRIDWIDTH && 0 <= tetromino.AnchorPosition.Row + row && tetromino.AnchorPosition.Row + row < GRIDHEIGHT && Field[tetromino.AnchorPosition.Row + row, tetromino.AnchorPosition.Column + column] != 0)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #2
0
 /// <summary>
 /// Checks if tetromino is outside of the grid.
 /// </summary>
 /// <returns><c>true</c>, if withing grid, <c>false</c> otherwise.</returns>
 /// <param name="tetromino">Tetromino.</param>
 private bool IsWithingGrid(Tetromino tetromino)
 {
     for (int row = 0; row < tetromino.GetRowCount(); ++row)
     {
         for (int column = 0; column < tetromino.GetColumnCount(); ++column)
         {
             if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && (tetromino.AnchorPosition.Column + column < 0 || GRIDWIDTH <= tetromino.AnchorPosition.Column + column || tetromino.AnchorPosition.Row + row < 0 || GRIDHEIGHT <= tetromino.AnchorPosition.Row + row))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #3
0
        /// <summary>
        /// Checks if it is an interfering tetromino above.
        /// </summary>
        /// <returns><c>true</c>, if interfering tetromino above was detected, <c>false</c> otherwise.</returns>
        /// <param name="tetromino">Tetromino.</param>
        private bool IsInterferingTetrominoAbove(Tetromino tetromino)
        {
            GridPosition position = tetromino.AnchorPosition;

            for (int row = 0; row < tetromino.GetRowCount(); ++row)
            {
                for (int column = 0; column < tetromino.GetColumnCount(); ++column)
                {
                    if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && row + position.Row - 1 < 0 && Field[position.Row + row - 1, position.Column + column] != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Checks if the tetromino is at top row.
        /// </summary>
        /// <returns><c>true</c>, if collision at top row was detected, <c>false</c> otherwise.</returns>
        /// <param name="tetromino">Tetromino.</param>
        public bool IsAtTopRow(Tetromino tetromino)
        {
            GridPosition position = tetromino.AnchorPosition;

            for (int row = 0; row < tetromino.GetRowCount(); ++row)
            {
                for (int column = 0; column < tetromino.GetColumnCount(); ++column)
                {
                    if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && row + position.Row - 1 < 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #5
0
        /// <summary>
        /// Checks if is is a tetromino below makes it impossible to move that way.
        /// </summary>
        /// <returns><c>true</c>, if interfering tetromino below was detected, <c>false</c> otherwise.</returns>
        /// <param name="tetromino">Tetromino.</param>
        private bool IsInterferingTetrominoBelow(Tetromino tetromino)
        {
            GridPosition position = tetromino.AnchorPosition;

            for (int row = 0; row < tetromino.GetRowCount(); ++row)
            {
                for (int column = 0; column < tetromino.GetColumnCount(); ++column)
                {
                    if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && (position.Row + row + 1) < GRIDHEIGHT && 0 <= position.Column + column && position.Column + column < GRIDWIDTH && Field[position.Row + row + 1, position.Column + column] != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #6
0
        /// <summary>
        /// Checks if the tetromino will go outside the grid to the right if it gets moved by one.
        /// </summary>
        /// <returns><c>true</c>, if collision at the right edge was detected, <c>false</c> otherwise.</returns>
        /// <param name="tetromino">Tetromino.</param>
        public bool IsAtRightEdge(Tetromino tetromino)
        {
            GridPosition position = tetromino.AnchorPosition;

            for (int row = 0; row < tetromino.GetRowCount(); ++row)
            {
                for (int column = 0; column < tetromino.GetColumnCount(); ++column)
                {
                    if (tetromino.Shape[tetromino.Rotation, row, column] != 0 && GRIDWIDTH <= column + position.Column + 1)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #7
0
 /// <summary>
 /// Places the tetromino on the grid if it is not placed allready.
 /// </summary>
 /// <param name="tetromino">Tetromino.</param>
 public void PlaceOnGrid(Tetromino tetromino)
 {
     if (!tetromino.IsLockedInPlace)
     {
         GridPosition position = tetromino.AnchorPosition;
         for (int row = 0; row < tetromino.GetRowCount(); ++row)
         {
             for (int column = 0; column < tetromino.GetColumnCount(); ++column)
             {
                 if (tetromino.Shape[tetromino.Rotation, row, column] != 0)
                 {
                     Field[position.Row + row, position.Column + column] = tetromino.Color;
                 }
             }
         }
         tetromino.IsLockedInPlace = true;
     }
 }