Сервис быстрых ответов от искусственного интеллекта
Вопрос пользователя:
Ответ нейросети:
Для написания викторины на WPF C# вам понадобится создать новый проект WPF в Visual Studio и добавить необходимые элементы управления, такие как текстовые блоки, кнопки, радиокнопки и т.д.
Пример кода для создания простой викторины:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace WpfQuizApp
{
public partial class MainWindow : Window
{
private List<Question> questions;
private int currentQuestionIndex;
public MainWindow()
{
InitializeComponent();
InitializeQuestions();
ShowQuestion();
}
private void InitializeQuestions()
{
questions = new List<Question>
{
new Question("What is the capital of France?", new List<string> { "London", "Paris", "Berlin", "Rome" }, 1),
new Question("What is the largest planet in our solar system?", new List<string> { "Mars", "Venus", "Jupiter", "Saturn" }, 2),
new Question("Who painted the Mona Lisa?", new List<string> { "Vincent van Gogh", "Leonardo da Vinci", "Pablo Picasso", "Michelangelo" }, 1)
};
}
private void ShowQuestion()
{
if (currentQuestionIndex < questions.Count)
{
Question question = questions[currentQuestionIndex];
questionTextBlock.Text = question.Text;
answersRadioButtons.Children.Clear();
foreach (string answer in question.Answers)
{
RadioButton radioButton = new RadioButton();
radioButton.Content = answer;
answersRadioButtons.Children.Add(radioButton);
}
}
else
{
MessageBox.Show("Quiz completed!");
}
}
private void NextButton_Click(object sender, RoutedEventArgs e)
{
Question currentQuestion = questions[currentQuestionIndex];
RadioButton selectedAnswer = answersRadioButtons.Children.OfType<RadioButton>().FirstOrDefault(r => r.IsChecked == true);
if (selectedAnswer != null && currentQuestion.CorrectAnswerIndex == answersRadioButtons.Children.IndexOf(selectedAnswer))
{
MessageBox.Show("Correct!");
}
else
{
MessageBox.Show("Incorrect!");
}
currentQuestionIndex++;
ShowQuestion();
}
}
public class Question
{
public string Text { get; set; }
public List<string> Answers { get; set; }
public int CorrectAnswerIndex { get; set; }
public Question(string text, List<string> answers, int correctAnswerIndex)
{
Text = text;
Answers = answers;
CorrectAnswerIndex = correctAnswerIndex;
}
}
}
Этот код создает простое приложение викторины с тремя вопросами и вариантами ответов. При нажатии на кнопку "Next" программа проверяет выбранный ответ и выводит сообщение о правильности ответа.
Напишите нам, если в вопросе есть ваши персональные данные (yasnoponyatno24@yandex.ru)
Обратите внимание: ответы, предоставляемые искусственным интеллектом, могут не всегда быть точными. Не рассчитывайте на них в критически важных областях, таких как медицина, юриспруденция, финансы или в вопросах, связанных с безопасностью. Для важных решений всегда обращайтесь к квалифицированным специалистам. Администрация сайта не несет ответственности за контент, сгенерированный автоматически.