public void AddPieceToBoard(Piece piece) { if (piece.Color == ChessColor.White) { WhitePieces.Add(piece); } else { BlackPieces.Add(piece); } }
// // Summary: // The basic constructor of a DraughtsMatch.s public DraughtsMatch() { // // Place the red pieces in their initial positions and place the piece in a collection. for (int arrRow = 0; arrRow <= 3; arrRow++) { // // Explanation about the value to be assigned to arrColumn variable: // // Arrray's odd lines will have their frist pieces in column 0, // while Even lines will have the frist pieces in the array column 1. for (int arrColumn = 1 - arrRow % 2; arrColumn < Board.Width; arrColumn += 2) { Board.PlacePiece( new Pawn(new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height), Board, Team.Red), new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height)); RedPieces.Add(Board.Pieces(arrRow, arrColumn)); } } // // Place the white pieces in their initial positions and place the piece in a collection. for (int arrRow = 6; arrRow < Board.Height; arrRow++) { // // Explanation about the value to be assigned to arrColumn variable: // // Arrray's odd lines will have their frist pieces in column 0, // while Even lines will have the frist pieces in the array column 1. for (int arrColumn = 1 - arrRow % 2; arrColumn < Board.Width; arrColumn += 2) { Board.PlacePiece( new Pawn(new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height), Board, Team.White), new TwoDimensionsArrayPosition(arrRow, arrColumn).ToBoardPosition(Board.Height)); WhitePieces.Add(Board.Pieces(arrRow, arrColumn)); } } Round = 1; TurnPlayer = Team.White; }
/// <summary> /// Add a piece to the board, if there already is a piece on the same square then remove the current piece /// </summary> /// <param name="piece"></param> public void AddPiece(Piece piece) { // see if there already is a piece at that position Piece overridenPiece = GetPiece(piece.Position); if (overridenPiece != null) { //this.Remove(overridenPiece); } // Add new piece _pieces.Add(piece); // Make sure that the black and white pices lists are keeps up to date if (piece.Side == Globals.Side.Black) { BlackPieces.Add(piece); } else { WhitePieces.Add(piece); } }