示例#1
0
        private void updateGameBoard()
        {
            oVuong cell;

            for (int row = 0; row < numRows; row++)
            {
                for (int col = 0; col < numCols; col++)
                {
                    boardCells.TryGetValue(oVuongKey(row, col), out cell);
                    cell.oVuongColor = board.grid[row, col];
                }
            }
            Tetromino block = board.currentBlock;

            for (int row = 0; row < block.currBlock.GetLength(0); row++)
            {
                for (int col = 0; col < block.currBlock.GetLength(1); col++)
                {
                    ToaDo c = new ToaDo(col, row);
                    c = block.toBoardCoord(c);
                    if (block.currBlock[row, col] && c.x >= 0 && c.x < numCols && c.y < numRows)
                    {
                        boardCells.TryGetValue(oVuongKey(c.y, c.x), out cell);

                        cell.oVuongColor = block.blockColor;
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Returns true if a cell is occupied otherwise false
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 private bool isOccupiedCell(ToaDo c)
 {
     if (c.x < numCols && c.x >= 0 && c.y < numRows && c.y >= 0 && this.grid[c.y, c.x] == this.boardColor)
     {
         return(false);
     }
     return(true);
 }
示例#3
0
 public Board()
 {
     this.rowsCompleted = 0;
     this.currentLevel  = 1;
     this.score         = 0;
     this.currentBlock  = new Tetromino();
     this.coord         = new ToaDo(0, 0);
     this.colorCodeBoard();
 }
示例#4
0
        /// <summary>
        /// Lock the last played block into position once it is done moving
        /// </summary>
        private void lockLastBlock()
        {
            if (currentBlock.currBlock != null)
            {
                ToaDo c   = null;
                int   dim = 4;

                for (int row = 0; row < dim; row++)
                {
                    for (int col = 0; col < dim; col++)
                    {
                        if (currentBlock.currBlock[row, col])
                        {
                            c = currentBlock.toBoardCoord(new ToaDo(col, row));
                            this.grid[c.y, c.x] = currentBlock.blockColor;
                        }
                    }
                }
            }
        }
示例#5
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);
        }
示例#6
0
 public ToaDo toBoardCoord(ToaDo coord)
 {
     coord.x += this.x;
     coord.y += this.y;
     return(coord);
 }