2024-02-06 20:33:48 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Seaplane
|
|
|
|
|
{
|
|
|
|
|
public partial class FormSeaplane : Form
|
|
|
|
|
{
|
2024-02-11 12:40:40 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
2024-02-07 08:29:34 +04:00
|
|
|
|
private DrawingSeaplane? _drawningSeaplane;
|
2024-02-11 12:40:40 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// конструктор формы
|
|
|
|
|
/// </summary>
|
2024-02-06 20:33:48 +04:00
|
|
|
|
public FormSeaplane()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2024-02-11 12:40:40 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки транспорта
|
|
|
|
|
/// </summary>
|
2024-02-07 17:50:12 +04:00
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningSeaplane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningSeaplane.DrawTransport(gr);
|
|
|
|
|
pictureBoxSeaplane.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка кнопик Создать
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-02-07 08:20:07 +04:00
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
2024-02-07 08:09:56 +04:00
|
|
|
|
{
|
2024-02-07 08:20:07 +04:00
|
|
|
|
Random random = new();
|
2024-02-07 08:29:34 +04:00
|
|
|
|
_drawningSeaplane = new DrawingSeaplane();
|
|
|
|
|
_drawningSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255),
|
2024-02-07 08:20:07 +04:00
|
|
|
|
random.Next(0, 255), random.Next(0, 255)), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
2024-02-07 08:29:34 +04:00
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
|
|
|
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
2024-02-11 12:22:28 +04:00
|
|
|
|
_drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2024-02-07 08:29:34 +04:00
|
|
|
|
|
2024-02-07 17:50:12 +04:00
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перемещение объекта по форме
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningSeaplane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
result = _drawningSeaplane.MoveTransport(DirectionType.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
result = _drawningSeaplane.MoveTransport(DirectionType.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
result = _drawningSeaplane.MoveTransport(DirectionType.Right);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
result = _drawningSeaplane.MoveTransport(DirectionType.Left);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
2024-02-07 08:09:56 +04:00
|
|
|
|
}
|
2024-02-06 20:33:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|