2022-11-13 20:39:23 +04:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsApp1
|
|
|
|
|
{
|
|
|
|
|
public partial class FormTractor : Form
|
|
|
|
|
{
|
|
|
|
|
private TractorDraw _Tractor;
|
|
|
|
|
|
2022-11-28 22:39:41 +04:00
|
|
|
|
public TractorDraw SelectedTractor { get; private set; }
|
2022-11-13 20:39:23 +04:00
|
|
|
|
public FormTractor()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new Bitmap(pictureBoxTractor.Width, pictureBoxTractor.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_Tractor?.DrawEntity(gr);
|
|
|
|
|
pictureBoxTractor.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 21:25:33 +04:00
|
|
|
|
private void SetData()
|
2022-11-13 20:39:23 +04:00
|
|
|
|
{
|
2022-11-14 21:25:33 +04:00
|
|
|
|
Random random = new();
|
2022-11-13 20:39:23 +04:00
|
|
|
|
_Tractor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTractor.Width, pictureBoxTractor.Height);
|
|
|
|
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_Tractor.Tractor.Speed}";
|
|
|
|
|
toolStripStatusLabelWeight.Text = $"Вес: {_Tractor.Tractor.Weight}";
|
2022-11-14 21:25:33 +04:00
|
|
|
|
toolStripStatusLabelBodyColor.Text = $"Цвет кузова: {_Tractor.Tractor.BodyColor.Name}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Random random = new Random();
|
2022-11-28 22:39:41 +04:00
|
|
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
|
ColorDialog dialog = new();
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
color = dialog.Color;
|
|
|
|
|
}
|
|
|
|
|
_Tractor = new TractorDraw(random.Next(100, 300), random.Next(1000, 2000), color); SetData();
|
2022-11-13 20:39:23 +04:00
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
_Tractor?.MoveTransport(Direction.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
_Tractor?.MoveTransport(Direction.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
_Tractor?.MoveTransport(Direction.Left);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
_Tractor?.MoveTransport(Direction.Right);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void pictureBoxTractor_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_Tractor?.ChangeBorders(pictureBoxTractor.Width, pictureBoxTractor.Height);
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
2022-11-14 21:25:33 +04:00
|
|
|
|
|
|
|
|
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Random random = new Random();
|
2022-11-28 22:39:41 +04:00
|
|
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
|
ColorDialog dialog = new();
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
color = dialog.Color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
|
ColorDialog dialogDop = new();
|
|
|
|
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
dopColor = dialogDop.Color;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 23:38:47 +04:00
|
|
|
|
_Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor, true, true);
|
2022-11-28 22:39:41 +04:00
|
|
|
|
|
2022-11-14 21:25:33 +04:00
|
|
|
|
SetData();
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
2022-11-28 22:39:41 +04:00
|
|
|
|
|
|
|
|
|
private void buttonSelectedTractor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SelectedTractor = _Tractor;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
2022-11-13 20:39:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|