2024-12-14 14:49:42 +04:00
|
|
|
|
using laba3.Subprograms;
|
|
|
|
|
using System;
|
2024-12-14 13:32:15 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace ProgLab1.GUI
|
|
|
|
|
{
|
|
|
|
|
public partial class MathGameForm : Form
|
|
|
|
|
{
|
2024-12-14 14:49:42 +04:00
|
|
|
|
private Label error;
|
2024-12-14 13:32:15 +04:00
|
|
|
|
private Label formula;
|
2024-12-14 14:49:42 +04:00
|
|
|
|
private Label rules;
|
|
|
|
|
private TextBox textBoxA;
|
|
|
|
|
private TextBox textBoxB;
|
|
|
|
|
private Label labelA;
|
|
|
|
|
private Label labelB;
|
|
|
|
|
|
|
|
|
|
private double a=0;
|
|
|
|
|
private double b=0;
|
|
|
|
|
private GuessAnswerMath game;
|
|
|
|
|
private GuessForm guessForm;
|
|
|
|
|
public MathGameForm(Form onCloseForm)
|
2024-12-14 13:32:15 +04:00
|
|
|
|
{
|
2024-12-14 14:49:42 +04:00
|
|
|
|
guessForm = new GuessForm(onCloseForm);
|
|
|
|
|
game = new GuessAnswerMath();
|
2024-12-14 13:32:15 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.Text = "Угадайка";
|
|
|
|
|
|
|
|
|
|
formula = new Label();
|
|
|
|
|
formula.Text = "Math.Sin((Math.Pow(a, 3) + Math.Pow(b, 5)) / (2 * PI)) + Math.Pow(Math.Cos(a + b), (1.0 / 3.0))";
|
|
|
|
|
formula.AutoSize = true;
|
|
|
|
|
formula.Top = 50;
|
|
|
|
|
formula.Left = 50;
|
|
|
|
|
|
2024-12-14 14:49:42 +04:00
|
|
|
|
rules = new Label();
|
|
|
|
|
rules.Text = "Нужно ввести аргументы для функции, а затем попытаться отгадать её значение";
|
|
|
|
|
rules.AutoSize = true;
|
|
|
|
|
rules.Top = 100;
|
|
|
|
|
rules.Left = 50;
|
|
|
|
|
|
|
|
|
|
// Создание Label для "a"
|
|
|
|
|
labelA = new Label();
|
|
|
|
|
labelA.Text = "a:";
|
|
|
|
|
labelA.Top = 150;
|
|
|
|
|
labelA.Left = 20;
|
|
|
|
|
labelA.AutoSize = true;
|
|
|
|
|
|
|
|
|
|
// Создание TextBox для "a"
|
|
|
|
|
textBoxA = new TextBox();
|
|
|
|
|
textBoxA.Top = 150;
|
|
|
|
|
textBoxA.Left = 50;
|
|
|
|
|
textBoxA.Width = 300;
|
|
|
|
|
|
|
|
|
|
// Создание Label для "b"
|
|
|
|
|
labelB = new Label();
|
|
|
|
|
labelB.Text = "b:";
|
|
|
|
|
labelB.Top = 190;
|
|
|
|
|
labelB.Left = 20;
|
|
|
|
|
labelB.AutoSize = true;
|
|
|
|
|
|
|
|
|
|
// Создание TextBox для "b"
|
|
|
|
|
textBoxB = new TextBox();
|
|
|
|
|
textBoxB.Top = 190;
|
|
|
|
|
textBoxB.Left = 50;
|
|
|
|
|
textBoxB.Width = 300;
|
|
|
|
|
|
|
|
|
|
error = new Label();
|
|
|
|
|
error.Text = "";
|
|
|
|
|
error.AutoSize = true;
|
|
|
|
|
error.Top = 220;
|
|
|
|
|
error.Left = 50;
|
|
|
|
|
error.ForeColor = Color.Red;
|
|
|
|
|
|
2024-12-14 13:32:15 +04:00
|
|
|
|
this.Controls.Add(formula);
|
2024-12-14 14:49:42 +04:00
|
|
|
|
this.Controls.Add(rules);
|
|
|
|
|
this.Controls.Add(labelA);
|
|
|
|
|
this.Controls.Add(textBoxA);
|
|
|
|
|
this.Controls.Add(labelB);
|
|
|
|
|
this.Controls.Add(textBoxB);
|
|
|
|
|
this.Controls.Add(error);
|
|
|
|
|
|
|
|
|
|
Button confirmButton = new Button
|
|
|
|
|
{
|
|
|
|
|
Text = "Подтвердить",
|
|
|
|
|
Width = 100,
|
|
|
|
|
Height = 30,
|
|
|
|
|
Top = 165,
|
|
|
|
|
Left = 400
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
confirmButton.Click += ConfirmButton_Click;
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(confirmButton);
|
|
|
|
|
|
|
|
|
|
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => { e.Cancel = true; this.Hide(); onCloseForm.Show(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateInput(TextBox textBox)
|
|
|
|
|
{
|
|
|
|
|
if (double.TryParse(textBox.Text, out _))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfirmButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Проверяем значения в полях
|
|
|
|
|
bool isAValid = ValidateInput(textBoxA);
|
|
|
|
|
bool isBValid = ValidateInput(textBoxB);
|
|
|
|
|
|
|
|
|
|
if (isAValid && isBValid)
|
|
|
|
|
{
|
|
|
|
|
// Если оба значения корректные, выводим сумму в
|
|
|
|
|
textBoxA.BackColor = SystemColors.Window;
|
|
|
|
|
textBoxB.BackColor = SystemColors.Window;
|
|
|
|
|
a = double.Parse(textBoxA.Text);
|
|
|
|
|
b = double.Parse(textBoxB.Text);
|
|
|
|
|
|
|
|
|
|
game.setArgs(a, b);
|
|
|
|
|
|
|
|
|
|
bool funcValid = game.CheckArgs();
|
2024-12-22 11:40:58 +04:00
|
|
|
|
|
2024-12-14 14:49:42 +04:00
|
|
|
|
if (!funcValid)
|
|
|
|
|
{
|
|
|
|
|
error.Text = "Функция не определена при этих аргументах";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
error.Text = "";
|
2024-12-22 11:40:58 +04:00
|
|
|
|
game.ComputeResult();
|
2024-12-14 14:49:42 +04:00
|
|
|
|
guessForm.SetAnswer(game.GetResult());
|
|
|
|
|
this.Hide();
|
|
|
|
|
guessForm.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-22 11:40:58 +04:00
|
|
|
|
else
|
2024-12-14 14:49:42 +04:00
|
|
|
|
{
|
|
|
|
|
// Если есть ошибка, подсвечиваем поля
|
|
|
|
|
if (!isAValid) textBoxA.BackColor = Color.Red;
|
|
|
|
|
if (!isBValid) textBoxB.BackColor = Color.Red;
|
|
|
|
|
error.Text = "Аргументы должны быть double";
|
|
|
|
|
}
|
2024-12-14 13:32:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|