コード例 #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();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Piece.cs プロジェクト: Virkin/ChessEngine
        protected List <string> GetLineMove(int vertInc = 0, int horInc = 0)
        {
            List <int> IjCoord = board.CoordToIj(pos);

            List <string> lineMove = new List <string>();

            int i, j;

            for (int n = 1; n < board.GetBoardEdgeLen(); n++)
            {
                i = IjCoord[0] + n * vertInc;
                j = IjCoord[1] + n * horInc;

                if (board.InBoard(i, j))
                {
                    if (board.IsVoid(i, j))
                    {
                        lineMove.Add(board.IjToCoord(i, j));
                    }
                    else
                    {
                        if (board.IsKillable(board.IjToCoord(i, j), color))
                        {
                            lineMove.Add(board.IjToCoord(i, j));
                        }

                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            return(lineMove);
        }