Esempio n. 1
0
        private void StartGameButton_Click(object sender, EventArgs e)
        {
            byte[] message = new ASCIIEncoding().GetBytes("122");
            ClientSocket.client.Send(message);
            byte[] response  = new byte[1024];
            int    bytesRead = ClientSocket.client.Receive(response);

            Array.Resize <byte>(ref response, bytesRead);
            if (GlobalHelpers.GetCode(response) == "222")
            {
                stopThread = true;
                this.Hide();
                var game = new GameQuestion(this.room.Metadata);
                game.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("Could Not Start Game!");
                LeaveLobbyButton.PerformClick();
            }
        }
        private void updateLoop()
        {
            while (!stopThread)
            {
                Thread.Sleep(5000);
                byte[] message = new ASCIIEncoding().GetBytes("123");
                ClientSocket.client.Send(message);
                byte[] response  = new byte[1024];
                int    bytesRead = ClientSocket.client.Receive(response);
                Array.Resize <byte>(ref response, bytesRead);
                if (GlobalHelpers.GetCode(response) == "223")
                {
                    var roomState = MessagePack.MessagePackSerializer.Deserialize <JSON_Classes.GetRoomStateResponse>(GlobalHelpers.GetMsgpack(response));
                    switch (roomState.Status)
                    {
                    case 0:
                        if (!stopThread)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                this.PlayerListBox.DataSource = roomState.Room.Players;
                            });
                        }
                        break;

                    default:
                        if (!stopThread)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                MessageBox.Show("There Was An Error Getting The Room Info!");
                                this.Close();
                                DialogResult = DialogResult.Abort;
                            });
                        }
                        break;
                    }
                    switch (roomState.Room.Metadata.IsActive) // Game Status Check
                    {
                    case 0:                                   // Still In Lobby, Do Nothing
                        break;

                    case -1:     // Admin Closed Lobby, Leave
                        if (!stopThread)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                MessageBox.Show("Room Has Been Closed!");
                                this.Close();
                                DialogResult = DialogResult.Abort;
                            });
                            stopThread = true;
                        }
                        break;

                    default:     // Game Started
                        if (!stopThread)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                this.Hide();
                                var game = new GameQuestion(this.room.Metadata);
                                game.ShowDialog();
                                this.Close();
                            });
                            stopThread = true;
                        }
                        break;
                    }
                }
            }
        }