public void movePiece(Point p) { BoardPosition bp = PositionAndPixels.PixelsToBoardPosition(p); if ((bp.X >= 0) & (bp.X < 8) & (bp.Y >= 0) & (bp.Y < 8)) { if (chessGame.GetChessBoard().GetHasPiece()[bp.X, bp.Y] && !isSelecting) { selectedPosition = new BoardPosition(bp.X, bp.Y); isSelecting = true; } else if (isSelecting && (bp.X == selectedPosition.X) && (bp.Y == selectedPosition.Y)) { selectedPosition = new BoardPosition(-2, -1); isSelecting = false; } else if (isSelecting && chessGame.GetChessBoard().GetHasPiece()[bp.X, bp.Y] && chessGame.GetChessBoard().GetBoard()[bp.X, bp.Y].getColor().Equals(ChessBoard.OtherColor(chessGame.GetChessBoard().GetBoard()[selectedPosition.X, selectedPosition.Y].getColor()))) { chessGame.movePiece(selectedPosition, bp); selectedPosition = new BoardPosition(-2, -1); isSelecting = false; } else if (isSelecting && !chessGame.GetChessBoard().GetHasPiece()[bp.X, bp.Y]) { chessGame.movePiece(selectedPosition, bp); selectedPosition = new BoardPosition(-2, -1); isSelecting = false; } } }
private void boardPanel_MouseClick(object sender, MouseEventArgs e) { mouse_x = e.X; mouse_y = e.Y; Point mousePoint = new Point(mouse_x, mouse_y); BoardPosition bp = new BoardPosition(); if (aChessGame.GetFirstPlayerColor().Equals(Piece.Color.BLACK)) { bp = PositionAndPixels.PixelsToBoardPosition(mousePoint); } else { bp = PositionAndPixels.PixelsToBoardPositionInverse(mousePoint); } if (e.Button == MouseButtons.Right) { aChessGame.DiscardPiece(); } else { aChessGame.ManipulatePiece(bp); } Refresh(); CheckGameStatus(); }
private void boardPanel_MouseClick(object sender, MouseEventArgs e) { mouse_x = e.X; mouse_y = e.Y; Point mousePoint = new Point(mouse_x, mouse_y); BoardPosition bp = PositionAndPixels.PixelsToBoardPosition(mousePoint); if (e.Button == MouseButtons.Right) { chessGameView.GetChessGame().DiscardPiece(); } else { chessGameView.GetChessGame().MovePiece(bp); } selectedPieceTextBox.Text = chessGameView.GetChessGame().PrintPiece(); HasKings(); Refresh(); }