Example #1
0
        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();
        }
Example #2
0
        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;
                }
            }
        }
Example #3
0
        private void boardPanel_Paint(object sender, PaintEventArgs e)
        {
            PositionAndPixels.boardPanel_x = boardPanel.Width;
            PositionAndPixels.boardPanel_y = boardPanel.Height;
            PositionAndPixels.Update();

            g = e.Graphics;
            UpdateBoard();
        }
        public void DrawPossibleMovesInverse(Graphics g)
        {
            int square = PositionAndPixels.square;
            List <BoardPosition> listOfMoves = aPieceManipulator.GetListOfMoves();

            if (listOfMoves != null)
            {
                foreach (BoardPosition bp in listOfMoves)
                {
                    Point point = PositionAndPixels.BoardPositionToPixelsInverse(bp);
                    g.DrawRectangle(aPen, point.X, point.Y, square, square);
                }
            }
        }
Example #5
0
        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();
        }
Example #6
0
 private void DrawPieces(Graphics g)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (aBoard.GetBoard()[i, j].HasPiece())
             {
                 Point point = new Point();
                 if (aFirstPlayer.Equals(Piece.Color.BLACK))
                 {
                     point = PositionAndPixels.BoardPositionToPixels(new BoardPosition(i, j));
                 }
                 else
                 {
                     point = PositionAndPixels.BoardPositionToPixelsInverse(new BoardPosition(i, j));
                 }
                 aSquaresView[i, j].drawPiece(g, point);
             }
         }
     }
 }