using System;
using System.Windows.Forms;

namespace GuessNumber
{
    public class MainForm : Form
    {
        private readonly TextBox txtGuess;
        private readonly Button btnGuess;
        private readonly Label lblResult;

        private readonly Random random = new();
        private int secret;

        public MainForm()
        {
            Text = "Hádaj číslo";
            Width = 350;
            Height = 180;
            StartPosition = FormStartPosition.CenterScreen;

            Label lbl = new()
            {
                Text = "Zadaj číslo 1-100:",
                Left = 20,
                Top = 20,
                Width = 120
            };

            txtGuess = new TextBox()
            {
                Left = 150,
                Top = 18,
                Width = 100
            };

            btnGuess = new Button()
            {
                Text = "Hádať",
                Left = 20,
                Top = 55,
                Width = 100
            };

            lblResult = new Label()
            {
                Left = 20,
                Top = 95,
                Width = 280,
                Height = 30
            };

            btnGuess.Click += BtnGuess_Click;

            Controls.Add(lbl);
            Controls.Add(txtGuess);
            Controls.Add(btnGuess);
            Controls.Add(lblResult);

            secret = random.Next(1, 101);
        }

        private void BtnGuess_Click(object? sender, EventArgs e)
        {
            if (!int.TryParse(txtGuess.Text, out int guess))
            {
                lblResult.Text = "Zadaj platné číslo.";
                return;
            }

            if (guess < secret)
            {
                lblResult.Text = "Príliš malé.";
            }
            else if (guess > secret)
            {
                lblResult.Text = "Príliš veľké.";
            }
            else
            {
                lblResult.Text = "Správne! Generujem nové číslo.";
                secret = random.Next(1, 101);
            }
        }
    }
}
