//constructor with the piece public BoardCell(int Y, int X, string CellType, BoardPiece Piece) { DefaultImage = CellType; DefaultHighlightImage = CellType; this.X = X; this.Y = Y; SetPiece(Piece);//set the piece as current piece }
/// <summary> /// recieve BoardPiece and set it as current piece /// </summary> /// <param name="Piece"></param> /// <returns></returns> public bool SetPiece(BoardPiece Piece) { CurrentPiece = Piece; if (CurrentPiece != null) { CurrentPiece.X = X; CurrentPiece.Y = Y; SetSourceImage(CurrentPiece.DefaultHighlightImage); } else { SetSourceImage(DefaultImage); } return(true); }
/// <summary> /// draw board using 2D array with alternate black and white cells /// and then populate with pieces on the black cell /// </summary> public void drawBoard() { content = new BoardCell[8, 8]; int cellColor = 1; // 0 for white and 1 for black string pieceColor = null; bool WhiteCell = false; for (int i = 0; i < 8; i++)// to generate alternate cell colours { if (cellColor == 0) { cellColor = 1; } else { cellColor = 0; } for (int j = 0; j < 8; j++) { if (j % 2 == cellColor) { WhiteCell = true; } else { WhiteCell = false; } // to generate board pieces BoardPiece Piece = null; //it will only generate pieces for black cells //for first 3 rows and last 3 rows and where cellcolour is black if ((i < 3 || i > 4) && WhiteCell == false) { //for first 3 rows of the board player1 pieces if (i < 3) { //get a colour from player1 to set piece colour for player1 pieceColor = game.Player1.Color; } else { pieceColor = game.Player2.Color; } } else { pieceColor = null; } if (string.IsNullOrEmpty(pieceColor) == false) { if (i < 3) { Piece = new BoardPiece(game.Player1);//create a player1 piece } else { Piece = new BoardPiece(game.Player2);// create a player2 piece } } else { Piece = null; } BoardCell Cell; if (WhiteCell)//if WhiteCell= false that means white board cells { Cell = new BoardCell(i, j, BoardCell.WHITE_CELL, Piece); } else { Cell = new BoardCell(i, j, BoardCell.BLACK_CELL, Piece); } drawBoardElements(Cell); //draw cell on the grid content[i, j] = Cell; if (pieceColor == game.Player1.Color) { game.Player1.ActivePieces.Push(Piece);//add to list of active pieces for player1 } else if (pieceColor == game.Player2.Color) { game.Player2.ActivePieces.Push(Piece);//add to list of active pieces for player2 } } } }