private async void Button_Click(object sender, RoutedEventArgs e) { playerOne = Player1name.Content.ToString(); playerTwo = Player2name.Content.ToString(); if (Startbtn.Content == "Start") { Wordjumble game1 = new Wordjumble(); this.Content = game1; using (var db = new WordJumbleScoreBoardEntities3()) { LB newPlayer = new LB(); LB newPlayer2 = new LB(); newPlayer.Name = playerOne; newPlayer.Score = 0; newPlayer2.Name = playerTwo; newPlayer2.Score = 0; db.LBs.Add(newPlayer); db.LBs.Add(newPlayer2); db.SaveChanges(); } //HighScore.ItemsSource = db.LBs.ToList(); } if (string.IsNullOrWhiteSpace(Namebox.Text)) { Namebox.Background = Brushes.Red; Namebox.Opacity = 0.3; if (Namebox.Background == Brushes.Red) { await Task.Delay(500); Namebox.Background = Brushes.Aqua; Namebox.Opacity = 0.7; } } else { Player1name.Content = Namebox.Text; Namebox.Text = " "; Namebox.Visibility = Visibility.Hidden; (App.Current as App).player1 = Player1name.Content.ToString(); if (Namebox.Visibility == Visibility.Hidden) { Nameboxp2.Visibility = Visibility.Visible; } } if (string.IsNullOrWhiteSpace(Nameboxp2.Text)) { Namebox.Background = Brushes.Red; Namebox.Opacity = 0.3; if (Namebox.Background == Brushes.Red) { await Task.Delay(500); Namebox.Background = Brushes.Aqua; Namebox.Opacity = 0.7; } } else { Player2name.Content = Nameboxp2.Text; Nameboxp2.Text = " "; (App.Current as App).player2 = Player2name.Content.ToString(); Startbtn.Content = "Start"; } }
public async void Checkbtn_Click(object sender, RoutedEventArgs e) { if (whosturn == true) { playerturn.Content = selectedplayer1; ScoreCount.Content = P1Score; } else { playerturn.Content = selectedplayer2; ScoreCount.Content = P2Score; } if (Answertxt.Text == Answers) { Correctping.Play(); Answertxt.Background = Brushes.ForestGreen; //istictac = true; Answertxt.Text = ""; Answertxt.Background = Brushes.Aqua; tester(); if (whosturn == true) { P1Score += 100; ScoreCount.Content = P1Score; } else { P2Score += 100; ScoreCount.Content = P2Score; } //navwindow.Navigate(new tic_tac_toe().KeepAlive); } else //if(Answertxt.Text != Answers) { incorrectping.Play(); Answertxt.Background = Brushes.Red; await Task.Delay(500); Answertxt.Background = Brushes.Aqua; P1S += 1f; if (P1S % 2 == 0) { if (whosturn == true) { whosturn = false; tester(); Answertxt.Text = ""; } else { whosturn = true; tester(); Answertxt.Text = ""; } } if (P1S == 7) { finalp1Score.Content = ($"{selectedplayer1}: {P1Score}"); } if (P1S == 9) { finalp2Score.Content = ($"{selectedplayer2}: {P2Score}"); if (P1Score > P2Score) { MessageBox.Show($"{selectedplayer1} Wins"); } else { MessageBox.Show($"{selectedplayer2} Wins"); } Answertxt.IsEnabled = false; using (var db = new WordJumbleScoreBoardEntities3()) { var updatePlayer = db.LBs.OrderByDescending(p => p.Id).Skip(1).First(); updatePlayer.Score = P1Score; var updatePlayer2 = db.LBs.OrderByDescending(p => p.Id).First(); updatePlayer2.Score = P2Score; db.SaveChanges(); } //this.Content = new Wordjumble(); } /*counter++; * * if(counter == 2 && whosturn == true) * { * whosturn = false; * * finalCount.Content = ($"{selectedplayer1}: {Score}"); * } * else if(counter == 2 && whosturn == false) * { * * whosturn = true; * // counter = 0; * * }*/ } }