Лабораторная работа №1
This commit is contained in:
parent
b05d496408
commit
a1e7d192d8
@ -7,31 +7,38 @@ public class DrawningSeaplane
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntitySeaplane? EntitySportCar { get; private set; }
|
public EntitySeaplane? EntitySeaplane { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth;
|
private int? _pictureWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна
|
/// Высота окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight;
|
private int? _pictureHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки автомобиля
|
/// Левая координата прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
private int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки автомобиля
|
/// Верхняя кооридната прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
private int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки автомобиля
|
/// Ширина прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningCarWidth = 110;
|
private readonly int _drawningSeaplaneWidth = 130;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки автомобиля
|
/// Высота прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningCarHeight = 60;
|
private readonly int _drawningSeaplaneHeight = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -39,19 +46,18 @@ public class DrawningSeaplane
|
|||||||
/// <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 additionalColor, bool floats, bool boat)
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
|
||||||
{
|
{
|
||||||
EntitySportCar = new EntitySeaplane();
|
EntitySeaplane = new EntitySeaplane();
|
||||||
EntitySportCar.Init(speed, weight, bodyColor, additionalColor,
|
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, boat);
|
||||||
bodyKit, wing, sportLine);
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -66,6 +72,7 @@ public class DrawningSeaplane
|
|||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -77,49 +84,55 @@ public class DrawningSeaplane
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO если при установке объекта в эти координаты, он будет
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||||
"выходить" за границы формы
|
|
||||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||||
12
|
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
/// <returns>true - перемещене выполнено, false - перемещение
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
невозможно</returns>
|
public bool MoveTransport(DirectionType direction)
|
||||||
public bool MoveTransport(DirectionType direction)
|
|
||||||
{
|
{
|
||||||
if (EntitySportCar == null || !_startPosX.HasValue ||
|
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
!_startPosY.HasValue)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntitySportCar.Step > 0)
|
if (_startPosX.Value - EntitySeaplane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntitySportCar.Step;
|
_startPosX -= (int)EntitySeaplane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntitySportCar.Step > 0)
|
if (_startPosY.Value - EntitySeaplane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntitySportCar.Step;
|
_startPosY -= (int)EntitySeaplane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
//TODO прописать логику сдвига в право
|
if (_startPosX.Value + _drawningSeaplaneWidth + EntitySeaplane.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntitySeaplane.Step;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
//TODO прописать логику сдвига в вниз
|
|
||||||
|
if (_startPosY.Value + _drawningSeaplaneHeight + EntitySeaplane.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntitySeaplane.Step;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -131,138 +144,71 @@ public bool MoveTransport(DirectionType direction)
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntitySportCar == null || !_startPosX.HasValue ||
|
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
!_startPosY.HasValue)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black, 2);
|
||||||
Brush additionalBrush = new
|
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
|
||||||
SolidBrush(EntitySportCar.AdditionalColor);
|
|
||||||
// обвесы
|
|
||||||
13
|
|
||||||
if (EntitySportCar.BodyKit)
|
//Отрисовка основных частей самолёта
|
||||||
|
Brush br = new SolidBrush(EntitySeaplane.BodyColor);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
||||||
|
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
||||||
|
Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
||||||
|
Point point2 = new Point(_startPosX.Value + 40, _startPosY.Value + 20);
|
||||||
|
Point point3 = new Point(_startPosX.Value + 100, _startPosY.Value + 20);
|
||||||
|
Point point4 = new Point(_startPosX.Value + 130, _startPosY.Value + 30);
|
||||||
|
Point point5 = new Point(_startPosX.Value + 100, _startPosY.Value + 40);
|
||||||
|
Point point6 = new Point(_startPosX.Value + 10, _startPosY.Value + 40);
|
||||||
|
Point[] points = { point1, point2, point3, point4, point5, point6 };
|
||||||
|
g.FillPolygon(br, points);
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 40, _startPosY.Value + 20);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 40);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 30);
|
||||||
|
|
||||||
|
//Крылья
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
||||||
|
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 25, 40, 10);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 30, _startPosY.Value + 25, 40, 10);
|
||||||
|
|
||||||
|
|
||||||
|
//Шасси
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 38, _startPosY.Value + 40, 4, 5);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 88, _startPosY.Value + 40, 4, 5);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
|
||||||
|
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 38, _startPosY.Value + 40, 4, 5);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 88, _startPosY.Value + 40, 4, 5);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
|
||||||
|
|
||||||
|
|
||||||
|
//Надувнвя лодка
|
||||||
|
if (EntitySeaplane.Boat)
|
||||||
{
|
{
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value,
|
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
||||||
20, 20);
|
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value +
|
|
||||||
40, 20, 20);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value +
|
|
||||||
10, 20, 40);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value,
|
|
||||||
15, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value +
|
|
||||||
45, 15, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90,
|
|
||||||
_startPosY.Value, 20, 20);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90,
|
|
||||||
_startPosY.Value + 40, 20, 20);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
|
||||||
_startPosY.Value + 10, 20, 40);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
|
||||||
_startPosY.Value + 1, 15, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
|
||||||
_startPosY.Value + 45, 15, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20,
|
|
||||||
20);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40,
|
|
||||||
20, 20);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10,
|
|
||||||
20, 40);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value,
|
|
||||||
14, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value +
|
|
||||||
45, 14, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value,
|
|
||||||
_startPosY.Value, 20, 20);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value,
|
|
||||||
_startPosY.Value + 40, 20, 20);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 1,
|
|
||||||
_startPosY.Value + 10, 25, 40);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5,
|
|
||||||
_startPosY.Value + 1, 15, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5,
|
|
||||||
_startPosY.Value + 45, 15, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value,
|
|
||||||
39, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value +
|
|
||||||
45, 39, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
|
||||||
_startPosY.Value + 1, 40, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
|
||||||
_startPosY.Value + 45, 40, 15);
|
|
||||||
}
|
}
|
||||||
//границы автомобиля
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20,
|
//Поплавки
|
||||||
20);
|
if (EntitySeaplane.Floats)
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20,
|
|
||||||
20);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20,
|
|
||||||
20);
|
|
||||||
14
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20,
|
|
||||||
20);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10,
|
|
||||||
30);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15,
|
|
||||||
10, 30);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70,
|
|
||||||
52);
|
|
||||||
//задние фары
|
|
||||||
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,
|
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||||
_startPosY.Value + 23, 25, 15);
|
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||||
_startPosY.Value + 23, 35, 15);
|
g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10,
|
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||||
_startPosY.Value + 23, 20, 15);
|
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||||
}
|
|
||||||
// крыло
|
|
||||||
if (EntitySportCar.Wing)
|
|
||||||
15
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value,
|
|
||||||
_startPosY.Value + 5, 10, 50);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5,
|
|
||||||
10, 50);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
private DrawningSeaplane? _drawningSeaplane;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор формы
|
||||||
|
/// </summary>
|
||||||
public FormSeaplane()
|
public FormSeaplane()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
/// Метод прорисовки машины
|
||||||
|
/// </summary>
|
||||||
|
private void Draw()
|
||||||
{
|
{
|
||||||
Random random = new();
|
if (_drawningSeaplane == null)
|
||||||
_drawningSeaplane = new DrawningSeaplane();
|
{
|
||||||
_drawningSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000),
|
return;
|
||||||
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)));
|
|
||||||
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
|
||||||
_drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningSeaplane.DrawTransport(gr);
|
_drawningSeaplane.DrawTransport(gr);
|
||||||
pictureBoxSeaplane.Image = bmp;
|
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)
|
||||||
|
{
|
||||||
|
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 "buttonLeft":
|
||||||
|
result =
|
||||||
|
_drawningSeaplane.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
result =
|
||||||
|
_drawningSeaplane.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user