Загрузка данных


<Window x:Class="WpfApp1.MainMenu"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Главное меню" Height="300" Width="400">

    <Grid>
        <Button Content="Играть"
                Width="150" Height="60"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Click="StartGame_Click"/>
    </Grid>
</Window>
using System.Windows;

namespace WpfApp1
{
    public partial class MainMenu : Window
    {
        public MainMenu()
        {
            InitializeComponent();
        }

        private void StartGame_Click(object sender, RoutedEventArgs e)
        {
            GameWindow game = new GameWindow();
            game.Show();
            this.Close();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace WpfApp1
{
    public partial class GameWindow : Window
    {
        int Numb = 1;
        int score = 0;

        bool hint50 = true;
        bool hintHall = true;
        bool hintFriend = true;

        List<AfQ> qwest = new List<AfQ>();
        Random rnd = new Random();

        public GameWindow()
        {
            InitializeComponent();
            qwest = AfQ.GetQuestions();
            UpdateQuestion();
        }

        private void AnswerForQuestion(object sender, RoutedEventArgs e)
        {
            var q = qwest.Where(m => m.Number == Numb).FirstOrDefault();

            string selected = "";

            if (Answer1.IsChecked == true) selected = Answer1.Content.ToString();
            if (Answer2.IsChecked == true) selected = Answer2.Content.ToString();
            if (Answer3.IsChecked == true) selected = Answer3.Content.ToString();
            if (Answer4.IsChecked == true) selected = Answer4.Content.ToString();

            if (selected == "")
            {
                MessageBox.Show("Выберите ответ!");
                return;
            }

            if (selected == q.RightAnswer)
            {
                score += q.Price;
                MessageBox.Show("Правильно!");

                Numb++;

                if (Numb > qwest.Count)
                {
                    EndWindow end = new EndWindow(score);
                    end.Show();
                    this.Close();
                }
                else
                {
                    UpdateQuestion();
                }
            }
            else
            {
                MessageBox.Show("Неправильно!");
                EndWindow end = new EndWindow(score);
                end.Show();
                this.Close();
            }
        }

        private void Button_Click_50(object sender, RoutedEventArgs e)
        {
            if (!hint50) return;

            var q = qwest.First(x => x.Number == Numb);

            if (Answer1.Content.ToString() != q.FiftyFiftyAnswer1 && Answer1.Content.ToString() != q.FiftyFiftyAnswer2)
                Answer1.Visibility = Visibility.Hidden;

            if (Answer2.Content.ToString() != q.FiftyFiftyAnswer1 && Answer2.Content.ToString() != q.FiftyFiftyAnswer2)
                Answer2.Visibility = Visibility.Hidden;

            if (Answer3.Content.ToString() != q.FiftyFiftyAnswer1 && Answer3.Content.ToString() != q.FiftyFiftyAnswer2)
                Answer3.Visibility = Visibility.Hidden;

            if (Answer4.Content.ToString() != q.FiftyFiftyAnswer1 && Answer4.Content.ToString() != q.FiftyFiftyAnswer2)
                Answer4.Visibility = Visibility.Hidden;

            hint50 = false;
            Hint50.Background = Brushes.Red;
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (!hintFriend) return;

            hintFriend = false;
            HintFriend.Background = Brushes.Red;

            var q = qwest.First(x => x.Number == Numb);
            MessageBox.Show("Друг думает: " + q.RightAnswer);
        }

        private void Button_Click_Hall(object sender, RoutedEventArgs e)
        {
            if (!hintHall) return;

            hintHall = false;
            HintHall.Background = Brushes.Red;

            var q = qwest.First(x => x.Number == Numb);

            int correct = rnd.Next(60, 80);
            MessageBox.Show("Большинство выбирает: " + q.RightAnswer + " (" + correct + "%)");
        }

        private void UpdateQuestion()
        {
            var q = qwest.First(x => x.Number == Numb);

            QuestionNumber.Text = "Вопрос № " + Numb;
            QuestionText.Text = q.Question;

            Answer1.Content = q.Answer1;
            Answer2.Content = q.Answer2;
            Answer3.Content = q.Answer3;
            Answer4.Content = q.Answer4;

            ScoreText.Text = "Очки: " + score;

            Answer1.IsChecked = false;
            Answer2.IsChecked = false;
            Answer3.IsChecked = false;
            Answer4.IsChecked = false;

            Answer1.Visibility = Visibility.Visible;
            Answer2.Visibility = Visibility.Visible;
            Answer3.Visibility = Visibility.Visible;
            Answer4.Visibility = Visibility.Visible;
        }
    }
}
<Window x:Class="WpfApp1.EndWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Конец игры" Height="300" Width="400">

    <Grid>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

            <TextBlock Name="FinalScore"
                       FontSize="24"
                       Margin="0,0,0,20"
                       TextAlignment="Center"/>

            <Button Content="Вернуться на главный экран"
                    Width="250"
                    Height="50"
                    Click="BackToMenu_Click"/>

        </StackPanel>
    </Grid>
</Window>
using System.Windows;

namespace WpfApp1
{
    public partial class EndWindow : Window
    {
        public EndWindow(int score)
        {
            InitializeComponent();
            FinalScore.Text = "Ваш счет: " + score;
        }

        private void BackToMenu_Click(object sender, RoutedEventArgs e)
        {
            MainMenu menu = new MainMenu();
            menu.Show();
            this.Close();
        }
    }
}