ISEbd-21_Tomasheva_RoadTrai.../RoadTrain/RoadTrain/FormRoadTrain.cs
2022-12-07 12:13:11 +04:00

131 lines
4.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace RoadTrain
{
public partial class FormRoadTrain : Form
{
private DrawningRoadTrain _RoadTrain;
public DrawningRoadTrain SelectedRoadTrain { get; private set; }
public FormRoadTrain()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки грузовика
/// </summary>
private void Draw()
{
Bitmap bmp = new(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
Graphics gr = Graphics.FromImage(bmp);
_RoadTrain?.DrawTransport(gr);
pictureBoxRoadTrain.Image = bmp;
}
/// <summary>
/// Метод установки данных
/// </summary>
private void SetData()
{
Random rnd = new();
_RoadTrain.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_RoadTrain.RoadTrain.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_RoadTrain.RoadTrain.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_RoadTrain.RoadTrain.BodyColor.Name}";
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_RoadTrain = new DrawningRoadTrain(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_RoadTrain?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_RoadTrain?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_RoadTrain?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_RoadTrain?.MoveTransport(Direction.Right);
break;
}
Draw();
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBoxCar_Resize(object sender, EventArgs e)
{
_RoadTrain?.ChangeBorders(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_RoadTrain = new DrawningSweeperRoadTrain(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Выбрать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectRoadTrain_Click(object sender, EventArgs e)
{
SelectedRoadTrain = _RoadTrain;
DialogResult = DialogResult.OK;
}
}
}