Ejemplo n.º 1
0
        /// <summary>
        /// Create a new level.
        /// </summary>
        /// <param name="width">Width of the level in number of blocks.</param>
        /// <param name="height">Height of the level in number of blocks.</param>
        public GamePlayManager(int width, int height)
        {
            //Set up the starting matrix and set it to all zeroes.
            levelGrid = new int[width, height];
            Array.Clear(levelGrid, 0, levelGrid.Length);

            //Generate the first block, and set up rotation subsystem.
            blockFactory = new BlockFactory();
            wallKickData = new WallKickData();

            activeBlock = blockFactory.GetNewBlock();
            activeBlockPosition = spawnPoint;

            //Generate the next 3 blocks.
            nextBlocks = new Queue<Block>();
            for (int i = 0; i < 3; i++)
            {
                nextBlocks.Enqueue(blockFactory.GetNewBlock());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Puts a new block in the level.
        /// </summary>
        /// <returns>Returns a value indicating if switching to the new block was succesful.</returns>
        /// <remarks>TODO: Separate the check for the possibility of adding a block from the actual adding.</remarks>
        public void ActivateNextBlock()
        {
            activeBlockPosition = spawnPoint;

            //Get next block from the queue.
            activeBlock = nextBlocks.Dequeue();
            nextBlocks.Enqueue(blockFactory.GetNewBlock());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if a block can be placed at the specified position.
        /// </summary>
        /// <param name="block">The block that needs to be checked.</param>
        /// <param name="position">Relative position on the LevelGrid.</param>
        /// <returns></returns>
        private bool BlockPositionIsValid(Block block, Point position)
        {
            //Check if block would be out of bounds of the level.
            if (position.X + block.Offset.X < 0 ||
                position.X + block.Offset.X + block.Width > levelGrid.GetUpperBound(0) + 1 ||
                position.Y + block.Offset.Y < 0 ||
                position.Y + block.Offset.Y + block.Height > levelGrid.GetUpperBound(1) + 1
                )
                return false;

            //Check if block would overlap any existing blocks in the level.
            for (int x = 0; x < block.Width; x++)
            {
                for (int y = 0; y < block.Height; y++)
                {
                    if (levelGrid[x + position.X + block.Offset.X, y + position.Y + block.Offset.Y] > 0)
                    {
                        if (block.Shape[x, y] > 0)
                            return false;
                    }
                }
            }

            //The block is valid if it has passed all previous validations.
            return true;
        }