private void Click_Board(object s, EventArgs e) { DrawPieces(chessBoard); if (!(s is Button)) { return; } Button button = (Button)s; button.FlatStyle = FlatStyle.Standard; TableLayoutPanelCellPosition a = boardLayoutPanel.GetPositionFromControl((Control)s); if (!(button.Tag is ChessPiece)) { if (selectedPlayer > -1) { chessBoard.ActionPiece(selectedPiece.x, selectedPiece.y, a.Column - 1, a.Row - 1); selectedPlayer = -1; DrawPieces(chessBoard); } return; } ChessPiece chessPiece = (ChessPiece)button.Tag; Console.WriteLine("({2}, {3}) - {0} from team {1}", chessPiece.GetType(), chessPiece.Player, a.Column - 1, a.Row - 1); if (selectedPlayer > -1 && selectedPlayer != chessPiece.Player) { chessBoard.ActionPiece(selectedPiece.x, selectedPiece.y, a.Column - 1, a.Row - 1); selectedPlayer = -1; DrawPieces(chessBoard); } else { selectedPlayer = chessPiece.Player; selectedPiece.x = a.Column - 1; selectedPiece.y = a.Row - 1; foreach (Chess.Point point in chessBoard.PieceActions(a.Column - 1, a.Row - 1)) { Button actionButton = (Button)boardLayoutPanel.GetControlFromPosition(point.x + 1, point.y + 1); actionButton.FlatStyle = FlatStyle.Standard; Console.WriteLine("~({0}, {1})", point.x, point.y); } Console.WriteLine(); } }