Exemple #1
0
 /// <summary>
 /// Checks to see if the Current Falling Block Can Rotate the Block Right
 /// </summary>
 /// <returns>True, it did rotate.  False, if it didn't</returns>
 private bool CheckRotateRight()
 {
     //If the Block is hitting blocks then rotate it back Left (CCW)
     foreach (var item in BlockThatsFalling.BlockCells)
     {
         if (_cells[item.CellLocationX, item.CellLocationY].Filled == true)
         {
             BlockThatsFalling.RotateLeft();
             return(false);
         }
     }
     return(true);
 }
Exemple #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();
            }
        }