private void Events_DataReceived(object sender, DataReceivedEventArgs e) { switch (Encoding.UTF8.GetString(e.Data).Split(':')[0]) { case Messages.Server.Start: this.Invoke((MethodInvoker) delegate { this.Hide(); gameForm = new GameForm(Encoding.UTF8.GetString(e.Data).Split(':')[1], this); gameForm.Text = this.Text; gameForm.Show(); }); break; case Messages.Client.Move: this.Invoke((MethodInvoker) delegate { gameForm.statusLabel.Text = "TWOJA TURA"; gameForm.enemyMoveFromServer(Int32.Parse(Encoding.UTF8.GetString(e.Data).Split(':')[1])); }); break; case Messages.Server.Cancel: break; case Messages.Server.Disconnect: MessageBox.Show("Błędny login lub hasło", "Login ERROR"); client.Disconnect(); loginFormsVisible(true); this.Invoke((MethodInvoker) delegate { this.Text = " "; }); break; case Messages.Server.User: this.Invoke((MethodInvoker) delegate { this.Text += $" W->{ Encoding.UTF8.GetString(e.Data).Split(':')[1]} P->{Encoding.UTF8.GetString(e.Data).Split(':')[2]}"; }); break; case Messages.Server.Registered: MessageBox.Show("Konto zostało stworzone", "Registered"); break; case Messages.Server.Matches: this.Invoke((MethodInvoker) delegate { String[] matches = Encoding.UTF8.GetString(e.Data).Split(':'); listBoxMatches.Items.Clear(); for (int i = 1; i < matches.Length; i++) { listBoxMatches.Items.Add($"{matches[i]}"); } }); break; case Messages.Server.Logged: MessageBox.Show("Taki gracz jest już zalogowany", "Login ERROR"); client.Disconnect(); loginFormsVisible(true); this.Invoke((MethodInvoker) delegate { this.Text = " "; }); break; case Messages.Server.Winner: this.Invoke((MethodInvoker) delegate { gameForm.Close(); this.Show(); this.joinButton.Enabled = true; this.buttonRefresh.Enabled = true; }); client.Send(Messages.Client.SaveGame + ":" + Encoding.UTF8.GetString(e.Data).Split(':')[1] + ":" + Encoding.UTF8.GetString(e.Data).Split(':')[2] + ":" + Encoding.UTF8.GetString(e.Data).Split(':')[3]); MessageBox.Show("Wygrał gracz - " + Encoding.UTF8.GetString(e.Data).Split(':')[3], "Koniec Gry"); break; case Messages.Server.Lost: this.Invoke((MethodInvoker) delegate { this.Show(); this.joinButton.Enabled = true; this.buttonRefresh.Enabled = true; this.client.Send(Messages.Server.Cancel); }); this.Invoke((MethodInvoker) delegate { gameForm.Close(); }); MessageBox.Show("Przegrana! Wygrał gracz - " + Encoding.UTF8.GetString(e.Data).Split(':')[1], "Koniec Gry"); break; } }