74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
|
namespace Liner
|
|||
|
{
|
|||
|
public partial class MainScreen : 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 DrawingLiner? _drawingLiner;
|
|||
|
private Bitmap bmp;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public MainScreen()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (_drawingLiner == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
gr.Clear(Color.White);
|
|||
|
_drawingLiner.DrawTransport(gr);
|
|||
|
pictureBoxLiner.Image = bmp;
|
|||
|
gr.Dispose();
|
|||
|
}
|
|||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
_drawingLiner = new DrawingLiner();
|
|||
|
_drawingLiner.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)),
|
|||
|
pictureBoxLiner.Width, pictureBoxLiner.Height);
|
|||
|
_drawingLiner.SetPosition(random.Next(10, 100),
|
|||
|
random.Next(10, 100));
|
|||
|
Draw();
|
|||
|
}
|
|||
|
|
|||
|
private void buttonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_drawingLiner == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
_drawingLiner.MoveTransport(DirectionType.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
_drawingLiner.MoveTransport(DirectionType.Down);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
_drawingLiner.MoveTransport(DirectionType.Left);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
_drawingLiner.MoveTransport(DirectionType.Right);
|
|||
|
break;
|
|||
|
}
|
|||
|
Draw();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|