Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace Zad2
- {
- public partial class Main : Form
- {
- private User _user;
- private Random _random;
- private string _binaryValue;
- private int _maxQuastion = 5;
- private int _currentQuastion = 0;
- private int _rightAnswered = 0;
- public Main(User user)
- {
- InitializeComponent();
- _user = user;
- _random = new Random();
- }
- private void Main_Load(object sender, EventArgs e)
- {
- label1.Text = $"Здравствйте, {_user.Login},";
- this.Text = $"{_currentQuastion + 1}\\{_maxQuastion}";
- Generate();
- }
- private void Generate()
- {
- _binaryValue = Convert.ToString(_random.Next(1, 1000), 2);
- BinaryTextBox.Text = _binaryValue;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (UserTextBox.Text != "")
- {
- if (UserTextBox.Text == $"{Convert.ToInt32(_binaryValue,2)}")
- {
- MessageBox.Show("Верно!");
- _rightAnswered++;
- }
- else
- {
- MessageBox.Show($"Неверно, правильный ответ был: {Convert.ToInt32(_binaryValue, 2)}");
- }
- _currentQuastion++;
- if (_currentQuastion >= _maxQuastion)
- {
- MessageBox.Show($"Тест завершен, твоя оценка: {_rightAnswered}");
- _currentQuastion = 0;
- _rightAnswered = 0;
- }
- this.Text = $"{_currentQuastion + 1}\\{_maxQuastion}";
- Generate();
- }
- else
- {
- MessageBox.Show("Введите значение");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment