Лабораторная работа №1
This commit is contained in:
parent
b05d496408
commit
a1e7d192d8
@ -1,268 +1,214 @@
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningSeaplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySeaplane? EntitySportCar { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningCarWidth = 110;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningCarHeight = 60;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
{
|
||||
EntitySportCar = new EntitySeaplane();
|
||||
EntitySportCar.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyKit, wing, sportLine);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет
|
||||
"выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
12
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение
|
||||
невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySportCar == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySportCar == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntitySportCar.AdditionalColor);
|
||||
// обвесы
|
||||
13
|
||||
if (EntitySportCar.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value,
|
||||
20, 20);
|
||||
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);
|
||||
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,
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningSeaplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySeaplane? EntitySeaplane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки гидросамолёта
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки гидросамолёта
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки гидросамолёта
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneWidth = 130;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки гидросамолёта
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="floats">Признак наличия поплавков</param>
|
||||
/// <param name="boat">Признак наличия лодки</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat)
|
||||
{
|
||||
EntitySeaplane = new EntitySeaplane();
|
||||
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, boat);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySeaplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySeaplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningSeaplaneWidth + EntitySeaplane.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
|
||||
if (_startPosY.Value + _drawningSeaplaneHeight + EntitySeaplane.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntitySeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
//Отрисовка основных частей самолёта
|
||||
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 + 50, _startPosY.Value + 15, 30, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
||||
|
||||
}
|
||||
|
||||
//Поплавки
|
||||
if (EntitySeaplane.Floats)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// Класс-сущность "Гидросамолёт"
|
||||
/// </summary>
|
||||
public class EntitySeaplane
|
||||
{
|
||||
@ -24,45 +24,39 @@ public class EntitySeaplane
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// Признак (опция) наличия поплавков
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
public bool Floats { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// Признак (опция) наличия лодки
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Boat { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// Шаг перемещения гидросамолёта
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// Инициализация полей объекта-класса гидросамолёта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
/// <param name="floats">Признак наличия поплавков</param>
|
||||
/// <param name="boat">Признак наличия лодки</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool floats, bool boat)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
Floats = floats;
|
||||
Boat = boat;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxSeaplane = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateSeaplane = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
@ -42,75 +42,79 @@
|
||||
pictureBoxSeaplane.Dock = DockStyle.Fill;
|
||||
pictureBoxSeaplane.Location = new Point(0, 0);
|
||||
pictureBoxSeaplane.Name = "pictureBoxSeaplane";
|
||||
pictureBoxSeaplane.Size = new Size(850, 539);
|
||||
pictureBoxSeaplane.Size = new Size(900, 500);
|
||||
pictureBoxSeaplane.TabIndex = 0;
|
||||
pictureBoxSeaplane.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateSeaplane
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 504);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSeaplane.Location = new Point(12, 465);
|
||||
buttonCreateSeaplane.Name = "buttonCreateSeaplane";
|
||||
buttonCreateSeaplane.Size = new Size(75, 23);
|
||||
buttonCreateSeaplane.TabIndex = 1;
|
||||
buttonCreateSeaplane.Text = "Создать";
|
||||
buttonCreateSeaplane.UseVisualStyleBackColor = true;
|
||||
buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(718, 490);
|
||||
buttonLeft.Location = new Point(768, 451);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrow_up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(758, 450);
|
||||
buttonUp.Location = new Point(808, 411);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrow_down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(758, 490);
|
||||
buttonDown.Location = new Point(808, 451);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrow_right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(799, 490);
|
||||
buttonRight.Location = new Point(849, 451);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// FormSeaplane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(850, 539);
|
||||
ClientSize = new Size(900, 500);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonCreateSeaplane);
|
||||
Controls.Add(pictureBoxSeaplane);
|
||||
Name = "FormSeaplane";
|
||||
Text = "Гидросамолёт";
|
||||
@ -121,7 +125,7 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxSeaplane;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateSeaplane;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
|
@ -1,40 +1,87 @@
|
||||
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 ProjectSeaplane
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public partial class FormSeaplane : Form
|
||||
{
|
||||
public partial class FormSeaplane : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningSeaplane? _drawningSeaplane;
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
public FormSeaplane()
|
||||
{
|
||||
private DrawningSeaplane? _drawningSeaplane;
|
||||
|
||||
public FormSeaplane()
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки машины
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningSeaplane == null)
|
||||
{
|
||||
InitializeComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
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>
|
||||
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();
|
||||
_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)), 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);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningSeaplane.DrawTransport(gr);
|
||||
pictureBoxSeaplane.Image = bmp;
|
||||
|
||||
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