private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) //backgroundworker medemogenlijk gemaakt door Jonathan :D danku voor de tip! { if (host == true) { ServerHost.RecieveTurn(); } else { ServerClient.RecieveTurn(); } }
private async void host_button_Click(object sender, EventArgs e) { player.SoundLocation = "click.wav"; player.Play(); await Task.Delay(300); player.Stop(); host = true; Connecting1Label.Visible = true; host_button.Enabled = false; client_button.Enabled = false; RandomizeButtons(); ServerHost.StartServer(); CheckConnect(); }
public async void Check_kaart() { Button[] ButtonGrid = { GridButton1, GridButton1Dup, GridButton2, GridButton2Dup, GridButton3, GridButton3Dup, GridButton4, GridButton4Dup, GridButton5, GridButton5Dup, GridButton6, GridButton6Dup, GridButton7, GridButton7Dup, GridButton8, GridButton8Dup }; if (Kaart1Select != null && Kaart2Select != null) { if (Kaart1Select.Tag == Kaart2Select.Tag) { if (Kaart1Select.Name == Kaart2Select.Name) { Kaart2Select = null; } else if (Kaart1Select.Name != Kaart2Select.Name) { player.SoundLocation = "ping.wav"; player.Play(); foreach (var x in ButtonGrid) { x.Enabled = false; } await Task.Delay(3000); Kaart1Select.Visible = false; Kaart2Select.Visible = false; TurnArray[0] = Kaart1Select.Name; TurnArray[1] = Kaart2Select.Name; if (host == true) { ServerHost.SendTurn(); } else { ServerClient.SendTurn(); } if (Connectionfail != true) // zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { Kaart1Select = null; Kaart2Select = null; Point_Add(); GC.Collect(); foreach (var x in ButtonGrid) { x.Enabled = true; } } } } else { foreach (var x in ButtonGrid) { x.Enabled = false; } await Task.Delay(3000); switch (thema) { case "Media": Kaart1Select.BackgroundImage = Resources.cardback; Kaart2Select.BackgroundImage = Resources.cardback; break; case "Films": Kaart1Select.BackgroundImage = Resources.clapperboard; Kaart2Select.BackgroundImage = Resources.clapperboard; break; case "Games": Kaart1Select.BackgroundImage = Resources.controller_cardback; Kaart2Select.BackgroundImage = Resources.controller_cardback; break; } TurnArray[0] = Kaart1Select.Name; TurnArray[1] = Kaart2Select.Name; if (host == true) { ServerHost.SendTurn(); } else { ServerClient.SendTurn(); } if (Connectionfail != true)// zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { Kaart1Select = null; Kaart2Select = null; Change_Beurt(); GC.Collect(); foreach (var x in ButtonGrid) { x.Enabled = false; } backgroundWorker.RunWorkerAsync(); } } } }
void SetupGame() { if (host == true) { player1 = LocalPlayer; ServerHost.SendGameState(); if (Connectionfail != true) { ServerHost.RecieveName(); } if (Connectionfail != true) { OtherPlayer = ServerHost.ClientName; OtherPlayerLabel.Text = OtherPlayer; player2 = OtherPlayer; PlayerBeurt = player1; BeurtLabel.Text = PlayerBeurt; ServerHost.SendName(); } if (Connectionfail != true) { Speler1Box.Visible = true; Speler2Box.Visible = true; BeurtBox.Visible = true; LocalPlayerLabel.Visible = true; OtherPlayerLabel.Visible = true; BeurtLabel.Visible = true; PuntenLocal.Text = "0"; PuntenOther.Text = "0"; PuntenLocal.Visible = true; PuntenOther.Visible = true; hostofclient.Visible = false; host_button.Visible = false; client_button.Visible = false; Button[] ButtonGrid = { GridButton1, GridButton1Dup, GridButton2, GridButton2Dup, GridButton3, GridButton3Dup, GridButton4, GridButton4Dup, GridButton5, GridButton5Dup, GridButton6, GridButton6Dup, GridButton7, GridButton7Dup, GridButton8, GridButton8Dup }; foreach (Button x in ButtonGrid) { x.Visible = true; } } } else { player2 = LocalPlayer; ServerClient.RecieveGamaData(); if (Connectionfail != true) // zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { Point[] ButtonGridLocation = ServerClient.TempRandomButLocation.ToArray(); for (int i = 0; i < ButtonGridLocation.Length; i++) { switch (i) { case 0: GridButton1.Location = ButtonGridLocation[i]; break; case 1: GridButton1Dup.Location = ButtonGridLocation[i]; break; case 2: GridButton2.Location = ButtonGridLocation[i]; break; case 3: GridButton2Dup.Location = ButtonGridLocation[i]; break; case 4: GridButton3.Location = ButtonGridLocation[i]; break; case 5: GridButton3Dup.Location = ButtonGridLocation[i]; break; case 6: GridButton4.Location = ButtonGridLocation[i]; break; case 7: GridButton4Dup.Location = ButtonGridLocation[i]; break; case 8: GridButton5.Location = ButtonGridLocation[i]; break; case 9: GridButton5Dup.Location = ButtonGridLocation[i]; break; case 10: GridButton6.Location = ButtonGridLocation[i]; break; case 11: GridButton6Dup.Location = ButtonGridLocation[i]; break; case 12: GridButton7.Location = ButtonGridLocation[i]; break; case 13: GridButton7Dup.Location = ButtonGridLocation[i]; break; case 14: GridButton8.Location = ButtonGridLocation[i]; break; case 15: GridButton8Dup.Location = ButtonGridLocation[i]; break; } } } if (Connectionfail != true) // zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { ServerClient.SendName(); } if (Connectionfail != true) // zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { ServerClient.RecieveName(); } if (Connectionfail != true) // zorgt ervoor dat deze code niet meer verwerkt word als er een connection error is opgetreden. { OtherPlayer = ServerClient.HostName; OtherPlayerLabel.Text = OtherPlayer; player1 = OtherPlayer; PlayerBeurt = player1; BeurtLabel.Text = PlayerBeurt; Speler1Box.Visible = true; Speler2Box.Visible = true; BeurtBox.Visible = true; LocalPlayerLabel.Visible = true; OtherPlayerLabel.Visible = true; BeurtLabel.Visible = true; PuntenLocal.Text = "0"; PuntenOther.Text = "0"; PuntenLocal.Visible = true; PuntenOther.Visible = true; ip.Visible = false; IpTextBox.Visible = false; connect_button.Visible = false; Button[] ButtonGrid = { GridButton1, GridButton1Dup, GridButton2, GridButton2Dup, GridButton3, GridButton3Dup, GridButton4, GridButton4Dup, GridButton5, GridButton5Dup, GridButton6, GridButton6Dup, GridButton7, GridButton7Dup, GridButton8, GridButton8Dup }; foreach (Button x in ButtonGrid) { x.Visible = true; x.Enabled = false; } backgroundWorker.RunWorkerAsync(); } } }