Пример #1
0
        public void CheckCollisions()
        {
            List <Tetromino> copyOfTetrominos = new List <Tetromino>(Tetromino.DockedTetrominos);

            foreach (Block block in ActiveTetromino.Shape)
            {
                foreach (Tetromino tetromino in copyOfTetrominos)
                {
                    foreach (Block tetrominoBlock in tetromino.Shape)
                    {
                        block.SetBounds(block.Left, block.Top, block.Width, block.Height + 1);

                        if (block.Bounds.IntersectsWith(tetrominoBlock.Bounds))
                        {
                            TetrominoDocked?.Invoke(this);
                        }

                        block.SetBounds(block.Left, block.Top, block.Width, block.Height - 1);
                    }
                }
            }
        }
Пример #2
0
        public void MoveTetromino(MovingDirections movingDirection)
        {
            switch (movingDirection)
            {
            case MovingDirections.Left:
                bool allowMovementLeft = true;
                foreach (Block block in Shape)
                {
                    if (block.Left <= 0)
                    {
                        allowMovementLeft = false;
                    }
                }

                if (!allowMovementLeft)
                {
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }

                break;

            case MovingDirections.Right:
                bool allowMovementRight = true;
                foreach (Block block in Shape)
                {
                    if (block.Right >= TetrisConfig.getFieldWidth())
                    {
                        allowMovementRight = false;
                    }
                }

                if (!allowMovementRight)
                {
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }
                break;

            case MovingDirections.Down:
                bool allowMovementDown = true;
                foreach (Block block in Shape)
                {
                    if (block.Bottom >= TetrisConfig.getFieldHeight())
                    {
                        allowMovementDown = false;
                    }
                }

                if (!allowMovementDown)
                {
                    TetrominoDocked?.Invoke(this);
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }
                break;

            default:
                break;
            }
        }