PIbd-21_Putintsev_D.M._Road.../RoadTrain/FormRoadTrain.cs

92 lines
2.9 KiB
C#
Raw Normal View History

namespace RoadTrain
{
public partial class FormRoadTrain : Form
{
/// <summary>
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private DrawningRoadTrain? _drawningRoadTrain;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public FormRoadTrain()
{
InitializeComponent();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private void Draw()
{
if (_drawningRoadTrain == null)
{
return;
}
Bitmap bmp = new(pictureBoxRoadTrain.Width,
pictureBoxRoadTrain.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningRoadTrain.DrawTransport(gr);
pictureBoxRoadTrain.Image = bmp;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningRoadTrain == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningRoadTrain.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningRoadTrain.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningRoadTrain.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningRoadTrain.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningRoadTrain = new DrawningRoadTrain();
EntityRoadTrain entityRoadTrain = new EntityRoadTrain();
entityRoadTrain.Init(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(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)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
_drawningRoadTrain.Init(entityRoadTrain, pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
_drawningRoadTrain.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
}
}