Esempio n. 1
0
 private void DeleteID_Click(object sender, EventArgs e)
 {
     SessionID.Invoke(new Action(() => SessionID.Text         = ""));
     SessionIDInfo.Invoke(new Action(() => SessionIDInfo.Text = "Użytkownik usunął ID sesji!"));
     LogTextBox.Invoke(new Action(() => LogTextBox.Text       = "RECIEVER> Waiting for data..."));
 } //DELET ID
Esempio n. 2
0
        public void ExecAndAck()
        {
            FromByte(this.buffer);
            //Wybór co robimy na podstawie operacji:

            if (this.op == "HelloThere")        //Przydział ID
            {
                if (this.od == "GeneralKenobi") //Serwer przysłał nam nowe ID!
                {
                    SessionID.Invoke(new Action(() => SessionID.Text         = this.id));
                    SessionIDInfo.Invoke(new Action(() => SessionIDInfo.Text = "Otrzymano nowe ID od serwera!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }

                if (this.od == "NOK") //Serwer nie przysłał nam nowego ID!
                {
                    SessionID.Invoke(new Action(() => SessionIDInfo.Text = "Serwer odmówił przydziału ID!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", "", tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }
            }

            if (this.op == "TR") //Pozostały czas
            {
                SetReadyToSend(true);
                GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Czas ucieka!"));
                TimeLeft.Invoke(new Action(() => TimeLeft.Text = tm));

                //Potwierdzenie komunikatu

                SetMessage(op, "RogerRoger", id, tm, lb);
                SendMessageToServer(2);

                //Sprzątanie

                SetMessage("");
                this.buffer = null;
                return;
            }

            if (this.op == "GN")     //Zgadywanie liczby
            {
                if (this.od == "WN") //Nie zgadłeś
                {
                    GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Zła liczba!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(2);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }

                if (this.od == "WIN")
                {
                    GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Brawo! O tą liczbę mi chodziło!"));
                    Number.Invoke(new Action(() => Number.BackColor = Color.PaleGreen));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie po wygranej!!!
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> User has won the game! Terminating connection...\r\n")));
                    TimeLeft.Invoke(new Action(() => TimeLeft.Text   = ""));
                    SessionID.Invoke(new Action(() => SessionID.Text = ""));
                    SetReadyToSend(false);

                    SetMessage("");
                    this.buffer = null;
                    return;
                }
            }

            if (this.op == "ItIsOverAnakin") //Koniec gry
            {
                LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> It is over! Server has terminated the communication.\r\n")));
                TimeLeft.Invoke(new Action(() => TimeLeft.Text               = ""));
                SessionID.Invoke(new Action(() => SessionID.Text             = ""));
                GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "To koniec Anakinie, mam wysoką ziemię!"));
                SetReadyToSend(false);

                //?potfierdzenie?

                return;
            }

            //W przypadku, gdy nie trafiliśmy w żadnego ifa
            WrongMessage();
            return;
        }