private void MovePiece(GamePiece movingPiece, BoardLocation EndLoc, GameState gameState) { _GameTurn.GameState = GameState.INMOVE; AdjustBoard(movingPiece.BoardLocation, GridEntry.EMPTY); Controls.Remove(movingPiece as Control); movingPiece.BoardLocation = EndLoc; if (movingPiece.IsPromoted == false && (EndLoc.Row == 0 || EndLoc.Row == 7)) { if (movingPiece.PieceState == GridEntry.WHITEPAWN && EndLoc.Row == 7) { KingPiece(movingPiece, GetImage("Checkers.Assets.WhiteKing.png"), GridEntry.WHITEKING); } if (movingPiece.PieceState == GridEntry.BLACKPAWN && EndLoc.Row == 0) { KingPiece(movingPiece, GetImage("Checkers.Assets.BlackKing.png"), GridEntry.BLACKKING); } } movingPiece.Location = new Point((LEFTMARGIN + TILESIZE * EndLoc.Column) + 10, (TOPMARGIN + TILESIZE * EndLoc.Row) + 10); this.Controls.Add(movingPiece); this.Controls.SetChildIndex(movingPiece, 1000); movingPiece.BringToFront(); _GameTurn.GameState = gameState; AdjustBoard(movingPiece.BoardLocation, movingPiece.PieceState); TurnChange(); }
private void KingPiece(GamePiece movingPiece, Image KingImage, GridEntry PromotionState) { Controls.Remove(movingPiece as Control); movingPiece.Image = KingImage; movingPiece.PieceState = PromotionState; movingPiece.IsPromoted = true; Controls.Add(movingPiece); Controls.SetChildIndex(movingPiece, 1001); movingPiece.BringToFront(); AdjustBoard(movingPiece.BoardLocation, movingPiece.PieceState); }
//Methods private void InitBoard() { int iInd = 0; int iIndex = 64; int iWhite = 1; int iBlack = 1; for (int row = 0; row < BOARDSIZE; row++) { for (int col = 0; col < BOARDSIZE; col++) { TilePiece gridCell = new TilePiece(TILESIZE); gridCell.MouseDown += gameCell_MouseDown; gridCell.BoardLocation = new BoardLocation { Row = row, Column = col }; gridCell.Location = new Point(LEFTMARGIN + TILESIZE * col, TOPMARGIN + TILESIZE * row); //mBox.Text += (TOPMARGIN + TILESIZE * row).ToString() + ", " + (5 + TILESIZE * col) + Environment.NewLine; gridCell.BackColor = (row % 2 == 0 && col % 2 == 0) || (row % 2 == 1 && col % 2 == 1) ? Color.White : Color.Black; gridCell.DragDrop += gridCell_DragDrop; gridCell.DragEnter += gridCell_DragEnter; this.Controls.Add(gridCell); this.Controls.SetChildIndex(gridCell, ++iInd); if (row > 4 && gridCell.BackColor == Color.Black) { _GameTurn.BOARDARRAY[row, col] = (int)GridEntry.BLACKPAWN; GamePiece piece = new GamePiece() { BoardLocation = new BoardLocation { Row = row, Column = col } }; piece.MouseDown += piece_MouseDown; piece.DragEnter += piece_DragEnter; piece.DragDrop += piece_DragDrop; piece.PieceState = GridEntry.BLACKPAWN; piece.Name = "BLACKPIECE_" + iWhite++; piece.Image = GetImage("Checkers.Assets.BlackPiece.png"); piece.Location = new Point((LEFTMARGIN + TILESIZE * col) + 10, (TOPMARGIN + TILESIZE * row) + 10); this.Controls.Add(piece); this.Controls.SetChildIndex(piece, ++iIndex); piece.BringToFront(); } else if (row < 3 && gridCell.BackColor == Color.Black) { _GameTurn.BOARDARRAY[row, col] = (int)GridEntry.WHITEPAWN; GamePiece piece = new GamePiece() { BoardLocation = new BoardLocation { Row = row, Column = col } }; piece.MouseDown += piece_MouseDown; piece.DragEnter += piece_DragEnter; piece.DragDrop += piece_DragDrop; piece.PieceState = GridEntry.WHITEPAWN; piece.Name = "WHITEPIECE_" + iBlack++; piece.Image = GetImage("Checkers.Assets.WhitePiece.png"); piece.Location = new Point((LEFTMARGIN + TILESIZE * col) + 10, (TOPMARGIN + TILESIZE * row) + 10); this.Controls.Add(piece); this.Controls.SetChildIndex(piece, ++iIndex); piece.BringToFront(); } else { if (gridCell.BackColor == Color.Black) { _GameTurn.BOARDARRAY[row, col] = (int)GridEntry.EMPTY; } else { _GameTurn.BOARDARRAY[row, col] = (int)GridEntry.NULL; } } } } }