Exemplo n.º 1
0
        private bool veryfyList(PlayerL actuallist)

        {
            playersData listForVer = new playersData(actuallist.lista);

            return(listForVer.veryfiPlayersTypes());
        }
Exemplo n.º 2
0
        private void clientStart1()
        {
            cc = new Client(pl);
            Message ms = new Message();

            cc.cltStart("89.70.34.25", 50201);

            sendClientMSG();

            UPD_plList(plData.getList());
            //   startGame();
            while (!_shouldStop)
            {
                Message ms1 = new Message();
                ms1.Data = cc.checkIfGameStarted();

                PlayerL togame = SRL.takeM(ms1);
                //      activegame = true;
                check_MSG(togame);
                if (_shouldStop)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void clientStart()
        {
            ppp = new PlayerL(pl);

            /*  for (int i = 0; i < 8; i++)
             * {
             * Player p = new Player("127.0.0."+ i.ToString(), "aaa" + i.ToString());
             *
             * ppp.AddToPL(p);
             *
             * }*/
            Message msg1 = SRL.Serialize(ppp); // w msg.Data jest obiekt do wysłania

            cc = new Client(pl);
            Message ms = new Message();

            cc.cltStart("89.70.34.25", 50201);
            ms.Data = cc.runClient(msg1.Data);
            PlayerL ppppp2 = SRL.takeM(ms);

            check_MSG(ppppp2);

            UPD_plList(plData.getList());
            //   startGame();
            Message ms1 = new Message();

            ms1.Data = cc.checkIfGameStarted();
            PlayerL togame = SRL.takeM(ms1);

            check_MSG(togame);
        }
Exemplo n.º 4
0
        public void sendClientMSG()
        {
            Message ms = new Message();

            ms.Data = cc.runClient(sendMsg.Data);
            PlayerL ppppp2 = SRL.takeM(ms);

            check_MSG(ppppp2);
        }
Exemplo n.º 5
0
        public void processMSG()
        {
            Message msg2 = new Message();

            msg2.Data = ss.getMSG();
            if (msg2.Data != null)
            {
                PlayerL ppppp2 = SRL.takeM(msg2);
                check_MSG(ppppp2);
            }
        }
Exemplo n.º 6
0
 public bool check_Start(PlayerL plL)
 {
     if (plL.type == msgType.startGame)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        private void start_the_game()
        {
            if (server)
            {
                PlayerL sss = new PlayerL();
                sss.type = msgType.startGame;

                Message m = response(sss);
                ss.sendMSG(m);
            }
        }
Exemplo n.º 8
0
 public void SendColorRes(msgType cres)//zwrotka na zmianę koloru
 {
     if (server)
     {
         PlayerL sss = new PlayerL();
         sss.Lista = plData.getList();
         sss.type  = cres;
         Message m  = response(sss);
         Message ms = new Message();
         ss.sendMSG(m);
     }
 }
Exemplo n.º 9
0
        protected bool checkD(PlayerL pla)

        {
            if (pla.type == msgType.startGame)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        ////test połączenia
        private void serverStart()
        {
            Message msg2 = new Message();

            ss = new Server(pl);
            ss.socketSart();
            // czekamy na odbiór wyników
            msg2.Data = ss.getMSG();

            if (msg2.Data != null)
            {
                PlayerL ppppp2 = SRL.takeM(msg2);
                check_MSG(ppppp2);
            }
        }
Exemplo n.º 11
0
        public void UPD_srv_col()//zaktualizuj i wyswietl nowe kolory i odeslij reszcie
        {
            UPD_plList(plData.getList());
            if (activegame)
            {
                if (server)
                {
                    PlayerL p = new PlayerL();
                    p.lista = plData.getList();
                    p.type  = msgType.colorUpd;

                    Message m = response(p);
                    ss.sendMSG(m);
                }
            }
        }
Exemplo n.º 12
0
 private void MSGUpdPlayers(PlayerL ppppp2)//updatuje playersData o otrzymaną listę graczy
 {
     if (ppppp2 != null)
     {
         if (ppppp2.lista != null)
         {
             if (ppppp2.lista.Count > 0)
             {
                 foreach (Player p in ppppp2.lista)
                 {
                     plData.UpdatePlayerID(p);
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
 private void MSGUpdColorss(PlayerL ppppp2)//updatuje playersData o otrzymaną listę graczy
 {
     if (ppppp2 != null)
     {
         if (ppppp2.lista != null)
         {
             if (ppppp2.lista.Count > 0)
             {
                 foreach (Player p in ppppp2.lista)
                 {
                     plData.Change_Color(p, p.rabbitColor);
                     // updPlayerColor(p);
                 }
             }
         }
     }
 }
Exemplo n.º 14
0
        public Message preparesMSG(msgType m)
        {
            PlayerL player = new PlayerL(pl);

            player.type = m;

            /*if (m == msgType.colorUpd)//do testów
             * {
             *    player.Lista[0].playerID = "test";
             *    player.Lista[0].iPadd = "127.0.1.0";// na potrzeby testów
             *    player.Lista[0].Color = kolor;
             * }*/

            Message msg1 = SRL.Serialize(player); // w msg.Data jest obiekt do wysłania

            return(msg1);
        }
Exemplo n.º 15
0
        public Form3(Player pl, Point location, bool connection, Server serv, PlayerL actualList)
        {
            InitializeComponent();

            recentList    = actualList;
            player1       = pl;
            ss            = serv;
            serwer        = connection;      // czy jestem serwerem czy clientem
            this.Location = location;
            this.Show();
            buttonsLook();         // nazwy buttonów i inne

            button1.Click += startClick_EventHandler;

            communication = new Thread(new ThreadStart(exchangePlayerData));     // wyrzucamy serwer do innego wątku
            communication.Start();
            // createNewForm(connection);
        }
Exemplo n.º 16
0
        private bool veryfiStart(Message m)

        {
            PlayerL recivedList = SRL.takeM(m);

            if (recivedList != null)
            {
                if (recivedList.lista != null)             // sprawdzamy czy otrzymana lista jest niepusta
                {
                    playersData data = new playersData(recentList.lista);
                    if (true)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 17
0
 private void MSGAddPlayers(PlayerL ppppp2)//updatuje playersData o otrzymaną listę graczy
 {
     if (ppppp2 != null)
     {
         if (ppppp2.lista != null)
         {
             if (ppppp2.lista.Count > 0)
             {
                 foreach (Player p in ppppp2.lista)
                 {
                     if (p.iPadd != pl.iPadd)
                     {
                         //trzeba zrobic logike dodawania
                         plData.AddToPlayerList(p);
                     }
                 }
                 //   updatePlayerList2(ppp.lista);
             }
         }
     }
 }
Exemplo n.º 18
0
        private void processMSG(Message m)
        {
            PlayerL recivedList = SRL.takeM(m);            // tutaj tylko jednoelementowa lista

            if (recivedList != null)
            {
                if (recivedList.lista != null)             // sprawdzamy czy otrzymana lista jest niepusta
                {
                    playersData data = new playersData(recentList.lista);

                    for (int i = 0; i < recivedList.lista.Count(); i++)

                    {
                        data.udpdateData(recivedList.lista[i]);                  // aktualizujemy to co dostalismy
                    }

                    recentList.lista = data.getPlayersList();               // zrzucamy liste do listy (za duzo tego)
                                                                            //   updatePlayerList2(ppp.lista);
                }
            }
        }
Exemplo n.º 19
0
        private void runForm3()
        {
            PlayerL p = new PlayerL();

            p.lista = plData.getList();

            Form F3;

            // RequestStop();
            thread.Abort();
            if (server)
            {
                F3 = new Form3(pl, this.Location, server, ss, p);
            }
            else
            {
                F3 = new Form3(pl, this.Location, server, cc);
            }

            HideMe();
            F3.Enabled = true;
            F3.Visible = true;
            F3.Show();
        }
Exemplo n.º 20
0
        public void check_MSG(PlayerL plL)
        {
            switch (plL.type)
            {
            case msgType.startGame:
                _shouldStop = true;
                button5.Invoke(new Action(delegate()
                {
                    activegame = true;
                    button5.Show();
                    button5.PerformClick();
                    button5.Hide();
                }));

                /*
                 * this.Invoke(new Action(delegate ()
                 * {
                 *  this.Hide();
                 * }));*/
                break;

            case msgType.colorUpd:
                if (server)
                {
                    if (plData.checkColor(plL.Lista[0].Color))
                    {
                        MSGAddPlayers(plL);    //do testów
                                               //  MSGUpdPlayers(plL)// nie działa do konca
                        MSGUpdColorss(plL);
                        UPD_plList(plData.getList());
                        SendColorRes(msgType.okColor);
                    }
                    else
                    {
                        SendColorRes(msgType.wrongColor);
                    }
                }
                else     // klient powinien tylko zupdatowac dostanych graczy
                {
                    MSGAddPlayers(plL);
                    //   MSGUpdPlayers(plL);
                    MSGUpdColorss(plL);
                    UPD_plList(plData.getList());
                }

                break;

            case msgType.wrongColor:
                MSGAddPlayers(plL);
                updButtonColorWRONG();
                MSGUpdColorss(plL);
                //  MSGUpdPlayers(plL);
                UPD_plList(plData.getList());
                // LockButton1(true);
                break;

            case msgType.okColor:
                MSGAddPlayers(plL);
                //     MSGUpdPlayers(plL);
                MSGUpdColorss(plL);
                Player p = plData.getPlayerByIp(pl.iPadd);
                //  Player p = plData.getPlayerByLogin(pl.playerID);
                pl.rabbitColor = kolor;
                plData.Change_Color(pl, kolor);
                //  updOwnColor();


                UPD_plList(plData.getList());
                //  LockButton1(true);
                updButtonColor();

                break;

            case msgType.addPlayer:

                //dodaj gracza
                activegame = true;
                MSGAddPlayers(plL);
                // label3.Text = ppp.lista[0].playerID;
                UPD_plList(plData.getList());
                PlayerL sss = new PlayerL();
                sss.type = msgType.gameOn;

                sss.lista = plData.getList();
                Message m = response(sss);
                ss.sendMSG(m);

                break;

            case msgType.gameOn:    //dolaczono do gry

                activegame = true;
                MSGAddPlayers(plL);
                //  MSGUpdPlayers(plL);
                //  MSGUpdColorss(plL);//troche za duzo
                UPD_plList(plData.getList());

                break;


            case msgType.goOn:    //serwer i client przestają czekac na msg


                if (!server)
                {
                    Message msg4 = preparesMSG(msgType.goOn);
                    cc.sendOnlyClient(msg4.Data);
                }
                else
                {
                    start_the_game();
                    button5.Invoke(new Action(delegate()
                    {
                        activegame = true;
                        button5.Show();
                        button5.PerformClick();
                        button5.Hide();
                    }));
                }

                break;

            default:
                Console.WriteLine("Default case");
                break;
            }
        }
Exemplo n.º 21
0
        private void exchangePlayerData()

        {
            if (serwer)
            {
                Message TypeData = new Message();

                TypeData.Data = ss.getMSG();        // czekamy na message, odbieramy // deserializujemy

                processMSG(TypeData);               // wrzucamy message do obrobki

                waitForclick.WaitOne();             // poczekaj z weryfikacja az serwer kliknie !!!

                PlayerL confirmGame = new PlayerL();

                if (veryfyList(recentList))             // veryfikujemy liste (to bedzie inaczej wygladac w przypadku wielu graczy)
                {
                    // ( message z lista gdzie jest pozwolenie na gre )
                    //kask:zwrotka do clienta ze startem
                    confirmGame.type = msgType.startGame;
                    Message back = SRL.Serialize(confirmGame);


                    ss.sendMSG(back);
                    // jak w porzadku to wysylamy do klient ze lecimy dalej
                    //createNewForm(true);
                    // kask: wywolanie F4 z głownego watku
                    invoke_B4();
                }

                else
                {
                    confirmGame.type = msgType.empty;
                    //         ss.sendMSG ( Message z lista gdzie nie zezwala sie na gre
                    // a jak nie to gra jest wsrzymana i wybieramy jeszcze raz
                }
            }

            else

            {
                waitForclick.WaitOne();                           // zanim klient sie ruszy to musi poczekac az zostana dane wpisane

                PlayerL listTosend = new PlayerL(player1);        // do seralizacji zabieramy aktualnego playera

                Message singlePlayer = SRL.Serialize(listTosend); // serializujemygo i budujemy message

                cc.sendToServer(singlePlayer.Data);               // wysylamy go

                Message dataVer = new Message();

                dataVer.Data = cc.checkIfGameStarted();     // tu jest tablica z danymi do zweryfikowania

                PlayerL ver = SRL.takeM(dataVer);


                if (checkD(ver))                      // vczekamy na weryfikacje danych

                {
                    //kask:wywolanie F4 z glownego watku
                    invoke_B4();
                    //createNewForm(false);
                }

                else
                {
                }   // wybierzcie jeszcze raz}
            }
        }
Exemplo n.º 22
0
        public Message response(PlayerL p)//serializuje dane do wysłania
        {
            Message d = SRL.Serialize(p);

            return(d);
        }
Exemplo n.º 23
0
        public static Message doM(PlayerL player)
        {
            Message message = SRL.Serialize(player);

            return(message);
        }