using Avalonia.Controls;
using Avalonia.Interactivity;
using System;
namespace GuessGameApp
{
public partial class MainWindow : Window
{
private readonly Random _random = new();
private string _secretCode = "";
public MainWindow()
{
InitializeComponent();
GenerateCode();
}
private void GenerateCode()
{
// Берем длину из выбранного пункта ComboBox (3, 4 или 5)
int length = DifficultyCombo.SelectedIndex + 3;
_secretCode = "";
for (int i = 0; i < length; i++)
{
_secretCode += _random.Next(0, 10).ToString();
}
SecretBox.Text = _secretCode;
StatusText.Text = $"Загадано {length} цифр";
InputBox.Text = "";
}
private void OnDifficultyChanged(object? sender, SelectionChangedEventArgs e)
{
GenerateCode();
}
private void OnCheckClick(object? sender, RoutedEventArgs e)
{
if (InputBox.Text == _secretCode)
{
StatusText.Text = "Угадал! Загадываю новое...";
GenerateCode();
}
else
{
StatusText.Text = "Не угадал, попробуй еще!";
}
}
}
}