Exemplo n.º 1
0
 public void Update()
 {
     if (IsSearchState)
     {
         Search_Icon.RotateOn(0.01f);
         if (CancelSearch.Update() == ButtonStates.CLICKED)
         {
             SearchStateHide();
             CommandParser.SendCommandToMasterServer(new string[] { "STOPSEARCH" });
         }
     }
     else
     {
         for (var i = 0; i < DeckButtons.Length; i++)
         {
             if (DeckButtons[i].Update() == ButtonStates.CLICKED)
             {
                 ChoosedDeck = i;
             }
         }
         if (StartEnemySearch.Update() == ButtonStates.CLICKED)
         {
             SearchStateShow();
             CommandParser.SendCommandToMasterServer(new string[] { "SEARCH", ChoosedDeck.ToString() });
         }
         DeckButtons[ChoosedDeck].PlayAnimation("Selected");
     }
 }
Exemplo n.º 2
0
        public int Update(NetworkInterface MasterNI)
        {
            NameEdit.Update();
            PassEdit.Update();
            Br.UpdateAnims();
            if (Login.Update() == ButtonStates.CLICKED)
            {
                //DONE: Запрос на сервер
                IsRegistration  = false;
                IsRequestSended = false;
                MasterNI.ConnectTo(Config.ServerIP);
                Log.SendMessage("Подключение к мастер-серверу");

                ShowConnectingState();
            }
            else
            if (Register.Update() == ButtonStates.CLICKED)
            {
                //DONE: Запрос на сервер
                IsRegistration  = true;
                IsRequestSended = false;
                MasterNI.ConnectTo(Config.ServerIP);
                Log.SendMessage("Подключение к мастер-серверу");

                ShowConnectingState();
            }

            if (IsConnectingState)
            {
                Connecting_Icon.RotateOn(0.01f);

                if (MasterNI.IsConnected)
                {
                    if (IsRequestSended)
                    {
                        string[] command = null;
                        CommandParser.UpdateMasterServer(out command);
                        if (command != null)
                        {
                            IsRequestSended = false;
                            if (command[0] == "OK")
                            {
                                if (IsRegistration)
                                {
                                    SetText("Успешно зарегестрирован");
                                    ShowNormalState();
                                    MasterNI.Disconnect();
                                }
                                else
                                {
                                    ShowNormalState();
                                    _PlayerName  = command[1];
                                    _PlayerMoney = Convert.ToInt32(command[2]);
                                    Hide(true);
                                    return(1);
                                }
                            }
                            else
                            if (command[0] == "ERROR")
                            {
                                SetErrorText(Convert.ToInt32(command[1]));
                                ShowNormalState();
                                MasterNI.Disconnect();
                            }
                        }
                    }
                    else
                    {
                        IsRequestSended = true;
                        if (IsRegistration)
                        {
                            CommandParser.SendCommandToMasterServer(new string[] { "REGISTER", NameEdit.Text, PassEdit.Text });
                        }
                        else
                        {
                            CommandParser.SendCommandToMasterServer(new string[] { "LOGIN", NameEdit.Text, PassEdit.Text });
                        }
                    }
                }
                else
                {
                    if (MasterNI.IsError)
                    {
                        SetErrorText(ServerErrors.Length - 1);
                        IsRequestSended = false;
                        ShowNormalState();
                        MasterNI.Disconnect();
                    }
                }
            }
            return(0);
        }