83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
namespace Hydroplane
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
/// <summary>
|
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
/// </summary>
|
|
private DrawningHydroplane? _drawningSportCar;
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningSportCar == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxHydroplane.Width,
|
|
pictureBoxHydroplane.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningSportCar.DrawTransport(gr);
|
|
pictureBoxHydroplane.Image = bmp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningSportCar = new DrawningHydroplane();
|
|
_drawningSportCar.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)),
|
|
pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
|
_drawningSportCar.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 (_drawningSportCar == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningSportCar.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningSportCar.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningSportCar.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningSportCar.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
}
|
|
} |