Лабораторная работа №1

This commit is contained in:
ShuryginDima 2024-02-26 22:32:27 +03:00
parent b05d496408
commit a1e7d192d8
4 changed files with 327 additions and 336 deletions

View File

@ -1,268 +1,214 @@
namespace ProjectSeaplane; namespace ProjectSeaplane;
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary> /// </summary>
public class DrawningSeaplane public class DrawningSeaplane
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntitySeaplane? EntitySportCar { get; private set; } public EntitySeaplane? EntitySeaplane { get; private set; }
/// <summary>
/// Ширина окна /// <summary>
/// </summary> /// Ширина окна
private int? _pictureWidth; /// </summary>
/// <summary> private int? _pictureWidth;
/// Высота окна
/// </summary> /// <summary>
private int? _pictureHeight; /// Высота окна
/// <summary> /// </summary>
/// Левая координата прорисовки автомобиля private int? _pictureHeight;
/// </summary>
private int? _startPosX; /// <summary>
/// <summary> /// Левая координата прорисовки гидросамолёта
/// Верхняя кооридната прорисовки автомобиля /// </summary>
/// </summary> private int? _startPosX;
private int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки автомобиля /// Верхняя кооридната прорисовки гидросамолёта
/// </summary> /// </summary>
private readonly int _drawningCarWidth = 110; private int? _startPosY;
/// <summary>
/// Высота прорисовки автомобиля /// <summary>
/// </summary> /// Ширина прорисовки гидросамолёта
private readonly int _drawningCarHeight = 60; /// </summary>
/// <summary> private readonly int _drawningSeaplaneWidth = 130;
/// Инициализация свойств
/// </summary> /// <summary>
/// <param name="speed">Скорость</param> /// Высота прорисовки гидросамолёта
/// <param name="weight">Вес</param> /// </summary>
/// <param name="bodyColor">Основной цвет</param> private readonly int _drawningSeaplaneHeight = 50;
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <summary>
/// <param name="wing">Признак наличия антикрыла</param> /// Инициализация свойств
/// <param name="sportLine">Признак наличия гоночной полосы</param> /// </summary>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) /// <param name="speed">Скорость</param>
{ /// <param name="weight">Вес</param>
EntitySportCar = new EntitySeaplane(); /// <param name="bodyColor">Основной цвет</param>
EntitySportCar.Init(speed, weight, bodyColor, additionalColor, /// <param name="additionalColor">Дополнительный цвет</param>
bodyKit, wing, sportLine); /// <param name="floats">Признак наличия поплавков</param>
_pictureWidth = null; /// <param name="boat">Признак наличия лодки</param>
_pictureHeight = null; public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat)
_startPosX = null; {
_startPosY = null; EntitySeaplane = new EntitySeaplane();
} EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, boat);
/// <summary> _pictureWidth = null;
/// Установка границ поля _pictureHeight = null;
/// </summary> _startPosX = null;
/// <param name="width">Ширина поля</param> _startPosY = null;
/// <param name="height">Высота поля</param> }
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) /// <summary>
{ /// Установка границ поля
// TODO проверка, что объект "влезает" в размеры поля /// </summary>
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена /// <param name="width">Ширина поля</param>
_pictureWidth = width; /// <param name="height">Высота поля</param>
_pictureHeight = height; /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
return true; public bool SetPictureSize(int width, int height)
} {
/// <summary> // TODO проверка, что объект "влезает" в размеры поля
/// Установка позиции // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
/// </summary> _pictureWidth = width;
/// <param name="x">Координата X</param> _pictureHeight = height;
/// <param name="y">Координата Y</param> return true;
public void SetPosition(int x, int y) }
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) /// <summary>
{ /// Установка позиции
return; /// </summary>
} /// <param name="x">Координата X</param>
// TODO если при установке объекта в эти координаты, он будет /// <param name="y">Координата Y</param>
"выходить" за границы формы public void SetPosition(int x, int y)
// то надо изменить координаты, чтобы он оставался в этих границах {
12 if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
_startPosX = x; {
_startPosY = y; return;
} }
/// <summary> // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
/// Изменение направления перемещения // то надо изменить координаты, чтобы он оставался в этих границах
/// </summary>
/// <param name="direction">Направление</param> _startPosX = x;
/// <returns>true - перемещене выполнено, false - перемещение _startPosY = y;
невозможно</returns> }
public bool MoveTransport(DirectionType direction)
{ /// <summary>
if (EntitySportCar == null || !_startPosX.HasValue || /// Изменение направления перемещения
!_startPosY.HasValue) /// </summary>
{ /// <param name="direction">Направление</param>
return false; /// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
} public bool MoveTransport(DirectionType direction)
switch (direction) {
{ if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
//влево {
case DirectionType.Left: return false;
if (_startPosX.Value - EntitySportCar.Step > 0) }
{
_startPosX -= (int)EntitySportCar.Step; switch (direction)
} {
return true; //влево
//вверх case DirectionType.Left:
case DirectionType.Up: if (_startPosX.Value - EntitySeaplane.Step > 0)
if (_startPosY.Value - EntitySportCar.Step > 0) {
{ _startPosX -= (int)EntitySeaplane.Step;
_startPosY -= (int)EntitySportCar.Step; }
} return true;
return true; //вверх
// вправо case DirectionType.Up:
case DirectionType.Right: if (_startPosY.Value - EntitySeaplane.Step > 0)
//TODO прописать логику сдвига в право {
return true; _startPosY -= (int)EntitySeaplane.Step;
//вниз }
case DirectionType.Down: return true;
//TODO прописать логику сдвига в вниз // вправо
return true; case DirectionType.Right:
default: if (_startPosX.Value + _drawningSeaplaneWidth + EntitySeaplane.Step < _pictureWidth)
return false; {
} _startPosX += (int)EntitySeaplane.Step;
} }
/// <summary> return true;
/// Прорисовка объекта //вниз
/// </summary> case DirectionType.Down:
/// <param name="g"></param>
public void DrawTransport(Graphics g) if (_startPosY.Value + _drawningSeaplaneHeight + EntitySeaplane.Step < _pictureHeight)
{ {
if (EntitySportCar == null || !_startPosX.HasValue || _startPosY += (int)EntitySeaplane.Step;
!_startPosY.HasValue) }
{ return true;
return; default:
} return false;
Pen pen = new(Color.Black); }
Brush additionalBrush = new }
SolidBrush(EntitySportCar.AdditionalColor); /// <summary>
// обвесы /// Прорисовка объекта
13 /// </summary>
if (EntitySportCar.BodyKit) /// <param name="g"></param>
{ public void DrawTransport(Graphics g)
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, {
20, 20); if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + {
40, 20, 20); return;
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + }
10, 20, 40); Pen pen = new(Color.Black, 2);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
15, 15);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value +
45, 15, 15);
g.FillEllipse(additionalBrush, _startPosX.Value + 90, //Отрисовка основных частей самолёта
_startPosY.Value, 20, 20); Brush br = new SolidBrush(EntitySeaplane.BodyColor);
g.FillEllipse(additionalBrush, _startPosX.Value + 90, g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 20, 20);
_startPosY.Value + 40, 20, 20); g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 20, 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 90, Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
_startPosY.Value + 10, 20, 40); Point point2 = new Point(_startPosX.Value + 40, _startPosY.Value + 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 90, Point point3 = new Point(_startPosX.Value + 100, _startPosY.Value + 20);
_startPosY.Value + 1, 15, 15); Point point4 = new Point(_startPosX.Value + 130, _startPosY.Value + 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 90, Point point5 = new Point(_startPosX.Value + 100, _startPosY.Value + 40);
_startPosY.Value + 45, 15, 15); Point point6 = new Point(_startPosX.Value + 10, _startPosY.Value + 40);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, Point[] points = { point1, point2, point3, point4, point5, point6 };
20); g.FillPolygon(br, points);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, g.DrawPolygon(pen, points);
20, 20); g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 40, _startPosY.Value + 20);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 40);
20, 40); g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 30);
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value,
14, 15); //Крылья
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 25, 5);
45, 14, 15); g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 25, 5);
g.FillEllipse(additionalBrush, _startPosX.Value, g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 25, 40, 10);
_startPosY.Value, 20, 20); g.FillEllipse(br, _startPosX.Value + 30, _startPosY.Value + 25, 40, 10);
g.FillEllipse(additionalBrush, _startPosX.Value,
_startPosY.Value + 40, 20, 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 1, //Шасси
_startPosY.Value + 10, 25, 40); g.DrawRectangle(pen, _startPosX.Value + 38, _startPosY.Value + 40, 4, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 5, g.DrawRectangle(pen, _startPosX.Value + 88, _startPosY.Value + 40, 4, 5);
_startPosY.Value + 1, 15, 15); g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 5, g.DrawEllipse(pen, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
_startPosY.Value + 45, 15, 15); g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value,
39, 15); g.FillRectangle(br, _startPosX.Value + 38, _startPosY.Value + 40, 4, 5);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + g.FillRectangle(br, _startPosX.Value + 88, _startPosY.Value + 40, 4, 5);
45, 39, 15); g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 35, g.FillEllipse(br, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
_startPosY.Value + 1, 40, 15); g.FillEllipse(br, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
_startPosY.Value + 45, 40, 15);
} //Надувнвя лодка
//границы автомобиля if (EntitySeaplane.Boat)
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, {
20); g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
20);
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, }
20);
14 //Поплавки
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, if (EntitySeaplane.Floats)
20); {
g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
30); g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
10, 30); g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
52); g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
//задние фары
Brush brRed = new SolidBrush(Color.Red); }
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, }
20); }
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35,
20, 20);
//передние фары
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5,
20, 20);
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35,
20, 20);
//кузов
Brush br = new SolidBrush(EntitySportCar.BodyColor);
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10,
30);
g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10,
30);
g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70,
50);
//стекла
Brush brBlue = new SolidBrush(Color.LightBlue);
g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10,
5, 40);
g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10,
5, 40);
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8,
35, 2);
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51,
35, 2);
//выделяем рамкой крышу
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10,
35, 40);
g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15,
25, 30);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15,
15, 30);
// спортивная линия
if (EntitySportCar.SportLine)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 75,
_startPosY.Value + 23, 25, 15);
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
_startPosY.Value + 23, 35, 15);
g.FillRectangle(additionalBrush, _startPosX.Value + 10,
_startPosY.Value + 23, 20, 15);
}
// крыло
if (EntitySportCar.Wing)
15
{
g.FillRectangle(additionalBrush, _startPosX.Value,
_startPosY.Value + 5, 10, 50);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5,
10, 50);
}
}
}

View File

@ -1,6 +1,6 @@
namespace ProjectSeaplane; namespace ProjectSeaplane;
/// <summary> /// <summary>
/// Класс-сущность "Спортивный автомобиль" /// Класс-сущность "Гидросамолёт"
/// </summary> /// </summary>
public class EntitySeaplane public class EntitySeaplane
{ {
@ -24,45 +24,39 @@ public class EntitySeaplane
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия антикрыла /// Признак (опция) наличия поплавков
/// </summary> /// </summary>
public bool Wing { get; private set; } public bool Floats { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) наличия гоночной полосы /// Признак (опция) наличия лодки
/// </summary> /// </summary>
public bool SportLine { get; private set; } public bool Boat { get; private set; }
/// <summary> /// <summary>
/// Шаг перемещения автомобиля /// Шаг перемещения гидросамолёта
/// </summary> /// </summary>
public double Step => Speed * 100 / Weight; public double Step => Speed * 100 / Weight;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля /// Инициализация полей объекта-класса гидросамолёта
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param> /// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="floats">Признак наличия поплавков</param>
/// <param name="wing">Признак наличия антикрыла</param> /// <param name="boat">Признак наличия лодки</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool wing, bool sportLine) additionalColor, bool floats, bool boat)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
BodyKit = bodyKit; Floats = floats;
Wing = wing; Boat = boat;
SportLine = sportLine;
} }
} }

View File

@ -29,7 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxSeaplane = new PictureBox(); pictureBoxSeaplane = new PictureBox();
buttonCreate = new Button(); buttonCreateSeaplane = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
@ -42,75 +42,79 @@
pictureBoxSeaplane.Dock = DockStyle.Fill; pictureBoxSeaplane.Dock = DockStyle.Fill;
pictureBoxSeaplane.Location = new Point(0, 0); pictureBoxSeaplane.Location = new Point(0, 0);
pictureBoxSeaplane.Name = "pictureBoxSeaplane"; pictureBoxSeaplane.Name = "pictureBoxSeaplane";
pictureBoxSeaplane.Size = new Size(850, 539); pictureBoxSeaplane.Size = new Size(900, 500);
pictureBoxSeaplane.TabIndex = 0; pictureBoxSeaplane.TabIndex = 0;
pictureBoxSeaplane.TabStop = false; pictureBoxSeaplane.TabStop = false;
// //
// buttonCreate // buttonCreateSeaplane
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 504); buttonCreateSeaplane.Location = new Point(12, 465);
buttonCreate.Name = "buttonCreate"; buttonCreateSeaplane.Name = "buttonCreateSeaplane";
buttonCreate.Size = new Size(75, 23); buttonCreateSeaplane.Size = new Size(75, 23);
buttonCreate.TabIndex = 1; buttonCreateSeaplane.TabIndex = 1;
buttonCreate.Text = "Создать"; buttonCreateSeaplane.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true; buttonCreateSeaplane.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click; buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
// //
// buttonLeft // buttonLeft
// //
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrow_left; buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(718, 490); buttonLeft.Location = new Point(768, 451);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35); buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true; buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
// //
// buttonUp // buttonUp
// //
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrow_up; buttonUp.BackgroundImage = Properties.Resources.arrow_up;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(758, 450); buttonUp.Location = new Point(808, 411);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35); buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3; buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true; buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
// //
// buttonDown // buttonDown
// //
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrow_down; buttonDown.BackgroundImage = Properties.Resources.arrow_down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(758, 490); buttonDown.Location = new Point(808, 451);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35); buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4; buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
// //
// buttonRight // buttonRight
// //
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrow_right; buttonRight.BackgroundImage = Properties.Resources.arrow_right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(799, 490); buttonRight.Location = new Point(849, 451);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35); buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5; buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
// //
// FormSeaplane // FormSeaplane
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(850, 539); ClientSize = new Size(900, 500);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreateSeaplane);
Controls.Add(pictureBoxSeaplane); Controls.Add(pictureBoxSeaplane);
Name = "FormSeaplane"; Name = "FormSeaplane";
Text = "Гидросамолёт"; Text = "Гидросамолёт";
@ -121,7 +125,7 @@
#endregion #endregion
private PictureBox pictureBoxSeaplane; private PictureBox pictureBoxSeaplane;
private Button buttonCreate; private Button buttonCreateSeaplane;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;

View File

@ -1,40 +1,87 @@
using System; namespace ProjectSeaplane;
using System.Collections.Generic; /// <summary>
using System.ComponentModel; /// Форма работы с объектом "Спортивный автомобиль"
using System.Data; /// </summary>
using System.Drawing; public partial class FormSeaplane : Form
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectSeaplane
{ {
public partial class FormSeaplane : Form /// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningSeaplane? _drawningSeaplane;
/// <summary>
/// Конструктор формы
/// </summary>
public FormSeaplane()
{ {
private DrawningSeaplane? _drawningSeaplane; InitializeComponent();
}
public FormSeaplane() /// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw()
{
if (_drawningSeaplane == null)
{ {
InitializeComponent(); return;
} }
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
private void ButtonCreate_Click(object sender, EventArgs e) Graphics gr = Graphics.FromImage(bmp);
_drawningSeaplane.DrawTransport(gr);
pictureBoxSeaplane.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateSeaplane_Click(object sender, EventArgs e)
{
Random random = new();
_drawningSeaplane = new DrawningSeaplane();
_drawningSeaplane.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)));
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
_drawningSeaplane.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 (_drawningSeaplane == null)
{ {
Random random = new(); return;
_drawningSeaplane = new DrawningSeaplane(); }
_drawningSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000), string name = ((Button)sender)?.Name ?? string.Empty;
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), bool result = false;
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), switch (name)
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); {
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); case "buttonUp":
_drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); result =
_drawningSeaplane.MoveTransport(DirectionType.Up);
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); break;
Graphics gr = Graphics.FromImage(bmp); case "buttonDown":
_drawningSeaplane.DrawTransport(gr); result =
pictureBoxSeaplane.Image = bmp; _drawningSeaplane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawningSeaplane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
_drawningSeaplane.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
} }
} }
} }