Пример #1
0
 public void RemovePiece(Piece piece)
 {
     for (var i = 0; i < TOTAL_CELL_COUNT; i++)
     {
         // Piece objects are unique, so use reference equality
         if (_boardCells[i].Piece == piece)
         {
             _boardCells[i].Piece = null;
         }
     }
 }
Пример #2
0
 public bool PlacePiece(Piece piece, int boardCellIdx)
 {
     // We will manipulate the piece using its first cell
     return PlacePiece(piece, 0, boardCellIdx);
 }
Пример #3
0
 private bool PlacePiece(Piece piece, int pieceCellIdx, int boardCellIdx)
 {
     // We're going to process the piece
     piece.ResetProcessed();
     // Get all the boardCells that this piece would occupy
     var occupiedBoardCells = new List<BoardCell>();
     FindOccupiedBoardCells(occupiedBoardCells, piece.GetPieceCell(pieceCellIdx), _boardCells[boardCellIdx]);
     if (occupiedBoardCells.Count != Piece.NUMBER_OF_CELLS)
     {
         // Some cells of the piece don't fall on the board
         return false;
     }
     if (occupiedBoardCells.Any(t => t.Piece != null))
     {
         return false;
     }
     // Occupy the board cells with the piece
     foreach (var t in occupiedBoardCells)
     {
         t.Piece = piece;
     }
     return true; // The piece fits on the board
 }