Exemplo n.º 1
0
        public static Point GetCoordsAttakedOpponent(Client isPlaying, int y1, int x1, int y2, int x2, bool playerTop)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

            if (IndexClient == -1)
            {
                return(new Point(-1, -1));
            }

            for (int y = 0; y < ClientManager.ListClient[IndexClient].info_game.plateauCases.Length; y++)
            {
                for (int x = 0; x < ClientManager.ListClient[IndexClient].info_game.plateauCases[y].Length; x++)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist)
                    {
                        int distance1 = Distance.getDistance(y, x, y1, x1);
                        int distance2 = Distance.getDistance(y, x, y2, x2);

                        if (distance1 == 1 && distance2 == 1)
                        {
                            if (playerTop != ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnTop)
                            {
                                return(new Point(x, y));
                            }
                        }
                    }
                }
            }
            return(new Point(-1, -1));
        }
Exemplo n.º 2
0
        public static void setCase(Client isPlaying, int x, int y, string imgPawn = "-1", bool isExist = false, bool isTop = false)
        {
            int IndexClient   = ClientManager.byPseudo(isPlaying.info_main.pseudo);
            int IndexOpponent = ClientManager.byPseudo(isPlaying.info_game.opponent);

            if (IndexClient == -1 || IndexOpponent == -1)
            {
                return;
            }

            try
            {
                string pathImg = imgPawn.ToString();

                ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist = isExist;

                ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnTop = isTop;

                Match.SynchroWithOpponents(isPlaying);

                string packet = "set " + x + " " + y + " " + Convert.ToInt32(isExist) + " " + Convert.ToInt32(isTop) + " " + imgPawn;
                ClientManager.ListClient[IndexClient].Send(packet);
                ClientManager.ListClient[IndexOpponent].Send(packet);
            }
            catch (Exception ex)
            { Console.WriteLine(ex.ToString()); }
        }
Exemplo n.º 3
0
        public static void Timer(int IndexClient)
        {
            if (ClientManager.ListClient[IndexClient].info_game.isplaying)
            {
                if (ClientManager.ListClient[IndexClient].info_game.tour)
                {
                    int TimeCount = (Environment.TickCount / 1000) - (ClientManager.ListClient[IndexClient].info_game.timeCount / 1000);

                    if (TimeCount >= 30)
                    {
                        int IndexOpponent = ClientManager.byPseudo(ClientManager.ListClient[IndexClient].info_game.opponent);

                        if (IndexOpponent == -1)
                        {
                            return;
                        }

                        ClientManager.ListClient[IndexClient].info_game.asked   = false;
                        ClientManager.ListClient[IndexOpponent].info_game.asked = false;

                        playerManager.ChangeGameTurn(ClientManager.ListClient[IndexClient]);

                        ClientManager.ListClient[IndexClient].SendMsg("Temps écoulé ! Changement de tour !");
                        ClientManager.ListClient[IndexOpponent].SendMsg("Temps écoulé ! Changement de tour !");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void InscriptionMatch(Client MonClient)
        {
            Console.WriteLine("Inscription de " + MonClient.info_main.pseudo);
            if (MonClient.info_game.isplaying || DejaInscrit(MonClient))
            {
                return;
            }

            Attente.Add(MonClient);

            if (Attente.Count % 2 == 0 && Attente.Count != 0)
            {
                Console.WriteLine("2 joueurs vont êtes mis en relation ...");
                int IndexJoueur1 = ClientManager.byPseudo(Attente[0].info_main.pseudo);
                int IndexJoueur2 = ClientManager.byPseudo(Attente[1].info_main.pseudo);
                if (IndexJoueur1 == -1 || IndexJoueur2 == -1)
                {
                    return;
                }

                MatchTrouver(IndexJoueur1, IndexJoueur2);
                Attente.RemoveAt(0);
                Attente.RemoveAt(0);
            }
        }
Exemplo n.º 5
0
        public static void ChangeGameTurn(Client IsPlaying)
        {
            int IndexOpponent = ClientManager.byPseudo(IsPlaying.info_game.opponent);
            int IndexClient   = ClientManager.byPseudo(IsPlaying.info_main.pseudo);

            if (IndexClient == -1 || IndexOpponent == -1)
            {
                return;
            }

            ClientManager.ListClient[IndexClient].info_game.timeTourCount   = Environment.TickCount;
            ClientManager.ListClient[IndexOpponent].info_game.timeTourCount = Environment.TickCount;

            ClientManager.ListClient[IndexClient].info_game.timeExist   = 0;
            ClientManager.ListClient[IndexOpponent].info_game.timeExist = 0;

            if (IsPlaying.info_game.tour)
            {
                ClientManager.ListClient[IndexClient].info_game.tour   = !ClientManager.ListClient[IndexClient].info_game.tour;
                ClientManager.ListClient[IndexOpponent].info_game.tour = !ClientManager.ListClient[IndexOpponent].info_game.tour;
            }

            if (!EndGame.canMakeAnAction(WhosNext(IsPlaying)))
            {
                ClientManager.ListClient[IndexClient].SendMsg("Partie terminée");
                ClientManager.ListClient[IndexOpponent].SendMsg("Partie terminée");
                ClientManager.RedirectEnding(WhosNext(IsPlaying), false);
            }
        }
Exemplo n.º 6
0
        public static void initializePawn(Client isPlaying)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].isBlack)
                    {
                        PictureBox pb = new PictureBox();
                        ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].Rec.X = x;
                        ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].Rec.Y = y;

                        if (y < 3) // Pion du haut
                        {
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist = true;
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnTop   = true;
                        }
                        if (y > 6) // Pion du bas
                        {
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist = true;
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnTop   = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /*
         * 0 = Distance insuffisante
         * 1 = Déplacement d'une case
         * 2 = Mange un pion
         */

        public static int distanceStatus(Client isPlaying, int y1, int x1, int y2, int x2, bool playerTop)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            bool isKing   = ClientManager.ListClient[IndexClient].info_game.plateauCases[y2][x2].king;
            int  distance = getDistance(y1, x1, y2, x2);

            if (distance == 3) // Position d'attaque
            {
                Point OpponentCoords = Attack.GetCoordsAttakedOpponent(isPlaying, y1, x1, y2, x2, playerTop);

                if (OpponentCoords.X == -1)
                {
                    if (!isKing)
                    {
                        return(0);
                    }
                }
                else
                {
                    yPawn = OpponentCoords.Y;
                    xPawn = OpponentCoords.X;
                    return(2);
                }
            }
            else if (distance == 1) // Position de déplacement
            {
                if (!isKing)
                {
                    if (playerTop)
                    {
                        if (y1 - y2 != 1)
                        {
                            return(0);
                        }
                    }
                    else
                    if (y2 - y1 != 1)
                    {
                        return(0);
                    }
                }

                return(1);
            }

            if (distance >= 3 && isKing) // Déplacement pour les pions ' king '
            {
                int fre = freeField(isPlaying, playerTop, x1, y1, x2, y2);
                return(fre);
            }

            return(0);
        }
Exemplo n.º 8
0
        public static Client GetOpponent(Client Player)
        {
            int IndexOpponent = ClientManager.byPseudo(Player.info_game.opponent);

            if (IndexOpponent == -1)
            {
                return(null);
            }

            return(ClientManager.ListClient[IndexOpponent]);
        }
Exemplo n.º 9
0
        public static void SynchroWithOpponents(Client isPlaying)
        {
            int IndexOpponent = ClientManager.byPseudo(isPlaying.info_game.opponent);

            if (IndexOpponent == -1)
            {
                return;
            }

            ClientManager.ListClient[IndexOpponent].info_game.plateauCases = isPlaying.info_game.plateauCases;
        }
Exemplo n.º 10
0
        // Rempli la variable .plateau du client Player
        public static void remplirPlateau(Client Player)
        {
            int IndexClient = ClientManager.byPseudo(Player.info_main.pseudo);

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

            bool value         = false;
            int  index         = 0;
            int  index_plateau = 0;

            int[] ligne = new int[10];

            for (int i = 0; i < 100; i++)
            {
                int loca = i + 1;

                if (loca % 10 == 0 && i != 0)
                {
                    ligne[index] = Convert.ToInt32(value);
                    cases[] nouvelleCases = new cases[10];

                    for (int e = 0; e < 10; e++)
                    {
                        nouvelleCases[e].isBlack = Convert.ToBoolean(ligne[e]);
                    }

                    ClientManager.ListClient[IndexClient].info_game.plateauCases[index_plateau] = nouvelleCases;
                    ligne = new int[10];

                    index = 0;
                    index_plateau++;
                }
                else if (i % 2 == 0)
                {
                    ligne[index] = Convert.ToInt32(value);
                    index++;
                    value = !value;
                }
                else
                {
                    ligne[index] = Convert.ToInt32(value);
                    index++;
                    value = !value;
                }
            }
        }
Exemplo n.º 11
0
        public static void sendAnimation(Client isPlaying, int type, int x, int y)
        {
            int IndexClient   = ClientManager.byPseudo(isPlaying.info_main.pseudo);
            int IndexOpponent = ClientManager.byPseudo(isPlaying.info_game.opponent);

            if (IndexClient == -1 || IndexOpponent == -1)
            {
                return;
            }

            string packet = "anim " + type + " " + x + " " + y;

            ClientManager.ListClient[IndexClient].Send(packet);
            ClientManager.ListClient[IndexOpponent].Send(packet);
        }
Exemplo n.º 12
0
        public static Client WhosNext(Client IsPlaying)
        {
            int IndexOpponent = ClientManager.byPseudo(IsPlaying.info_game.opponent);
            int IndexClient   = ClientManager.byPseudo(IsPlaying.info_main.pseudo);

            if (IndexClient == -1 || IndexOpponent == -1)
            {
                return(null);
            }

            if (ClientManager.ListClient[IndexClient].info_game.tour)
            {
                return(ClientManager.ListClient[IndexClient]);
            }
            return(ClientManager.ListClient[IndexOpponent]);
        }
Exemplo n.º 13
0
        public static void checkJumpingNotPlayed(Client isPlaying, int myX, int myY, bool noPawn = false)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            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 && (ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].Rec != ClientManager.ListClient[IndexClient].info_game.plateauCases[myY][myX].Rec) || noPawn)
                    {
                        for (int y2 = 0; y2 < ClientManager.ListClient[IndexClient].info_game.plateauCases.Length; y2++)
                        {
                            for (int x2 = 0; x2 < ClientManager.ListClient[IndexClient].info_game.plateauCases[y2].Length; x2++)
                            {
                                if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y2][x2].pawnTop != playerTop &&
                                    ClientManager.ListClient[IndexClient].info_game.plateauCases[y2][x2].pawnExist)
                                {
                                    if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].king) // Pion normal
                                    {
                                        if (Attack.detectCanAtk(isPlaying, x1, y1))
                                        {
                                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].isnotcareful = true;
                                        }
                                    }
                                    else // Reine
                                    {
                                        if (Attack.detectCanAtkForKing(isPlaying, x1, y1))
                                        {
                                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y1][x1].isnotcareful = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Match.SynchroWithOpponents(isPlaying);
        }
Exemplo n.º 14
0
        public static void TimerTour(int IndexClient)
        {
            if (ClientManager.ListClient[IndexClient].info_game.isplaying)
            {
                if (ClientManager.ListClient[IndexClient].info_game.tour)
                {
                    int TimeCount = (Environment.TickCount / 1000) - (ClientManager.ListClient[IndexClient].info_game.timeTourCount / 1000);
                    int TimeExist = ClientManager.ListClient[IndexClient].info_game.timeExist;

                    if (TimeCount >= 30)
                    {
                        int IndexOpponent = ClientManager.byPseudo(ClientManager.ListClient[IndexClient].info_game.opponent);

                        if (IndexOpponent == -1)
                        {
                            return;
                        }

                        ClientManager.ListClient[IndexClient].info_game.asked   = false;
                        ClientManager.ListClient[IndexOpponent].info_game.asked = false;

                        Careful.checkJumpingNotPlayed(ClientManager.ListClient[IndexClient], 0, 0, true);

                        playerManager.ChangeGameTurn(ClientManager.ListClient[IndexClient]);

                        ClientManager.ListClient[IndexClient].SendMsg("Temps écoulé ! Changement de tour !");
                        ClientManager.ListClient[IndexOpponent].SendMsg("Temps écoulé ! Changement de tour !");
                    }
                    else if (TimeCount % 10 == 0 && TimeCount != 0 && TimeExist != (30 - TimeCount))
                    {
                        int IndexOpponent = ClientManager.byPseudo(ClientManager.ListClient[IndexClient].info_game.opponent);

                        if (IndexOpponent == -1)
                        {
                            return;
                        }

                        ClientManager.ListClient[IndexClient].info_game.timeExist   = 30 - TimeCount;
                        ClientManager.ListClient[IndexOpponent].info_game.timeExist = 30 - TimeCount;

                        ClientManager.ListClient[IndexClient].SendMsg("Il ne vous reste plus que " + (30 - TimeCount) + " secondes !");
                        ClientManager.ListClient[IndexOpponent].SendMsg("Il ne lui reste plus que " + (30 - TimeCount) + " secondes !");
                    }
                }
            }
        }
Exemplo n.º 15
0
        public static bool OpponentIsDead(Client isPlaying)
        {
            int IndexClient   = ClientManager.byPseudo(isPlaying.info_main.pseudo);
            int IndexOpponent = ClientManager.byPseudo(isPlaying.info_game.opponent);

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

            if (isPlaying.info_game.pawnAlive <= 0)
            {
                ClientManager.RedirectEnding(isPlaying, false);
                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        public static void pawnToKing(Client isPlaying, bool playerTop, int x, int y)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            if (Distance.isLastLine(playerTop, y))
            {
                if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king)
                {
                    Action.setCase(isPlaying, x, y, getPawnImgByPlayer(playerTop, true), true, playerTop);
                    ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king = true;
                }
            }
            Match.SynchroWithOpponents(isPlaying);
        }
Exemplo n.º 17
0
        public static void resetNotCarefulOpponent(Client Opponent)
        {
            int IndexOpponent = ClientManager.byPseudo(Opponent.info_main.pseudo);

            if (IndexOpponent == -1)
            {
                return;
            }

            for (int y = 0; y < ClientManager.ListClient[IndexOpponent].info_game.plateauCases.Length; y++)
            {
                for (int x = 0; x < ClientManager.ListClient[IndexOpponent].info_game.plateauCases[y].Length; x++)
                {
                    if (Opponent.info_main.playerTop == ClientManager.ListClient[IndexOpponent].info_game.plateauCases[y][x].pawnTop)
                    {
                        ClientManager.ListClient[IndexOpponent].info_game.plateauCases[y][x].isnotcareful = false;
                    }
                }
            }
            Match.SynchroWithOpponents(Opponent);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        public static void isNotCareful(Client isPlaying, int y, int x)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].isnotcareful && ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist)
            {
                /*DialogResult request = MessageBox.Show("Souhaitez-vous détruire ce pion ?", "Sauté n'est pas joué", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                 * if (request == DialogResult.Yes)
                 * {
                 *  //Animation.makeTransition((int)BunifuAnimatorNS.AnimationType.Particles, x, y);
                 *  Action.setCase(isPlaying, x, y);
                 * }*/
                isPlaying.SendRequest("Souhaitez-vous détruire ce pion ?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, x, y);
                isPlaying.info_game.asked = true;
                return;
            }
            isPlaying.SendMsg("Ce n'est pas vos pions");
        }
Exemplo n.º 21
0
        public static bool canMakeAnAction(Client isPlaying)
        {
            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

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

            bool playerTop = isPlaying.info_main.playerTop;

            for (int y = 0; y < ClientManager.ListClient[IndexClient].info_game.plateauCases.Length; y++)
            {
                for (int x = 0; x < ClientManager.ListClient[IndexClient].info_game.plateauCases[y].Length; x++)
                {
                    if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnTop == playerTop &&
                        ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist)
                    {
                        bool isKing = ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king;

                        if (!isKing)
                        {
                            if (Attack.detectCanAtk(isPlaying, x, y))
                            {
                                return(true);
                            }
                        }
                        if (isKing)
                        {
                            if (Attack.detectCanAtkForKing(isPlaying, x, y))
                            {
                                return(true);
                            }
                        }

                        if (!isKing)
                        {
                            int addX = 1;
                            int addY = 1;
                            if (playerTop)
                            {
                                if (y + addY <= 9 && x + addX <= 9)
                                {
                                    if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y + addY][x + addX].pawnExist)
                                    {
                                        return(true);
                                    }
                                }
                                if (y + addY <= 9 && x + (addX * -1) >= 0)
                                {
                                    if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y + addY][x + addX * -1].pawnExist)
                                    {
                                        return(true);
                                    }
                                }
                            }
                            else
                            {
                                addX = -1;
                                addY = -1;

                                if (y + addY >= 0 && x + addX >= 0)
                                {
                                    if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y + addY][x + addX].pawnExist)
                                    {
                                        return(true);
                                    }
                                }
                                if (y + addY >= 0 && x + (addX * -1) <= 9)
                                {
                                    if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y + addY][x + addX * -1].pawnExist)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 22
0
        public static bool Handler(Client isPlaying, string packet, bool firstRcv = false, Socket ClientSocket = null)
        {
            string[] packetSpace = packet.Split(' ');

            if (packetSpace.Length < 1)
            {
                return(false);
            }

            if (firstRcv)
            {
                if (packetSpace[0] == "addClient" && packetSpace.Length == 3)
                {
                    string pseudoByPacket = packetSpace[1];
                    string passeByPacket  = packetSpace[2];
                    if (ClientManager.byPseudo(pseudoByPacket) == -1) // Si le pseudo n'existe pas
                    {
                        Client newClient = new Client(pseudoByPacket, passeByPacket);

                        newClient.MySocket = ClientSocket;

                        Thread newThread = new Thread(newClient.Handler);
                        newClient.MyThread = newThread;

                        newClient.info_game.isplaying = false;

                        ClientManager.ListClient.Add(newClient);

                        RequeteSQL.SetOnline(newClient, true);

                        /* Thread */
                        newClient.MySendThread = new Thread(newClient.ThreadSendVoid);

                        newClient.MySendThread.Start();
                        newThread.Start();

                        return(true);
                    }
                }
                return(false);
            }
            Console.WriteLine("Packet recu par " + isPlaying.info_main.pseudo + " = " + packet);

            bool playing = isPlaying.info_game.isplaying;

            if (packetSpace[0] == "ok" && packetSpace.Length == 1)
            {
                isPlaying.info_main.received = true;
                return(true);
            }

            if (packetSpace[0] == "inscription" && packetSpace.Length == 1 && !playing)
            {
                MatchMaking.InscriptionMatch(isPlaying);
            }

            if (packetSpace[0] == "select" && packetSpace.Length == 5 && playing)
            {
                if (More.isDec(packetSpace[1]) && More.isDec(packetSpace[2]) &&
                    More.isDec(packetSpace[3]) && More.isDec(packetSpace[4]))
                {
                    int x         = More.s_int(packetSpace[1]);
                    int y         = More.s_int(packetSpace[2]);
                    int xSelected = More.s_int(packetSpace[3]);
                    int ySelected = More.s_int(packetSpace[4]);

                    if (x >= 0 && x <= 9 && y >= 0 && y <= 9 &&
                        xSelected >= 0 && xSelected <= 9 && ySelected >= 0 && ySelected <= 9)
                    {
                        Action.pawnMoving(isPlaying, x, y, xSelected, ySelected);
                    }
                    return(true);
                }
            }

            if (packetSpace[0] == "req_result" && packetSpace.Length == 4 && playing)
            {
                if (More.isDec(packetSpace[1]) && More.isDec(packetSpace[2]) &&
                    More.isDec(packetSpace[3]))
                {
                    if (isPlaying.info_game.asked)
                    {
                        int result = More.s_int(packetSpace[1]);
                        int x      = More.s_int(packetSpace[2]);
                        int y      = More.s_int(packetSpace[3]);

                        if (result == 1)
                        {
                            Action.setCase(isPlaying, x, y);
                        }
                        isPlaying.info_game.asked = false;
                    }
                    else
                    {
                        isPlaying.Send("msg Vous avez pris trop de temps à répondre");
                    }
                    return(true);
                }
            }

            if (packetSpace[0] == "chat" && packetSpace.Length >= 2 && playing)
            {
                /* Fonction - Chat à déplacer */
                if (isPlaying.info_game.chatOn)
                {
                    int IndexOpponent = ClientManager.byPseudo(isPlaying.info_game.opponent);
                    if (IndexOpponent == -1)
                    {
                        return(false);
                    }
                    isPlaying.info_game.timeChatCount = Environment.TickCount;

                    isPlaying.info_game.chatOn = false;

                    string messageChat = "[" + isPlaying.info_main.pseudo + "]: ";
                    for (int i = 1; i < packetSpace.Length; i++)
                    {
                        messageChat += packetSpace[i];
                        messageChat += " ";
                    }
                    isPlaying.SendMsg(messageChat);
                    ClientManager.ListClient[IndexOpponent].SendMsg(messageChat);
                }
                else
                {
                    isPlaying.SendMsg("Vous pouvez pas envoyer de message pour l'instant");
                }
            }

            /* if (packetSpace[0] == "newMatch" && packetSpace.Length == 4 && !playing)
             * {
             *       if (More.s_int(packetSpace[2]) == 0 || More.s_int(packetSpace[2]) == 1)
             *       {
             *               if (!isPlaying.info_main.iswait)
             *              {
             *                 string pseudoByPacket = packetSpace[1];
             *                      int playerTopByPacket = More.s_int(packetSpace[2]);
             *                      string opponentByPacket = packetSpace[3];
             *
             *                      // Traitement du match
             *                      int IndexClient = ClientManager.byPseudo(pseudoByPacket);
             *
             *                      if (IndexClient == -1)
             *                      {
             *                              return false;
             *                      }
             *
             *                      isPlaying.info_main.iswait = true;
             *
             *                      isPlaying.info_game.opponent = opponentByPacket;
             *                      isPlaying.info_main.playerTop = Convert.ToBoolean(playerTopByPacket);
             *                      isPlaying.info_game.tour = Convert.ToBoolean(playerTopByPacket);
             *
             *                      string PseudoClient = ClientManager.ListClient[IndexClient].info_main.pseudo;
             *                      string PseudoOpponent = ClientManager.ListClient[IndexClient].info_game.opponent;
             *
             *                      Console.WriteLine("Nouveau match : " + PseudoClient + " Vs : " + PseudoOpponent);
             *
             *                      int IndexOpponent = ClientManager.byPseudo(PseudoOpponent);
             *
             *                      if (IndexOpponent != -1)
             *                      {
             *                              if (Match.startGame(IndexClient, IndexOpponent))
             *                              {
             *                                      Console.WriteLine("Les deux joueurs sont prets ...");
             *                                      return true;
             *                              }
             *                      }
             *
             *               Console.WriteLine("L'autre joueur n'est pas encore pret ...");
             *                       return true;
             *               }
             *      }
             * }*/
            return(false);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public static bool pawnMoving(Client isPlaying, int x, int y, int xSelected, int ySelected)
        {
            if (isPlaying.info_game.asked)
            {
                isPlaying.SendMsg("En attente de la réponse ...");
                return(false);
            }

            if (isPlaying.info_main.playerTop != isPlaying.info_game.plateauCases[ySelected][xSelected].pawnTop)
            {
                Careful.isNotCareful(isPlaying, ySelected, xSelected);
                return(false);
            }

            if (!isPlaying.info_game.tour)
            {
                isPlaying.SendMsg("Ce n'est pas votre tour !");
                return(false);
            }

            if (isPlaying.info_game.iscombo)
            {
                if (!isPlaying.info_game.plateauCases[ySelected][xSelected].mainCombo)
                {
                    isPlaying.SendMsg("Vous ne pouvez jouer que le pion 'combo'");
                    return(false);
                }
            }

            int IndexClient = ClientManager.byPseudo(isPlaying.info_main.pseudo);

            Client Player   = playerManager.WhosNext(isPlaying);
            Client Opponent = playerManager.GetOpponent(Player);

            bool playerTop = Player.info_main.playerTop;

            if (ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist)
            {
                return(false);
            }

            if (x == xSelected && y == ySelected)
            {
                isPlaying.SendMsg("Choix annulé");
                return(false);
            }
            else if (!ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].pawnExist)
            {
                int ruleDistance = Distance.distanceStatus(isPlaying, y, x, ySelected, xSelected, playerTop);

                if (ruleDistance == 0 || (ruleDistance != 2 && ClientManager.ListClient[IndexClient].info_game.plateauCases[ySelected][xSelected].mainCombo &&
                                          Player.info_game.iscombo) || !Distance.sameDiagonal(y, x, ySelected, xSelected))
                {
                    isPlaying.SendMsg("Vous ne pouvez pas faire cela");
                    return(false);
                }

                //sendAnimation(isPlaying, (int)BunifuAnimatorNS.AnimationType.Transparent, x, y);

                Careful.resetNotCarefulOpponent(Opponent);

                Careful.checkJumpingNotPlayed(Player, x, y);

                ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king = ClientManager.ListClient[IndexClient].info_game.plateauCases[ySelected][xSelected].king;
                ClientManager.ListClient[IndexClient].info_game.plateauCases[ySelected][xSelected].king = false;

                Match.SynchroWithOpponents(isPlaying);

                setCase(isPlaying, x, y, imageManager.getPawnImgByPlayer(playerTop, ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king), true, playerTop);

                setCase(isPlaying, xSelected, ySelected);
                imageManager.pawnToKing(isPlaying, playerTop, x, y);

                if (ruleDistance == 2)
                {
                    bool isKing = ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].king;

                    int xPawn = Distance.xPawn;
                    int yPawn = Distance.yPawn;

                    //sendAnimation(isPlaying, (int)BunifuAnimatorNS.AnimationType.Particles, xPawn, yPawn);

                    setCase(isPlaying, xPawn, yPawn);
                    Opponent.info_game.pawnAlive--;

                    if (!isKing)
                    {
                        if (Attack.detectCanAtk(Player, x, y))
                        {
                            Player.info_game.iscombo = true;
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].mainCombo = true;
                            Match.SynchroWithOpponents(isPlaying);
                            return(true);
                        }
                    }
                    else
                    {
                        if (Attack.detectCanAtkForKing(Player, x, y))
                        {
                            Player.info_game.iscombo = true;
                            ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].mainCombo = true;
                            Match.SynchroWithOpponents(isPlaying);
                            return(true);
                        }
                    }

                    Player.info_game.iscombo = false;
                    ClientManager.ListClient[IndexClient].info_game.plateauCases[y][x].mainCombo = false;
                    Match.SynchroWithOpponents(isPlaying);
                    if (EndGame.OpponentIsDead(Opponent))
                    {
                        return(true);
                    }
                }

                playerManager.ChangeGameTurn(Player);

                xSelected = -1;
                ySelected = -1;
            }
            return(true);
        }