80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
|
using System.Windows.Forms;
|
|||
|
using WarmlyLocomotive;
|
|||
|
using static WarmlyLocomotive.EntityWarmlyLocomotive;
|
|||
|
|
|||
|
namespace WarmlyLocomotive
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|||
|
/// </summary>
|
|||
|
public partial class WarmlyLocomotiveForm : 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 DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
|||
|
public WarmlyLocomotiveForm()
|
|||
|
{
|
|||
|
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 (_drawningWarmlyLocomotive == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Bitmap bmp = new(pictureBox1.Width,
|
|||
|
pictureBox1.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_drawningWarmlyLocomotive.DrawTransport(gr);
|
|||
|
pictureBox1.Image = bmp;
|
|||
|
}
|
|||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive();
|
|||
|
_drawningWarmlyLocomotive.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)), Convert.ToBoolean(random.Next(0, 2)),
|
|||
|
pictureBox1.Width, pictureBox1.Height);
|
|||
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100),
|
|||
|
random.Next(10, 100));
|
|||
|
Draw();
|
|||
|
}
|
|||
|
private void buttonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
if (_drawningWarmlyLocomotive == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Down);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Left);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Right);
|
|||
|
break;
|
|||
|
}
|
|||
|
Draw();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|