Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.t.Abort();
            Client.client_socket.ReceiveTimeout = this.originalTimeout;
            byte[]            response = new byte[200];
            GameStartResponse res      = new GameStartResponse();

            byte[] request = serializer.buildMessage(17);
            Client.client_socket.Send(request);

            lock (Client.locker)
            {
                res = serializer.DeAssembleMessage <GameStartResponse>(response);
            }

            if (res.status == 1)
            {
                if (game_form == null)
                {
                    game_form = new game();

                    game_form.Parent = this;
                }

                game_form.Show();

                this.Hide();
            }
        }
Beispiel #2
0
        private void listen()
        {
            while (true)
            {
                Client.client_socket.ReceiveTimeout = 1;
                GameStartResponse   resS = new GameStartResponse();
                GetRoomStateReponse res  = new GetRoomStateReponse();
                byte[] response          = new byte[200];
                byte[] code  = new byte[1];
                int    bytes = -1;
                try
                {
                    lock (Client.locker)
                    {
                        bytes = Client.client_socket.Receive(code, 1, 0);
                    }
                }
                catch
                {
                    Console.Write("Hello World");
                }
                if (bytes == 0 || bytes == -1)
                {
                    Client.client_socket.ReceiveTimeout = originalTimeout;
                    byte[] request = serializer.buildMessage(19);
                    lock (Client.locker)
                    {
                        Client.client_socket.Send(request);
                        Client.client_socket.Receive(code, 1, 0);
                    }
                }
                if (bytes == 1)
                {
                    Console.Write("Hello World");
                }

                if (code[0] == 17)
                {
                    resS = serializer.DeAssembleMessageForThread <GameStartResponse>(response);
                    if (resS.status == 1)
                    {
                        return;
                    }
                }
                else
                {
                    res = serializer.DeAssembleMessageForThread <GetRoomStateReponse>(response);
                    if (res.status == 1)
                    {
                        for (int i = 0; i < res.players.Count; i++)
                        {
                            if (players_[i].Text == "")
                            {
                                players_[i].Text = res.players[i];
                            }
                        }
                        for (int i = players_.Count; i > res.players.Count; i--)
                        {
                            players_[i - 1].Text = "";
                        }
                    }
                }
                Thread.Sleep(3000);
            }
        }