102 lines
3.3 KiB
C#
102 lines
3.3 KiB
C#
|
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 ProjectCar
|
|||
|
{
|
|||
|
public partial class FormGasMachine : Form
|
|||
|
{
|
|||
|
private DrawningGasMachine? _drawningGasMachine;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// конструктор формы
|
|||
|
/// </summary>
|
|||
|
public FormGasMachine()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// метод прорисовки машины
|
|||
|
/// </summary>
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (_drawningGasMachine == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
Bitmap bmp = new(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_drawningGasMachine.DrawTransport(gr);
|
|||
|
pictureBoxGasMachine.Image = bmp;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// обработка нажатия кнопки "создать"
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
_drawningGasMachine = new DrawningGasMachine();
|
|||
|
_drawningGasMachine.Init(random.Next(100, 300), random.Next(1000, 3000),
|
|||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|||
|
_drawningGasMachine.SetPictureSize(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
|
|||
|
_drawningGasMachine.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|||
|
|
|||
|
Draw();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// перемещение объекта по форме
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_drawningGasMachine == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
bool result = false;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
result = _drawningGasMachine.MoveTransport(DirectionType.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
result = _drawningGasMachine.MoveTransport(DirectionType.Down);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
result = _drawningGasMachine.MoveTransport(DirectionType.Right);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
result = _drawningGasMachine.MoveTransport(DirectionType.Left);
|
|||
|
break;
|
|||
|
}
|
|||
|
if (result)
|
|||
|
{
|
|||
|
Draw();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|