Exemplo n.º 1
0
        private void CheckForBottomCollision()
        {
            lock (moveMutex)
            {
                //First check for collision with other tetrominoes
                var blocks = actualTetramino.GetBlocks();
                int width  = actualTetramino.GetBlockWidth();
                int height = actualTetramino.GetBlockHeight();

                int left, top;
                int grid_x, grid_y;

                foreach (Block b in blocks)
                {
                    top    = b.GetTop();
                    left   = b.GetLeft();
                    grid_y = top / height;
                    grid_x = left / width;

                    if ((top + height) == view.CanvasHeight)
                    {
                        bottomCollision = true;
                        break;
                    }
                    else
                    {
                        if (landedBlocks[grid_y + 1, grid_x] != null)
                        {
                            bottomCollision = true;
                            break;
                        }
                    }
                }

                if (bottomCollision && !gameOver)
                {
                    foreach (Block b in blocks)
                    {
                        top    = b.GetTop();
                        left   = b.GetLeft();
                        grid_y = top / height;
                        grid_x = left / width;

                        landedBlocks[grid_y, grid_x] = b;
                        blocksPerRow[grid_y]        += 1;
                    }
                }
            }
        }