Beispiel #1
0
 void CurrentBoard_OnPlayerWin(CellValues player)
 {
     ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), player.ToString() + " win!");
     chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
     chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
     chatBox.Items.Add(chatMessage);
     endGame = true;
     
 }
Beispiel #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            socket = IO.Socket("ws://gomoku-lajosveres.rhcloud.com:8000");
            bool firstConnect = true;
            object oldData = new object();
            while(true)
            {
                Thread.Sleep(100);
                socket.On("ChatMessage", (data) =>
                {
                    if(firstConnect || oldData != data)
                    {
                        firstConnect = false;
                        string chatSender;
                        string message = ((JObject)data)["message"].ToString();

                        if (((JObject)data)["from"] != null)
                        {
                            chatSender = ((JObject)data)["from"].ToString();
                        }
                        else
                        {
                            chatSender = "Server";
                        }
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            ChatMessage chatMessage = new ChatMessage(chatSender, DateTime.Now.ToString("hh:mm:ss tt"), message);
                            chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                            chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                            chatBox.Items.Add(chatMessage);
                            if (((JObject)data)["message"].ToString() == "Welcome!")
                            {
                                
                              
                                socket.Emit("MyNameIs", txtYourName.Text);
                                socket.Emit("ConnectToOtherPlayer");
                            }
                            
                        }));
                        oldData = data;
                    }
                });
            }
        }
Beispiel #3
0
 private void btnSend_Click(object sender, RoutedEventArgs e)    //Send message to chatbox
 {
     if (txtMessage.Text != "" && nameChanged)
     {
         ChatMessage chatMessage = new ChatMessage(player.Name, DateTime.Now.ToString("hh:mm:ss tt"), txtMessage.Text);
         chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
         chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
         chatBox.Items.Add(chatMessage);
     }         
 }