Anonim_999

Zad2Main

Jun 16th, 2022
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace Zad2
  5. {
  6.     public partial class Main : Form
  7.     {
  8.         private User _user;
  9.         private Random _random;
  10.         private string _binaryValue;
  11.         private int _maxQuastion = 5;
  12.         private int _currentQuastion = 0;
  13.         private int _rightAnswered = 0;
  14.  
  15.         public Main(User user)
  16.         {
  17.             InitializeComponent();
  18.             _user = user;
  19.             _random = new Random();
  20.         }
  21.  
  22.         private void Main_Load(object sender, EventArgs e)
  23.         {
  24.             label1.Text = $"Здравствйте, {_user.Login},";
  25.             this.Text = $"{_currentQuastion + 1}\\{_maxQuastion}";
  26.             Generate();
  27.         }
  28.  
  29.         private void Generate()
  30.         {
  31.             _binaryValue = Convert.ToString(_random.Next(1, 1000), 2);
  32.             BinaryTextBox.Text = _binaryValue;
  33.         }
  34.  
  35.         private void button1_Click(object sender, EventArgs e)
  36.         {
  37.             if (UserTextBox.Text != "")
  38.             {
  39.                 if (UserTextBox.Text == $"{Convert.ToInt32(_binaryValue,2)}")
  40.                 {
  41.                     MessageBox.Show("Верно!");
  42.                     _rightAnswered++;
  43.                 }
  44.                 else
  45.                 {
  46.                     MessageBox.Show($"Неверно, правильный ответ был: {Convert.ToInt32(_binaryValue, 2)}");
  47.                 }
  48.                 _currentQuastion++;
  49.  
  50.                 if (_currentQuastion >= _maxQuastion)
  51.                 {
  52.                     MessageBox.Show($"Тест завершен, твоя оценка: {_rightAnswered}");
  53.                     _currentQuastion = 0;
  54.                     _rightAnswered = 0;
  55.                 }
  56.                 this.Text = $"{_currentQuastion + 1}\\{_maxQuastion}";
  57.                 Generate();
  58.             }
  59.             else
  60.             {
  61.                 MessageBox.Show("Введите значение");
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment