Ejemplo n.º 1
0
    public bool IsObstructed(TetrisPiece piece, ObstructionDirection direction)
    {
        bool isObstructed = false;

        int yCheck = 0;
        int xCheck = 0;

        switch (direction)
        {
        case ObstructionDirection.DOWN:
        {
            yCheck = 1;
            xCheck = 0;
        }
        break;

        case ObstructionDirection.LEFT:
        {
            yCheck = 0;
            xCheck = -1;
        }
        break;

        case ObstructionDirection.RIGHT:
        {
            yCheck = 0;
            xCheck = 1;
        }
        break;
        }

        for (int itRow = piece.size.row - 1; itRow >= 0; itRow--)
        {
            for (int itCol = 0; itCol < piece.size.col; itCol++)
            {
                // check block is filled
                if (piece.Get(itRow, itCol) == 1)
                {
                    int rowPos = (piece.position.row + itRow) + yCheck;
                    int colPos = (piece.position.col + itCol) + xCheck;

                    if (rowPos >= 0 && rowPos < this.row &&
                        colPos >= 0 && colPos < this.col)
                    {
                        if (boardData[rowPos, colPos] == 1)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        // hit bottom
                        return(true);
                    }
                }
            }
        }

        return(isObstructed);
    }
Ejemplo n.º 2
0
 public void AttachPiece(TetrisPiece piece)
 {
     if (IsInside(piece))
     {
         for (int itRow = 0; itRow < piece.size.row; itRow++)
         {
             for (int itCol = 0; itCol < piece.size.col; itCol++)
             {
                 if (piece.Get(itRow, itCol) == 1)
                 {
                     boardData[piece.position.row + itRow, piece.position.col + itCol]   = piece.Get(itRow, itCol);
                     tetrisCells[piece.position.row + itRow, piece.position.col + itCol] = piece.GetCell(itRow, itCol);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public bool IsInside(TetrisPiece piece)
 {
     for (int itRow = 0; itRow < piece.size.row; itRow++)
     {
         for (int itCol = 0; itCol < piece.size.col; itCol++)
         {
             if (piece.Get(itRow, itCol) == 1)
             {
                 if (piece.position.row + itRow >= 0 && piece.position.row + itRow < row &&
                     piece.position.col + itCol >= 0 && piece.position.col < col)
                 {
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }