Exemplo n.º 1
0
        /// <summary>
        /// Checks to see if the Current Falling Block Can Rotate the Block Left
        /// </summary>
        /// <returns>True, it did rotate.  False, if it didn't</returns>
        private bool CheckRotateLeft()
        {
            //Flag if the Block needs to be Updated after rotating back
            bool updateBlock = false;

            //If the Block is hitting blocks then rotate it back Right (CW)
            foreach (var item in BlockThatsFalling.BlockCells)
            {
                if (_cells[item.CellLocationX, item.CellLocationY].Filled == true)
                {
                    BlockThatsFalling.RotateRight();
                    updateBlock = true;
                    break;
                }
            }
            if (updateBlock)
            {
                //Updates the block CellLocation Y
                foreach (var item in BlockThatsFalling.BlockCells)
                {
                    if (_cells[item.CellLocationX, item.CellLocationY].Filled == true)
                    {
                        foreach (var cell in BlockThatsFalling.BlockCells)
                        {
                            cell.CellLocationY++;
                        }
                        break;
                    }
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Moves the Falling Block based on the Key Pressed
        /// </summary>
        /// <param name="keyPressed">The Key that was pressed on the KeyBoard</param>
        public void MovePiece(Keys keyPressed)
        {
            List <Cells> oldCells = null;

            try
            {
                //Tell the game that we are starting to move the Piece and it should surpress any and all Key Events
                StartedMoving?.Invoke();
                //No need if the space bar is pressed.
                if (keyPressed != Keys.Space)
                {
                    oldCells = GetOldCellsData();
                }
                switch (keyPressed)
                {
                case Keys.Right:
                    if (CheckRightSideForBlocks())
                    {
                        BlockThatsFalling.MoveRight();
                    }
                    break;

                case Keys.Left:
                    if (CheckLeftSideForBlocksAndWalls())
                    {
                        BlockThatsFalling.MoveLeft();
                    }
                    break;

                case Keys.Up:
                    if (IsItOkayToMove())
                    {
                        BlockThatsFalling.RotateRight();
                        CheckRotateRight();
                    }
                    break;

                case Keys.Down:
                    if (IsItOkayToMove())
                    {
                        BlockThatsFalling.RotateLeft();
                        CheckRotateLeft();
                    }
                    break;

                case Keys.Space:
                    if (BlockThatsFalling.IsItFalling)
                    {
                        DropBlockToTheBottom();
                    }
                    break;

                case Keys.V:
                    MoveFallingBlock();
                    break;

                case Keys.C:
                    if (_allowBlockToBeHeld)
                    {
                        _allowBlockToBeHeld = false;
                        HoldFallingBlock();
                    }
                    break;

                default:
                    break;
                }
            }
            finally
            {
                if (keyPressed != Keys.Space)
                {
                    DrawOutTheBlocks(oldCells);
                }
                //Signal the game that the piece is done moving
                DoneMoving?.Invoke();
            }
        }