Exemple #1
0
        public static bool sameDiagonal(int x1, int y1, int x2, int y2)
        {
            Point coeffCoords = Maths.getCoeffDiff(x1, y1, x2, y2);
            int   addCoeffX   = coeffCoords.X;
            int   addCoeffY   = coeffCoords.Y;

            int xData = x2;
            int yData = y2;

            for (int i = 0; i < Math.Abs(x1 - x2); i++)
            {
                xData += addCoeffX;
                yData += addCoeffY;

                if (xData == x1 && yData == y1)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        public static bool detectCanAtkForKing(Client isPlaying, int x, int y)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

            if (IndexClient == -1)
            {
                return(false);
            }

            bool playerTop = isPlaying.info_main.playerTop;

            for (int y1 = 0; y1 < ClientManager.ListClient[IndexClient].info_game.plateauCases.Length; y1++)
            {
                for (int x1 = 0; x1 < ClientManager.ListClient[IndexClient].info_game.plateauCases[y1].Length; x1++)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].pawnTop != playerTop &&
                        ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].pawnExist)
                    {
                        Point coeffCoords = Maths.getCoeffDiff(x1, y1, x, y);

                        int addCoeffX = coeffCoords.X;
                        int addCoeffY = coeffCoords.Y;

                        int xData = x1 + addCoeffX;
                        int yData = y1 + addCoeffY;

                        if (xData <= 9 && yData <= 9 &&
                            xData >= 0 && yData >= 0)
                        {
                            if (Distance.freeField(isPlaying, playerTop, xData, yData, x, y, false) == 2)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #3
0
        public static bool detectCanAtk(Client isPlaying, int x, int y)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

            if (IndexClient == -1)
            {
                return(false);
            }

            bool playerTop = isPlaying.info_main.playerTop;

            for (int y1 = 0; y1 < ClientManager.ListClient[IndexClient].info_game.plateauCases.Length; y1++)
            {
                for (int x1 = 0; x1 < ClientManager.ListClient[IndexClient].info_game.plateauCases[y1].Length; x1++)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].pawnTop != playerTop &&
                        ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].pawnExist)
                    {
                        int distance = Distance.getDistance(y, x, y1, x1);
                        if (distance == 1)
                        {
                            Point coeffCoords = Maths.getCoeffDiff(x1, y1, x, y);
                            int   countDiffY  = coeffCoords.Y * 2;
                            int   countDiffX  = coeffCoords.X * 2;

                            if ((x + countDiffX) <= 9 && (y + countDiffY) <= 9 &&
                                (x + countDiffX) >= 0 && (y + countDiffY) >= 0)
                            {
                                if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y + countDiffY][x + countDiffX].pawnExist)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #4
0
        /*
         * 0 = Pas le droit d'avancer
         * 1 = Champ libre
         * 2 = Pion adverse présente & possibilité de l'attaquer
         */
        public static int freeField(Client isPlaying, bool playerTop, int x1, int y1, int x2, int y2, bool attacking = true)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

            if (IndexClient == -1)
            {
                return(0);
            }

            Point coeffCoords = Maths.getCoeffDiff(x1, y1, x2, y2);
            int   addCoeffX   = coeffCoords.X;
            int   addCoeffY   = coeffCoords.Y;

            for (int i = 1; i < Math.Abs(x1 - x2); i++)
            {
                int xA = x2 + (i * addCoeffX);
                int yA = y2 + (i * addCoeffY);

                if (xA >= 0 && xA <= 9 &&
                    yA >= 0 && yA <= 9)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[yA][xA].pawnExist)
                    {
                        if (ClientManager.ListClient[IndexClient].info_game.plateauCases[yA][xA].pawnTop == playerTop)
                        {
                            return(0);
                        }
                        else
                        {
                            int xData = xA + addCoeffX;
                            int yData = yA + addCoeffY;

                            for (int e = 1; e < Math.Abs(xA - x1) + 1; e++)
                            {
                                xData = xA + (addCoeffX * e);
                                yData = yA + (addCoeffY * e);

                                /*Console.WriteLine("xData = " + xData + " | yData = " + yData);
                                 * Console.WriteLine("addCoeffX = " + addCoeffX + " | addCoeffY = " + addCoeffY);
                                 * Console.WriteLine("Abs(x1 - x1) + 1 = " + (Math.Abs(xA - x1) + 1));
                                 * Console.WriteLine("e = " + e);*/
                                if (xData >= 0 && xData <= 9 && yData >= 0 && yData <= 9)
                                {
                                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[yData][xData].pawnExist)
                                    {
                                        return(0);
                                    }
                                    if (xData == x1 && yData == y1)
                                    {
                                        if (attacking)
                                        {
                                            xPawn = xA;
                                            yPawn = yA;
                                        }
                                        return(2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(1);
        }