Example #1
0
        bool CouldBlockMove(Direction direction)
        {
            BoundingBox b = CurrentBlock.BlockBounds[CurrentBlock.RotateIndex];
            int x = CurrentBlock.X;
            int y = CurrentBlock.Y;
            int rot = CurrentBlock.RotateIndex;
            switch (direction)
            {
                case Direction.Right:
                    for (int i = Block.BLOCK_SIZE - 1; i >= 0; i--)
                        for (int j = 0; j < Block.BLOCK_SIZE; j++)
                        {
                            if (CurrentBlock.Matrices[rot, i, j] == 0)
                                continue;
                            bool stop = false || GetF(i + x + 1, j + y) > 10;
                            if (direction == CurrentBlock.MoveDirection)
                                stop = stop || (i + x + 1 > FIELD_X / 2 - 1);
                            else
                                stop = stop || (i + x + 1 > FIELD_X - 1);
                            if (stop)
                                return false;
                        }
                    break;

                case Direction.Left:
                    for (int i = 0; i < Block.BLOCK_SIZE; i++)
                        for (int j = 0; j < Block.BLOCK_SIZE; j++)
                        {
                            if (CurrentBlock.Matrices[rot, i, j] == 0)
                                continue;
                            bool stop = false || GetF(i + x - 1, j + y) > 10;
                            if (direction == CurrentBlock.MoveDirection)
                                stop = stop || (i + x - 1 < FIELD_X / 2);
                            else
                                stop = stop || (i + x - 1 < 0);
                            if (stop)
                                return false;
                        }
                    break;

                case Direction.Top:
                    for (int j = 0; j < Block.BLOCK_SIZE; j++)
                        for (int i = 0; i < Block.BLOCK_SIZE; i++)
                        {
                            if (CurrentBlock.Matrices[rot, i, j] == 0)
                                continue;
                            bool stop = false || GetF(i + x, j + y - 1) > 10;
                            if (direction == CurrentBlock.MoveDirection)
                                stop = stop || (j + y - 1 < FIELD_Y / 2);
                            else
                                stop = stop || (j + y - 1 < 0);
                            if (stop)
                                return false;
                        }
                    break;

                case Direction.Bottom:
                    for (int j = Block.BLOCK_SIZE - 1; j >= 0; j--)
                        for (int i = 0; i < Block.BLOCK_SIZE; i++)
                        {
                            if (CurrentBlock.Matrices[rot, i, j] == 0)
                                continue;
                            bool stop = false || GetF(i + x, j + y + 1) > 10;
                            if (direction == CurrentBlock.MoveDirection)
                                stop = stop || (j + y + 1 > FIELD_Y / 2 - 1);
                            else
                                stop = stop || (j + y + 1 > FIELD_Y - 1);
                            if (stop)
                                return false;
                        }
                    break;
            }

            return true;
        }
Example #2
0
        void AddBlock(Direction origin)
        {
            //if (CurrentBlock != null)
            //    CurrentBlock = null;
            if (NextBlock == null)
                NextBlock = Block.CreateRandomBlock();

            CurrentBlock = NextBlock;
            NextBlock = Block.CreateRandomBlock();

            BoundingBox b = CurrentBlock.BlockBounds[CurrentBlock.RotateIndex];
            switch (origin)
            {
                case Direction.Right:
                    CurrentBlock.X = FIELD_X - 1 - b.Right;
                    CurrentBlock.Y = FIELD_Y / 2 - Block.BLOCK_CENTER_Y;
                    CurrentBlock.MoveDirection = Direction.Left;
                    //todo:
                    //alphaHorLine = LINE_INACTIVE_ALPHA;
                    //alphaVertLine = LINE_ACTIVE_ALPHA;
                    //next dir - from top
                    //nextblockdir rotation
                    break;

                case Direction.Left:
                    CurrentBlock.X = -CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Left;
                    CurrentBlock.Y = FIELD_Y / 2 - Block.BLOCK_CENTER_Y;
                    CurrentBlock.MoveDirection = Direction.Right;
                    break;

                case Direction.Top:
                    CurrentBlock.X = FIELD_X / 2 - 1 - Block.BLOCK_CENTER_X;
                    CurrentBlock.Y = -CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Top;
                    CurrentBlock.MoveDirection = Direction.Bottom;
                    break;

                case Direction.Bottom:
                    CurrentBlock.X = FIELD_X / 2 - 1 - Block.BLOCK_CENTER_X;
                    CurrentBlock.Y = FIELD_Y - CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Bottom - 1;
                    CurrentBlock.MoveDirection = Direction.Top;
                    break;
            }
        }