Пример #1
0
        public static async void Btn_Answer(object sender, RoutedEventArgs e)
        {
            if (current_right_answer == (sender as Button).Name.Split('_').Last())
            {
                QuestionTextBlock.Text = "Правильно!\n(。◕‿‿◕。)";
                ((MainWindow)Application.Current.MainWindow).canvas_question_options.Children.Clear();
                int    answer_num       = 0;
                Random rand_go          = new Random();
                int    count_of_animals = ((MainWindow)Application.Current.MainWindow).AnimalsList.Count;
                if (Int32.TryParse((sender as Button).Name.Split('_').Last(), out answer_num))
                {
                    ((MainWindow)Application.Current.MainWindow).AnimalsList[rand_go.Next(0, count_of_animals)].GoRightToLeft(
                        -300
                        );
                }
                else
                {
                    Animals.Animal animal_to_go = ((MainWindow)Application.Current.MainWindow).AnimalsList.FirstOrDefault
                                                      (o => o.Name.Contains((sender as Button).Name.Split('_').Last()));
                    animal_to_go.GoRightToLeft(-300);
                }
                ((MainWindow)Application.Current.MainWindow).common_score++;
                ((MainWindow)Application.Current.MainWindow).Score.Content =
                    ((MainWindow)Application.Current.MainWindow).common_score;
            }
            else
            {
                string temp_ques = QuestionTextBlock.Text;
                QuestionTextBlock.Text = "Неверно!\n☹";
                var result = await SimLongRunningProcessAsync();

                QuestionTextBlock.Text = temp_ques;
            }
        }
Пример #2
0
        public void InitAnimals(int min, int max)
        {
            Random rand_count    = new Random();
            Random rand_animal   = new Random();
            int    count_animals = rand_count.Next(min, max);

            Animals.Animal new_animal = null;
            for (int i = AnimalsList.Count + 1; i < count_animals; i++)
            {
                WasInit = true;
                int kind = rand_animal.Next(0, 3);
                switch (kind)
                {
                case 0:
                {
                    Animals.Dog dog = new Animals.Dog();
                    dog.Name   = "dog";
                    dog.Width  = dog_stay_width;
                    dog.Height = dog_stay_height;
                    dog.Margin = new Thickness(-dog_stay_width - start_pos, 0, 0, 0);
                    AnimalsList.Add(dog);
                    Canvas.SetBottom(dog, 10);
                    canvas_visual.Children.Add(dog);
                    StackPanel.SetZIndex(dog, 2);
                    new_animal = dog;
                    break;
                }

                case 1:
                {
                    Animals.Cat cat = new Animals.Cat();
                    cat.Width  = cat_stay_width;
                    cat.Name   = "cat";
                    cat.Height = cat_stay_width;
                    cat.Margin = new Thickness(-cat_stay_width - start_pos, 0, 0, 0);
                    Canvas.SetBottom(cat, 10);
                    AnimalsList.Add(cat);
                    canvas_visual.Children.Add(cat);
                    StackPanel.SetZIndex(cat, 2);
                    new_animal = cat;
                    break;
                }

                case 2:
                {
                    Animals.Bear bear = new Animals.Bear();
                    bear.Width  = bear_stay_width;
                    bear.Name   = "bear";
                    bear.Height = bear_stay_height;
                    bear.Margin = new Thickness(-bear_stay_width - start_pos, 0, 0, 0);
                    Canvas.SetBottom(bear, 20);
                    AnimalsList.Add(bear);
                    canvas_visual.Children.Add(bear);
                    new_animal = bear;
                    break;
                }
                }

                //calc x coord to
                double coord_to = 0;

                switch (i)
                {
                case 0:
                {
                    coord_to = new_animal.Margin.Left + AnimalsList[0].Width + 50;
                    break;
                }

                case 1:
                {
                    coord_to = new_animal.Margin.Left + 250;
                    break;
                }

                case 2:
                {
                    coord_to = new_animal.Margin.Left + 350;
                    break;
                }

                case 3:
                {
                    coord_to = new_animal.Margin.Left + 450;
                    break;
                }
                }
                if (AnimalsList.FirstOrDefault(o => o.Margin.Left == coord_to) != null)
                {
                    coord_to += coord_to < canvas_visual.ActualHeight / 2 ? -40 : 40;
                }
                // go animation
                new_animal.GoLeftToRight(coord_to);
            }

            // ask question
            Questions.AskQuestion();
        }