55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using ElectricLocomotive;
|
|
|
|
namespace ElectricLocomotive
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private DrawingLocomotiv? _drawingLocomotiv;
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
if (_drawingLocomotiv == null) return;
|
|
Bitmap bmp = new(locoBox.Width, locoBox.Height);
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
_drawingLocomotiv.DrawLoco(g);
|
|
locoBox.Image = bmp;
|
|
}
|
|
private void PaintObjectButton_click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawingLocomotiv = new DrawingLocomotiv();
|
|
_drawingLocomotiv.Init(random.Next(100, 300),random.Next(1000,3000),locoBox.Width,locoBox.Height);
|
|
_drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void MoveButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingLocomotiv == null) return;
|
|
|
|
Control button = sender as Control;
|
|
|
|
string name = button.Name;
|
|
switch (name)
|
|
{
|
|
case "moveUpButton":
|
|
_drawingLocomotiv.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "moveDownButton":
|
|
_drawingLocomotiv.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "moveLeftButton":
|
|
_drawingLocomotiv.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "moveRightButton":
|
|
_drawingLocomotiv.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
}
|
|
} |