Exemplo n.º 1
0
        private void PlayerReadyButton(object sender, RoutedEventArgs e)
        {
            Random rnd          = new Random();
            int    passwordTake = (int)((PasswordAmount)this.PasswordsComboBox.SelectedItem);

            for (int i = 0; i < passwordTake; i++)
            {
                int elementIndex = rnd.Next(0, PasswordCollection.Count - 1);
                PasswordGameCollection.Add(PasswordCollection.ElementAt(elementIndex));
                PasswordCollection.RemoveAt(elementIndex);
            }

            Passwordclass PasswordList = new Passwordclass();

            PasswordList = PasswordGameCollection.ElementAt(0);
            PasswordGameCollection.RemoveAt(0);
            PasswordLabelContent = PasswordList.Name;
            CategoryLabelContent = PasswordList.Category;

            PasswordAmountToQuess = passwordTake;

            playerReady = true;

            StackReadyPanel.Visibility = Visibility.Hidden;
            TimerTextBlock.Visibility  = Visibility.Visible;
            TimeForClock = TimeChoosen;
            Timer.Start();
        }
Exemplo n.º 2
0
        private void PasswordGuessed(object sender, RoutedEventArgs e)
        {
            if (playerReady)
            {
                StackReadyPanel.Visibility = Visibility.Visible;

                // here is some problem (only in full screen mode) with refreshing points in label graphic structure

                if (TeamToPLay && PasswordAmountToQuess > 0)
                {
                    Team2Score       += 1;
                    Team2ScoreContent = Team2Score.ToString() + " pkt";
                    Team2ScoreLabel.Refresh();
                }
                else if (!TeamToPLay && PasswordAmountToQuess > 0)
                {
                    Team1Score       += 1;
                    Team1ScoreContent = Team1Score.ToString() + " pkt";
                    Team1ScoreLabel.Refresh();
                }

                Task.Factory.StartNew(() =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { Team1ScoreLabel.UpdateLayout(); }));
                });

                Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { Team2ScoreLabel.UpdateLayout(); }));

                PasswordAmountToQuess--;

                GameIterations--;

                try
                {
                    if (PasswordAmountToQuess == 0 && GameIterations > 0)
                    {
                        Timer.Stop();
                        TimeForClock = TimeChoosen;

                        if (TeamToPLay)
                        {
                            TeamLabelContent   = Team1List.ElementAt(0);
                            PlayerLabelContent = Team1List.ElementAt(1);
                            Team1List.RemoveRange(0, 2);

                            TeamToPLay = team1;
                        }
                        else
                        {
                            TeamLabelContent   = Team2List.ElementAt(0);
                            PlayerLabelContent = Team2List.ElementAt(1);
                            Team2List.RemoveRange(0, 2);
                            TeamToPLay = team2;
                        }

                        TimerTextBlock.Visibility = Visibility.Hidden;
                        PasswordAmountToQuess     = (int)((PasswordAmount)this.PasswordsComboBox.SelectedItem);
                        MessageBox.Show("Następny gracz!");
                        playerReady = false;
                    }
                    else if (GameIterations > 0)
                    {
                        Passwordclass PasswordList = new Passwordclass();
                        PasswordList = PasswordGameCollection.ElementAt(0);
                        PasswordGameCollection.RemoveAt(0);
                        PasswordLabelContent = PasswordList.Name;
                        CategoryLabelContent = PasswordList.Category;
                    }

                    playerReady = false;

                    if (GameIterations <= 0)
                    {
                        int result = Team2Score - Team1Score;
                        if (result > 0)
                        {
                            MessageBox.Show("Koniec gry!\n Wygrała drużyna: " + Team2Name);
                        }
                        else if (result == 0)
                        {
                            MessageBox.Show("Koniec gry!\n REMIS!");
                        }
                        else
                        {
                            MessageBox.Show("Koniec gry!\n Wygrała drużyna: " + Team1Name);
                        }

                        SetParametersDefault();
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }