Пример #1
0
        public Chess PlaceAChess(int x, int y, Chess.ChessType type)
        {
            Point nodeId = FindTheClosetNode(x, y);

            if (nodeId == NO_MATCH_NODE)
            {
                return(null);
            }

            if (chesses[nodeId.X, nodeId.Y] != null)
            {
                return(null);
            }
            Point formPos = ConvertToFormPos(nodeId);

            chesses[nodeId.X, nodeId.Y] = new Chess(formPos.X, formPos.Y, type);

            _lastPlaceNode = nodeId;

            return(chesses[nodeId.X, nodeId.Y]);
        }
Пример #2
0
        public bool CheckLineUp(Chess.ChessType type)
        {
            int centerX = _lastPlaceNode.X;
            int centerY = _lastPlaceNode.Y;

            int total = 1;
            int count = 1;

            // \
            while (count <= 5)
            {
                if (centerX - count < 0 || centerY - count < 0)
                {
                    break;
                }
                if (chesses[centerX - count, centerY - count] == null)
                {
                    break;
                }
                if (chesses[centerX - count, centerY - count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            count = -1;

            while (count >= -5)
            {
                if (centerX - count >= Board.NODE_COUNT || centerY - count >= Board.NODE_COUNT)
                {
                    break;
                }
                if (chesses[centerX - count, centerY - count] == null)
                {
                    break;
                }

                if (chesses[centerX - count, centerY - count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count--;
            }

            if (total >= 5)
            {
                return(true);
            }

            total = 1;
            count = 1;

            // /
            while (count <= 5)
            {
                if (centerX - count < 0 || centerY + count >= Board.NODE_COUNT)
                {
                    break;
                }
                if (chesses[centerX - count, centerY + count] == null)
                {
                    break;
                }

                if (chesses[centerX - count, centerY + count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            count = 1;

            while (count <= 5)
            {
                if (centerX + count >= Board.NODE_COUNT || centerY - count < 0)
                {
                    break;
                }
                if (chesses[centerX + count, centerY - count] == null)
                {
                    break;
                }

                if (chesses[centerX + count, centerY - count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            if (total >= 5)
            {
                return(true);
            }

            total = 1;
            count = 1;

            // |
            while (count <= 5)
            {
                if (centerY - count < 0)
                {
                    break;
                }
                if (chesses[centerX, centerY - count] == null)
                {
                    break;
                }

                if (chesses[centerX, centerY - count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            count = 1;

            while (count <= 5)
            {
                if (centerY + count >= Board.NODE_COUNT)
                {
                    break;
                }
                if (chesses[centerX, centerY + count] == null)
                {
                    break;
                }

                if (chesses[centerX, centerY + count].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            if (total >= 5)
            {
                return(true);
            }

            total = 1;
            count = 1;

            // -

            while (count <= 5)
            {
                if (centerX + count >= Board.NODE_COUNT)
                {
                    break;
                }
                if (chesses[centerX + count, centerY] == null)
                {
                    break;
                }

                if (chesses[centerX + count, centerY].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            count = 1;

            while (count <= 5)
            {
                if (centerX - count < 0)
                {
                    break;
                }
                if (chesses[centerX - count, centerY] == null)
                {
                    break;
                }

                if (chesses[centerX - count, centerY].GetChessType() != type)
                {
                    break;
                }

                total++;
                count++;
            }

            if (total >= 5)
            {
                return(true);
            }

            return(false);
        }