예제 #1
0
 public Board()
 {
     this.rowsCompleted = 0;
     this.currentLevel  = 1;
     this.score         = 0;
     this.currentBlock  = new Tetromino();
     this.coord         = new ToaDo(0, 0);
     this.colorCodeBoard();
 }
예제 #2
0
        /// <summary>
        /// Returns true if the current block can drop one row down else false
        /// </summary>
        /// <returns></returns>
        private bool canDrop()
        {
            bool      canDrop   = true;
            Tetromino ifDropped = currentBlock.Clone();

            ifDropped.y++;

            if (!canBeThere(ifDropped))
            {
                canDrop = false;
            }
            return(canDrop);
        }
예제 #3
0
        /// <summary>
        /// Returns true if the current block is allowed to make its next move else false
        /// </summary>
        /// <param name="ablock"></param>
        /// <returns></returns>
        private bool canBeThere(Tetromino ablock)
        {
            bool isMoveable = true;
            int  dim        = 4;

            for (int row = 0; row < dim; row++)
            {
                for (int col = 0; col < dim; col++)
                {
                    if (ablock.currBlock[row, col])
                    {
                        ToaDo c = ablock.toBoardCoord(new ToaDo(col, row));
                        if (isOccupiedCell(c) || c.x >= numCols || c.x < 0 || c.y >= numRows)
                        {
                            isMoveable = false;
                        }
                    }
                }
            }
            return(isMoveable);
        }
예제 #4
0
        /// <summary>
        /// Returns true if the current block can rotate else false
        /// </summary>
        /// <param name="clockwise"></param>
        /// <returns></returns>
        private bool canRotate(bool clockwise)
        {
            bool      isRotatable = true;
            Tetromino whenRotated = currentBlock.Clone();

            if (clockwise)
            {
                whenRotated.rotateClockwise();
            }
            else
            {
                whenRotated.rotateCounterClockwise();
            }

            if (!canBeThere(whenRotated))
            {
                isRotatable = false;
            }

            return(isRotatable);
        }
예제 #5
0
        /// <summary>
        /// Returns true if the current block can move sideways else false
        /// </summary>
        /// <param name="left"></param>
        /// <returns></returns>
        private bool canMoveSideWays(bool left)
        {
            bool      isMoveable = true;
            Tetromino whenMoved  = currentBlock.Clone();

            if (left)
            {
                whenMoved.x--;
            }
            else
            {
                whenMoved.x++;
            }

            if (!canBeThere(whenMoved))
            {
                isMoveable = false;
            }

            return(isMoveable);
        }