Example #1
0
        private void BoardClick(object sender, EventArgs e)
        {
            MouseEventArgs mouseEvent = (MouseEventArgs)e;

            char[,] boardTab = board.GetBoardTab();

            int posi = (int)Math.Floor((double)mouseEvent.Y / boxSize);
            int posj = (int)Math.Floor((double)mouseEvent.X / boxSize);

            bool currentColor = board.GetColorTurn();

            foreach (Human human in player)
            {
                if (human.GetColor() == currentColor)
                {
                    if (movesToDisp.Count == 0)
                    {
                        if ((Char.IsLower(boardTab[posi, posj]) && currentColor == false) || (Char.IsUpper(boardTab[posi, posj]) && currentColor == true))
                        {
                            pieceCoord = board.IjToCoord(posi, posj);

                            movesToDisp = board.GetMove(pieceCoord);

                            Refresh();
                        }
                    }
                    else
                    {
                        moveCoord = board.IjToCoord(posi, posj);

                        if (movesToDisp.FindIndex(board.IjToCoord(posi, posj).Contains) >= 0)
                        {
                            board.SetPieceCoord(pieceCoord, moveCoord);
                            lastBoardArr = (char[, ])board.GetBoardTab().Clone();
                            human.IncrementMove();
                            movesToDisp.Clear();
                        }
                        else
                        {
                            movesToDisp.Clear();
                        }

                        Refresh();
                    }
                }
            }
        }