From 125be39c5f3dafaffb24c96e9ddb56ccf4d98cfb Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:17:03 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=20=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1_OAP/Lab1_OAP.sln | 31 +++ Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp | 1 + Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj | 135 ++++++++++++ Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters | 22 ++ .../DrawingGasolineTanker.cs | 186 ---------------- .../{ => Drawings}/DirectionType.cs | 2 +- .../Drawings/DrawingGasolineTanker.cs | 73 +++++++ .../Drawings/DrawingTanker.cs | 205 ++++++++++++++++++ .../Entities/EntityGasolineTanker.cs | 45 ++++ .../Entities/EntityTanker.cs | 48 ++++ .../EntityGasolineTanker.cs | 61 ------ .../FormGasolineTanker.Designer.cs | 18 +- .../FormGasolineTanker.cs | 62 ++++-- 13 files changed, 621 insertions(+), 268 deletions(-) create mode 100644 Lab1_OAP/Lab1_OAP.sln create mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp create mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj create mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters delete mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs rename ProjectGasolineTanker/ProjectGasolineTanker/{ => Drawings}/DirectionType.cs (89%) create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs delete mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs diff --git a/Lab1_OAP/Lab1_OAP.sln b/Lab1_OAP/Lab1_OAP.sln new file mode 100644 index 0000000..92627e6 --- /dev/null +++ b/Lab1_OAP/Lab1_OAP.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab1_OAP", "Lab1_OAP\Lab1_OAP.vcxproj", "{39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.ActiveCfg = Debug|x64 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.Build.0 = Debug|x64 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.ActiveCfg = Debug|Win32 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.Build.0 = Debug|Win32 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.ActiveCfg = Release|x64 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.Build.0 = Release|x64 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.ActiveCfg = Release|Win32 + {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AD8890FA-E7D7-4EB8-996C-597872ABE83B} + EndGlobalSection +EndGlobal diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp b/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj new file mode 100644 index 0000000..7b4bd6f --- /dev/null +++ b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {39e703ff-4168-4aca-84ca-cdd94bfe3fd3} + Lab1OAP + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters new file mode 100644 index 0000000..0805cb7 --- /dev/null +++ b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs deleted file mode 100644 index 12c41af..0000000 --- a/ProjectGasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs +++ /dev/null @@ -1,186 +0,0 @@ -namespace ProjectGasolineTanker; - -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawingGasolineTanker -{ - /// - /// Класс-сущность - /// - public EntityGasolineTanker? EntityGasolineTanker { get; private set; } - - /// - /// Ширина окна - /// - private int? _pictureWidth; - - /// - /// Высота окна - /// - private int? _pictureHeight; - - /// - /// Левая координата прорисовки газовоза - /// - private int? _startPosX; - - /// - /// Верхняя кооридната прорисовки газовоза - /// - private int? _startPosY; - - /// - /// Ширина прорисовки газовоза - /// - private readonly int _drawingTankerWidth = 160; - - /// - /// Высота прорисовки газовоза - /// - private readonly int _drawingTankerHeight = 55; - - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия украшения на колесах - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool ornamentWheels) - { - EntityGasolineTanker = new EntityGasolineTanker(); - EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, ornamentWheels); - _pictureWidth = null; - _pictureHeight = null; - _startPosX = null; - _startPosY = null; - } - - /// - /// Установка границ поля - /// - /// Ширина поля - /// Высота поля - /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах - public bool SetPictureSize(int width, int height) - { - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена - _pictureWidth = width; - _pictureHeight = height; - return true; - } - - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - - // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы - // то надо изменить координаты, чтобы он оставался в этих границах - _startPosX = x; - _startPosY = y; - } - - /// - /// Изменение направления перемещения - /// - /// Направление - /// true - перемещение выполнено, false - перемещение невозможно - public bool MoveTransport(DirectionType direction) - { - if (EntityGasolineTanker == null || !_startPosX.HasValue || !_startPosY.HasValue) - { - return false; - } - - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX.Value - (int)EntityGasolineTanker.Step > 0) - { - _startPosX -= (int)EntityGasolineTanker.Step; - } - return true; - //вверх - case DirectionType.Up: - if (_startPosY.Value - (int)EntityGasolineTanker.Step > 0) - { - _startPosY -= (int)EntityGasolineTanker.Step; - } - return true; - //вправо - case DirectionType.Right: - if (_startPosX.Value + _drawingTankerWidth + (int)EntityGasolineTanker.Step < _pictureWidth) - { - _startPosX += (int)EntityGasolineTanker.Step; - } - return true; - //вниз - case DirectionType.Down: - if (_startPosY.Value + _drawingTankerHeight + (int)EntityGasolineTanker.Step < _pictureHeight) - { - _startPosY += (int)EntityGasolineTanker.Step; - } - return true; - default: - return false; - } - } - - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics g) - { - if (EntityGasolineTanker == null || !_startPosX.HasValue || !_startPosY.HasValue) - { - return; - } - //бак бензовоза - Pen pen = new Pen(Color.Black); - Brush dopBrush = new SolidBrush(EntityGasolineTanker.AdditionalColor); - if (EntityGasolineTanker.BodyKit) - { - g.FillRectangle(dopBrush, _startPosX.Value + 25, _startPosY.Value + 5, 100, 35); - g.FillRectangle(dopBrush, _startPosX.Value + 80, _startPosY.Value, 10, 5); - } - - //колеса - Brush brBlack = new SolidBrush(Color.Black); - g.FillEllipse(brBlack, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20); - g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); - g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20); - //корпус - Brush br = new SolidBrush(EntityGasolineTanker?.BodyColor ?? Color.Black); - g.FillRectangle(br, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); - g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 140, 10); - //окно - Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); - //окантовка - g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); - g.DrawRectangle(pen, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 105, 10); - //крыло колеса - if (EntityGasolineTanker != null && EntityGasolineTanker.OrnamentWheels) - { - Pen penGray = new Pen(Color.Gray); - g.DrawEllipse(penGray, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20); - g.DrawEllipse(penGray, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); - g.DrawEllipse(penGray, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20); - } - } -} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/DirectionType.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs similarity index 89% rename from ProjectGasolineTanker/ProjectGasolineTanker/DirectionType.cs rename to ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs index 9ba1c53..0e27236 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/DirectionType.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectGasolineTanker; +namespace ProjectGasolineTanker.Drawings; /// /// Направление перемещения diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs new file mode 100644 index 0000000..5210b0f --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs @@ -0,0 +1,73 @@ +using ProjectGasolineTanker.Entities; + +namespace ProjectGasolineTanker.Drawings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawingGasolineTanker : DrawingTanker +{ + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия украшения на колесах + public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels) : base(160,55) + { + EntityTanker = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, ornamentWheels); + } + + public override void DrawTransport(Graphics g) + { + if (EntityTanker == null || EntityTanker is not EntityGasolineTanker tanker || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new Pen(Color.Black); + Brush dopBrush = new SolidBrush(tanker.AdditionalColor); + + //колеса + Brush brBlack = new SolidBrush(Color.Black); + g.FillEllipse(brBlack, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20); + g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); + g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20); + //корпус + Brush br = new SolidBrush(tanker?.BodyColor ?? Color.Black); + g.FillRectangle(br, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 140, 10); + //окно + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); + //окантовка + g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); + g.DrawRectangle(pen, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 105, 10); + + _startPosX += 10; + _startPosY += 10; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 10; + + //бак бензовоза + if (tanker != null && tanker.Tank) + { + g.FillRectangle(dopBrush, _startPosX.Value + 25, _startPosY.Value + 5, 100, 35); + g.FillRectangle(dopBrush, _startPosX.Value + 80, _startPosY.Value, 10, 5); + } + + //крыло колеса + if (tanker != null && tanker.OrnamentWheels) + { + Pen penGray = new Pen(Color.Gray); + g.DrawEllipse(penGray, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20); + g.DrawEllipse(penGray, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); + g.DrawEllipse(penGray, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20); + } + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs new file mode 100644 index 0000000..8aa437f --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs @@ -0,0 +1,205 @@ +using ProjectGasolineTanker.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.Drawings; +public class DrawingTanker +{ + /// + /// Класс-сущность + /// + public EntityTanker? EntityTanker { get; protected set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки газовоза + /// + protected int? _startPosX; + + /// + /// Верхняя кооридната прорисовки газовоза + /// + protected int? _startPosY; + + /// + /// Ширина прорисовки газовоза + /// + private readonly int _drawingTankerWidth = 130; + + /// + /// Высота прорисовки газовоза + /// + private readonly int _drawingTankerHeight = 50; + + /// + /// Пустой конструктор + /// + private DrawingTanker() + { + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawingTanker(int speed, double weight, Color bodyColor) : this() + { + EntityTanker = new EntityTanker(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки газовоза + /// Высота прорисовки газовоза + protected DrawingTanker(int _drawingTankerWidth, int _drawingTankerHeight) : this() + { + _drawingTankerWidth = _drawingTankerWidth; + _drawingTankerHeight = _drawingTankerHeight; + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public Boolean SetPictureSize(int width, int height) + { + if (width <= _drawingTankerWidth || height <= _drawingTankerHeight) return false; + _pictureWidth = width; + _pictureHeight = height; + if (_startPosX.HasValue && _startPosY.HasValue) + { + if (_startPosX + _drawingTankerWidth > _pictureWidth) + { + _startPosX = _pictureWidth.Value - _drawingTankerWidth; + } + if (_startPosY + _drawingTankerHeight > _pictureHeight) + { + _startPosY = _pictureHeight.Value - _drawingTankerHeight; + } + } + + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + _startPosX = x; + _startPosY = y; + + if (_drawingTankerHeight + y > _pictureHeight || y < 0) + { + _startPosY = 0; + } + if (_drawingTankerWidth + x > _pictureWidth || x < 0) + { + _startPosX = 0; + } + } + + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещение выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntityTanker == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - (int)EntityTanker.Step > 0) + { + _startPosX -= (int)EntityTanker.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - (int)EntityTanker.Step > 0) + { + _startPosY -= (int)EntityTanker.Step; + } + return true; + //вправо + case DirectionType.Right: + if (_startPosX.Value + _drawingTankerWidth + (int)EntityTanker.Step < _pictureWidth) + { + _startPosX += (int)EntityTanker.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + _drawingTankerHeight + (int)EntityTanker.Step < _pictureHeight) + { + _startPosY += (int)EntityTanker.Step; + } + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public virtual void DrawTransport(Graphics g) + { + if (EntityTanker == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + Pen pen = new Pen(Color.Black); + + //колеса + Brush brBlack = new SolidBrush(Color.Black); + g.FillEllipse(brBlack, _startPosX.Value + 120, _startPosY.Value + 25, 20, 20); + g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 25, 20, 20); + g.FillEllipse(brBlack, _startPosX.Value + 20, _startPosY.Value + 25, 20, 20); + //корпус + Brush br = new SolidBrush(EntityTanker?.BodyColor ?? Color.Black); + g.FillRectangle(br, _startPosX.Value + 105, _startPosY.Value, 40, 40); + g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 140, 10); + //окно + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX.Value + 110, _startPosY.Value, 25, 25); + //окантовка + g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value, 25, 25); + g.DrawRectangle(pen, _startPosX.Value + 105, _startPosY.Value, 40, 40); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 105, 10); + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs new file mode 100644 index 0000000..62b4b51 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs @@ -0,0 +1,45 @@ +using System.Drawing; + +namespace ProjectGasolineTanker.Entities +{ + /// + /// Класс-сущность "Газовоз" + /// + public class EntityGasolineTanker : EntityTanker + { + public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels) : base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + Tank = tank; + OrnamentWheels = ornamentWheels; + } + + public Color AdditionalColor { get; private set; } + + /// + /// Признак наличия цистерны + /// + public bool Tank { get; private set; } + + /// + /// Признак наличия украшенных колес + /// + public bool OrnamentWheels { get; private set; } + + /// + /// Инициализация полей объекта-класса газовоза + /// + /// Скорость + /// Вес газовоза + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия цистерны + /// Признак наличия украшенных колес + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels) + { + AdditionalColor = additionalColor; + Tank = tank; + OrnamentWheels = ornamentWheels; + } + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs new file mode 100644 index 0000000..ffe5f13 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.Entities; + +/// +/// Класс-сущность "Танкер" +/// +public class EntityTanker +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг перемещения газовоза + /// + public double Step => Speed * 100 / Weight; + + /// + /// Конструктор сущности + /// + /// Скорость + /// Вес газовоза + /// Основной цвет + + public EntityTanker(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} + diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs deleted file mode 100644 index 5a2882b..0000000 --- a/ProjectGasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace ProjectGasolineTanker; - -/// -/// Класс-сущность "Газовоз" -/// -public class EntityGasolineTanker -{ - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - - /// - /// Дополнительный цвет - /// - public Color AdditionalColor { get; private set; } - - /// - /// Признак наличия обвеса - /// - public bool BodyKit { get; private set; } - - /// - /// Признак наличия украшенных колес - /// - public bool OrnamentWheels { get; private set; } - - /// - /// Шаг перемещения газовоза - /// - public double Step => Speed * 100 / Weight; - - /// - /// Инициализация полей объекта-класса газовоза - /// - /// Скорость - /// Вес газовоза - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия украшенных колес - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool ornamentWheels) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - BodyKit = bodyKit; - OrnamentWheels = ornamentWheels; - } -} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs index d925acf..fcc0ec1 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs @@ -34,6 +34,7 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); + buttonCreateTanker = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxGasolineTanker).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreateGasolineTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateGasolineTanker.Location = new Point(12, 682); buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker"; - buttonCreateGasolineTanker.Size = new Size(112, 34); + buttonCreateGasolineTanker.Size = new Size(230, 34); buttonCreateGasolineTanker.TabIndex = 1; - buttonCreateGasolineTanker.Text = "Создать"; + buttonCreateGasolineTanker.Text = "Создать Бензовоз"; buttonCreateGasolineTanker.UseVisualStyleBackColor = true; buttonCreateGasolineTanker.Click += buttonCreateGasolineTanker_Click; // @@ -105,11 +106,23 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // + // buttonCreateTanker + // + buttonCreateTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateTanker.Location = new Point(248, 682); + buttonCreateTanker.Name = "buttonCreateTanker"; + buttonCreateTanker.Size = new Size(230, 34); + buttonCreateTanker.TabIndex = 6; + buttonCreateTanker.Text = "Создать Грузовик"; + buttonCreateTanker.UseVisualStyleBackColor = true; + buttonCreateTanker.Click += buttonCreateTanker_Click; + // // FormGasolineTanker // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1312, 749); + Controls.Add(buttonCreateTanker); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -130,5 +143,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateTanker; } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs index cacf984..bf37407 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs @@ -1,4 +1,5 @@ -using System; +using ProjectGasolineTanker.Drawings; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -15,7 +16,7 @@ namespace ProjectGasolineTanker /// /// Поле-объект для прорисовки объекта /// - private DrawingGasolineTanker? _drawingGasolineTanker; + private DrawingTanker? _drawingTanker; /// /// Инициализация формы /// @@ -28,16 +29,43 @@ namespace ProjectGasolineTanker /// private void Draw() { - if (_drawingGasolineTanker == null) + if (_drawingTanker == null) { return; } Bitmap bmp = new(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingGasolineTanker.DrawTransport(gr); + _drawingTanker.DrawTransport(gr); pictureBoxGasolineTanker.Image = bmp; } + + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawingTanker): + _drawingTanker = new DrawingTanker(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawingGasolineTanker): + _drawingTanker = new DrawingGasolineTanker(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))); + break; + default: + return; + } + _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + _drawingTanker.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + + + + /// /// Обработка нажатия кнопки создать /// @@ -45,16 +73,14 @@ namespace ProjectGasolineTanker /// private void buttonCreateGasolineTanker_Click(object sender, EventArgs e) { - Random random = new(); - _drawingGasolineTanker = new DrawingGasolineTanker(); - _drawingGasolineTanker.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))); - _drawingGasolineTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); - _drawingGasolineTanker.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); + CreateObject(nameof(DrawingGasolineTanker)); } + + private void buttonCreateTanker_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingTanker)); + } + /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -62,7 +88,7 @@ namespace ProjectGasolineTanker /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawingGasolineTanker == null) + if (_drawingTanker == null) { return; } @@ -72,16 +98,16 @@ namespace ProjectGasolineTanker switch (name) { case "buttonUp": - result = _drawingGasolineTanker.MoveTransport(DirectionType.Up); + result = _drawingTanker.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawingGasolineTanker.MoveTransport(DirectionType.Down); + result = _drawingTanker.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawingGasolineTanker.MoveTransport(DirectionType.Left); + result = _drawingTanker.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawingGasolineTanker.MoveTransport(DirectionType.Right); + result = _drawingTanker.MoveTransport(DirectionType.Right); break; } -- 2.25.1 From a69215962d5178c32c323df35a56423e77cca207 Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:48:28 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawings/DirectionType.cs | 3 +- .../Drawings/DrawingGasolineTanker.cs | 21 +-- .../Drawings/DrawingTanker.cs | 26 ++- .../FormGasolineTanker.Designer.cs | 26 +++ .../FormGasolineTanker.cs | 42 ++++- .../MovementStrategy/AbstractStrategy.cs | 78 +++++++++ .../MovementStrategy/IMoveableObject.cs | 27 ++++ .../MovementStrategy/MoveToBorder.cs | 41 +++++ .../MovementStrategy/MoveToCenter.cs | 42 +++++ .../MovementStrategy/MoveableTanker.cs | 66 ++++++++ .../MovementStrategy/MovementDirection.cs | 15 ++ .../MovementStrategy/ObjectParameters.cs | 73 +++++++++ .../MovementStrategy/StrategyStatus.cs | 14 ++ laboap1/laboap1.sln | 31 ++++ laboap1/laboap1/laboap1.cpp | 151 ++++++++++++++++++ laboap1/laboap1/laboap1.vcxproj | 136 ++++++++++++++++ laboap1/laboap1/laboap1.vcxproj.filters | 22 +++ 17 files changed, 787 insertions(+), 27 deletions(-) create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/AbstractStrategy.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/IMoveableObject.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToBorder.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToCenter.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveableTanker.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MovementDirection.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/ObjectParameters.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/StrategyStatus.cs create mode 100644 laboap1/laboap1.sln create mode 100644 laboap1/laboap1/laboap1.cpp create mode 100644 laboap1/laboap1/laboap1.vcxproj create mode 100644 laboap1/laboap1/laboap1.vcxproj.filters diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs index 0e27236..f552d6b 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DirectionType.cs @@ -5,6 +5,7 @@ /// public enum DirectionType { + Unknow = -1, /// /// Вверх /// @@ -23,5 +24,5 @@ public enum DirectionType /// /// Вправо /// - Right = 4 + Right = 4, } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs index 5210b0f..97b8d07 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs @@ -30,23 +30,6 @@ public class DrawingGasolineTanker : DrawingTanker Pen pen = new Pen(Color.Black); Brush dopBrush = new SolidBrush(tanker.AdditionalColor); - - //колеса - Brush brBlack = new SolidBrush(Color.Black); - g.FillEllipse(brBlack, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20); - g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); - g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20); - //корпус - Brush br = new SolidBrush(tanker?.BodyColor ?? Color.Black); - g.FillRectangle(br, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); - g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 140, 10); - //окно - Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); - //окантовка - g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25); - g.DrawRectangle(pen, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 105, 10); _startPosX += 10; _startPosY += 10; @@ -57,8 +40,8 @@ public class DrawingGasolineTanker : DrawingTanker //бак бензовоза if (tanker != null && tanker.Tank) { - g.FillRectangle(dopBrush, _startPosX.Value + 25, _startPosY.Value + 5, 100, 35); - g.FillRectangle(dopBrush, _startPosX.Value + 80, _startPosY.Value, 10, 5); + g.FillRectangle(dopBrush, _startPosX.Value + 15, _startPosY.Value + 3, 100, 35); + g.FillRectangle(dopBrush, _startPosX.Value + 70, _startPosY.Value, 5, 5); } //крыло колеса diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs index 8aa437f..84e09f2 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTanker.cs @@ -43,6 +43,26 @@ public class DrawingTanker /// private readonly int _drawingTankerHeight = 50; + /// + /// Координата X объекта + /// + public int? GetPosX => _startPosX; + + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + + /// + /// Ширина объекта + /// + public int GetWidth => _drawingTankerWidth; + + /// + /// Высота объекта + /// + public int GetHeight => _drawingTankerHeight; + /// /// Пустой конструктор /// @@ -72,8 +92,8 @@ public class DrawingTanker /// Высота прорисовки газовоза protected DrawingTanker(int _drawingTankerWidth, int _drawingTankerHeight) : this() { - _drawingTankerWidth = _drawingTankerWidth; - _drawingTankerHeight = _drawingTankerHeight; + this._drawingTankerWidth = _drawingTankerWidth; + this._drawingTankerHeight = _drawingTankerHeight; } /// @@ -98,9 +118,9 @@ public class DrawingTanker _startPosY = _pictureHeight.Value - _drawingTankerHeight; } } - return true; } + /// /// Установка позиции /// diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs index fcc0ec1..2e74d11 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs @@ -35,6 +35,8 @@ buttonRight = new Button(); buttonUp = new Button(); buttonCreateTanker = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxGasolineTanker).BeginInit(); SuspendLayout(); // @@ -117,11 +119,33 @@ buttonCreateTanker.UseVisualStyleBackColor = true; buttonCreateTanker.Click += buttonCreateTanker_Click; // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Location = new Point(1118, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(182, 33); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Location = new Point(1188, 51); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(112, 34); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; + // // FormGasolineTanker // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1312, 749); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateTanker); Controls.Add(buttonUp); Controls.Add(buttonRight); @@ -144,5 +168,7 @@ private Button buttonRight; private Button buttonUp; private Button buttonCreateTanker; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs index bf37407..ba4eed7 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs @@ -1,4 +1,5 @@ using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.MovementStrategy; using System; using System.Collections.Generic; using System.ComponentModel; @@ -17,16 +18,21 @@ namespace ProjectGasolineTanker /// Поле-объект для прорисовки объекта /// private DrawingTanker? _drawingTanker; + /// - /// Инициализация формы + /// Стратегия перемещения + /// + private AbstractStrategy? _strategy; + + /// + /// Конструктор формы /// public FormGasolineTanker() { InitializeComponent(); + _strategy = null; } - /// - /// Метод прорисовки бензовоза - /// + private void Draw() { if (_drawingTanker == null) @@ -60,6 +66,8 @@ namespace ProjectGasolineTanker } _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); _drawingTanker.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _strategy = null; + comboBoxStrategy.Enabled = true; Draw(); } @@ -116,5 +124,31 @@ namespace ProjectGasolineTanker Draw(); } } + + private void buttonStrategyStep_Click(object sender, EventArgs e) + { + if (_drawingTanker == null) return; + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) return; + _strategy.SetData(new MoveableTanker(_drawingTanker), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + } + if (_strategy == null) return; + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + + if (_strategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/AbstractStrategy.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..018f319 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,78 @@ +using System; + +namespace ProjectGasolineTanker.MovementStrategy +{ + public abstract class AbstractStrategy + { + private IMoveableObject? _moveableObject; + private StrategyStatus _state = StrategyStatus.NotInit; + + protected int FieldWidth { get; private set; } + protected int FieldHeight { get; private set; } + + public StrategyStatus GetStatus() { return _state; } + + public void SetData(IMoveableObject moveableObject, int width, int height) + { + if (moveableObject == null) + { + _state = StrategyStatus.NotInit; + return; + } + + _state = StrategyStatus.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + + public void MakeStep() + { + if (_state != StrategyStatus.InProgress) + { + return; + } + + if (IsTargetDestinaion()) + { + _state = StrategyStatus.Finish; + return; + } + + MoveToTarget(); + } + + protected bool MoveLeft() => MoveTo(MovementDirection.Left); + + protected bool MoveRight() => MoveTo(MovementDirection.Right); + + protected bool MoveUp() => MoveTo(MovementDirection.Up); + + protected bool MoveDown() => MoveTo(MovementDirection.Down); + + protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; + + protected int? GetStep() + { + if (_state != StrategyStatus.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + + protected abstract void MoveToTarget(); + + protected abstract bool IsTargetDestinaion(); + + private bool MoveTo(MovementDirection movementDirection) + { + if (_state != StrategyStatus.InProgress) + { + return false; + } + + return _moveableObject?.TryMoveObject(movementDirection) ?? false; + } + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/IMoveableObject.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..48131ff --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public interface IMoveableObject +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// Шаг объекта + /// + int GetStep { get; } + + /// + /// Попытка переместить объект в указанном направлении + /// + /// Направление + /// true - объект перемещен, false - перемещение невозможно + bool TryMoveObject(MovementDirection direction); +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToBorder.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..805069b --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public class MoveToBorder : AbstractStrategy +{ + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight; + } + + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + int diffX = objParams.RightBorder - FieldWidth + 11; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) MoveLeft(); + else MoveRight(); + } + int diffY = objParams.DownBorder - FieldHeight + 11; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) MoveUp(); + else MoveDown(); + } + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToCenter.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..844964e --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public class MoveToCenter : AbstractStrategy +{ + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && + objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; + } + + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) MoveLeft(); + else MoveRight(); + } + int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) MoveUp(); + else MoveDown(); + } + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveableTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveableTanker.cs new file mode 100644 index 0000000..632bcf2 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MoveableTanker.cs @@ -0,0 +1,66 @@ +using ProjectGasolineTanker.Drawings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public class MoveableTanker : IMoveableObject +{ + /// + /// Поле-объект класса DrawingTanker или его наследника + /// + private readonly DrawingTanker? _tanker = null; + + /// + /// Конструктор + /// + /// Объект класса DrawingTanker + public MoveableTanker(DrawingTanker tanker) + { + _tanker = tanker; + } + + public ObjectParameters? GetObjectPosition + { + get + { + if (_tanker == null || _tanker.EntityTanker == null || !_tanker.GetPosX.HasValue || !_tanker.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_tanker.GetPosX.Value, _tanker.GetPosY.Value, _tanker.GetWidth, _tanker.GetHeight); + } + } + + public int GetStep => (int)(_tanker?.EntityTanker?.Step ?? 0); + + public bool TryMoveObject(MovementDirection direction) + { + if (_tanker == null || _tanker.EntityTanker == null) + { + return false; + } + + return _tanker.MoveTransport(GetDirectionType(direction)); + } + + /// + /// Конвертация из MovementDirection в DirectionType + /// + /// MovementDirection + /// DirectionType + private static DirectionType GetDirectionType(MovementDirection direction) + { + return direction switch + { + MovementDirection.Left => DirectionType.Left, + MovementDirection.Right => DirectionType.Right, + MovementDirection.Up => DirectionType.Up, + MovementDirection.Down => DirectionType.Down, + _ => DirectionType.Unknow, + }; + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MovementDirection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..8a070b4 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/MovementDirection.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public enum MovementDirection +{ + Up = 1, + Down = 2, + Left = 3, + Right = 4, +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/ObjectParameters.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..efa9bbc --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public class ObjectParameters +{ + /// + /// Координата x + /// + private readonly int _x; + + /// + /// Координата y + /// + private readonly int _y; + + /// + /// Ширина объекта + /// + private readonly int _width; + + /// + /// Высота объекта + /// + private readonly int _height; + + /// + /// Левая граница + /// + public int LeftBorder => _x; + /// + /// Верхняя граница + /// + public int TopBorder => _y; + + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + + /// + /// Нижняя граница + /// + public int DownBorder => _y + _height; + + /// + /// Середина объекта + /// + public int ObjectMiddleHorizontal => _x + _width / 2; + /// + /// Середина объекта + /// + public int ObjectMiddleVertical => _y + _height / 2; + + /// + /// Конструктор + /// + /// Координата x + /// Координата y + /// Ширина объекта + /// Высота объекта + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/StrategyStatus.cs b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..9a92c58 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.MovementStrategy; + +public enum StrategyStatus +{ + NotInit, + InProgress, + Finish +} diff --git a/laboap1/laboap1.sln b/laboap1/laboap1.sln new file mode 100644 index 0000000..9f5ffa8 --- /dev/null +++ b/laboap1/laboap1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "laboap1", "laboap1\laboap1.vcxproj", "{1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.ActiveCfg = Debug|x64 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.Build.0 = Debug|x64 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.ActiveCfg = Debug|Win32 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.Build.0 = Debug|Win32 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.ActiveCfg = Release|x64 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.Build.0 = Release|x64 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.ActiveCfg = Release|Win32 + {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {898933DD-7FA8-4FA7-872F-63991ACB024A} + EndGlobalSection +EndGlobal diff --git a/laboap1/laboap1/laboap1.cpp b/laboap1/laboap1/laboap1.cpp new file mode 100644 index 0000000..0329b66 --- /dev/null +++ b/laboap1/laboap1/laboap1.cpp @@ -0,0 +1,151 @@ +#include +#include +#include + +void printArray(int arr[], int size) { + for (int i = 0; i < size; i++) { + printf("%d ", arr[i]); + } + printf("\n"); +} + +void insertionSort(int arr[], int size) { + int i, key, j; + for (i = 1; i < size; i++) { + key = arr[i]; + j = i - 1; + + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } +} + +void merge(int arr[], int left, int mid, int right) { + int i, j, k; + int n1 = mid - left + 1; + int n2 = right - mid; + + int L[n1], R[n2]; + + for (i = 0; i < n1; i++) + L[i] = arr[left + i]; + for (j = 0; j < n2; j++) + R[j] = arr[mid + 1 + j]; + + i = 0; + j = 0; + k = left; + while (i < n1 && j < n2) { + if (L[i] <= R[j]) { + arr[k] = L[i]; + i++; + } + else { + arr[k] = R[j]; + j++; + } + k++; + } + + while (i < n1) { + arr[k] = L[i]; + i++; + k++; + } + + while (j < n2) { + arr[k] = R[j]; + j++; + k++; + } +} + +void mergeSort(int arr[], int left, int right) { + if (left < right) { + int mid = left + (right - left) / 2; + + mergeSort(arr, left, mid); + mergeSort(arr, mid + 1, right); + + merge(arr, left, mid, right); + } +} + +int main() { + srand(time(0)); + + int size; + printf("Enter the size of the array: "); + scanf("%d", &size); + + int arr[size]; + for (int i = 0; i < size; i++) { + arr[i] = rand() % 100; + } + + printf("Randomly generated array: "); + printArray(arr, size); + + int choice; + printf("Enter 1 to delete an element, 2 to insert a new element: "); + scanf("%d", &choice); + + if (choice == 1) { + int index; + printf("Enter the index of the element you want to delete: "); + scanf("%d", &index); + + for (int i = index; i < size - 1; i++) { + arr[i] = arr[i + 1]; + } + size--; + } + else if (choice == 2) { + int index, element; + printf("Enter the index at which you want to insert the new element: "); + scanf("%d", &index); + printf("Enter the new element: "); + scanf("%d", &element); + + for (int i = size; i > index; i--) { + arr[i] = arr[i - 1]; + } + arr[index] = element; + size++; + } + else { + printf("Invalid choice"); + return 0; + } + + printf("Modified array: "); + printArray(arr, size); + + int arr_copy[size]; + for (int i = 0; i < size; i++) { + arr_copy[i] = arr[i]; + } + + clock_t start_time = clock(); + insertionSort(arr, size); + clock_t end_time = clock(); + double insertion_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; + + printf("Array sorted using Insertion Sort: "); + printArray(arr, size); + printf("Time taken by Insertion Sort: %f seconds\n", insertion_time); + + start_time = clock(); + mergeSort(arr_copy, 0, size - 1); + end_time = clock(); + double merge_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; + + printf("Array sorted using Merge Sort: "); + printArray(arr_copy, size); + printf("Time taken by Merge Sort: %f seconds\n", merge_time); + + return 0; +} \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj b/laboap1/laboap1/laboap1.vcxproj new file mode 100644 index 0000000..085cb5f --- /dev/null +++ b/laboap1/laboap1/laboap1.vcxproj @@ -0,0 +1,136 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {1f4724c2-6bc1-42c2-acc1-93aaa85ba624} + laboap1 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj.filters b/laboap1/laboap1/laboap1.vcxproj.filters new file mode 100644 index 0000000..2bff827 --- /dev/null +++ b/laboap1/laboap1/laboap1.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file -- 2.25.1 From 82a849f0870b000eb4a7549599052afa39e545e2 Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Tue, 21 May 2024 21:37:28 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BE=D1=82=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1_OAP/Lab1_OAP.sln | 31 ----- Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp | 1 - Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj | 135 ------------------ Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters | 22 --- laboap1/laboap1.sln | 31 ----- laboap1/laboap1/laboap1.cpp | 151 --------------------- laboap1/laboap1/laboap1.vcxproj | 136 ------------------- laboap1/laboap1/laboap1.vcxproj.filters | 22 --- 8 files changed, 529 deletions(-) delete mode 100644 Lab1_OAP/Lab1_OAP.sln delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters delete mode 100644 laboap1/laboap1.sln delete mode 100644 laboap1/laboap1/laboap1.cpp delete mode 100644 laboap1/laboap1/laboap1.vcxproj delete mode 100644 laboap1/laboap1/laboap1.vcxproj.filters diff --git a/Lab1_OAP/Lab1_OAP.sln b/Lab1_OAP/Lab1_OAP.sln deleted file mode 100644 index 92627e6..0000000 --- a/Lab1_OAP/Lab1_OAP.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab1_OAP", "Lab1_OAP\Lab1_OAP.vcxproj", "{39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.ActiveCfg = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.Build.0 = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.ActiveCfg = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.Build.0 = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.ActiveCfg = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.Build.0 = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.ActiveCfg = Release|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AD8890FA-E7D7-4EB8-996C-597872ABE83B} - EndGlobalSection -EndGlobal diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp b/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp deleted file mode 100644 index 5f28270..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj deleted file mode 100644 index 7b4bd6f..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {39e703ff-4168-4aca-84ca-cdd94bfe3fd3} - Lab1OAP - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters deleted file mode 100644 index 0805cb7..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file diff --git a/laboap1/laboap1.sln b/laboap1/laboap1.sln deleted file mode 100644 index 9f5ffa8..0000000 --- a/laboap1/laboap1.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "laboap1", "laboap1\laboap1.vcxproj", "{1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.ActiveCfg = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.Build.0 = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.ActiveCfg = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.Build.0 = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.ActiveCfg = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.Build.0 = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.ActiveCfg = Release|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {898933DD-7FA8-4FA7-872F-63991ACB024A} - EndGlobalSection -EndGlobal diff --git a/laboap1/laboap1/laboap1.cpp b/laboap1/laboap1/laboap1.cpp deleted file mode 100644 index 0329b66..0000000 --- a/laboap1/laboap1/laboap1.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include - -void printArray(int arr[], int size) { - for (int i = 0; i < size; i++) { - printf("%d ", arr[i]); - } - printf("\n"); -} - -void insertionSort(int arr[], int size) { - int i, key, j; - for (i = 1; i < size; i++) { - key = arr[i]; - j = i - 1; - - while (j >= 0 && arr[j] > key) { - arr[j + 1] = arr[j]; - j = j - 1; - } - arr[j + 1] = key; - } -} - -void merge(int arr[], int left, int mid, int right) { - int i, j, k; - int n1 = mid - left + 1; - int n2 = right - mid; - - int L[n1], R[n2]; - - for (i = 0; i < n1; i++) - L[i] = arr[left + i]; - for (j = 0; j < n2; j++) - R[j] = arr[mid + 1 + j]; - - i = 0; - j = 0; - k = left; - while (i < n1 && j < n2) { - if (L[i] <= R[j]) { - arr[k] = L[i]; - i++; - } - else { - arr[k] = R[j]; - j++; - } - k++; - } - - while (i < n1) { - arr[k] = L[i]; - i++; - k++; - } - - while (j < n2) { - arr[k] = R[j]; - j++; - k++; - } -} - -void mergeSort(int arr[], int left, int right) { - if (left < right) { - int mid = left + (right - left) / 2; - - mergeSort(arr, left, mid); - mergeSort(arr, mid + 1, right); - - merge(arr, left, mid, right); - } -} - -int main() { - srand(time(0)); - - int size; - printf("Enter the size of the array: "); - scanf("%d", &size); - - int arr[size]; - for (int i = 0; i < size; i++) { - arr[i] = rand() % 100; - } - - printf("Randomly generated array: "); - printArray(arr, size); - - int choice; - printf("Enter 1 to delete an element, 2 to insert a new element: "); - scanf("%d", &choice); - - if (choice == 1) { - int index; - printf("Enter the index of the element you want to delete: "); - scanf("%d", &index); - - for (int i = index; i < size - 1; i++) { - arr[i] = arr[i + 1]; - } - size--; - } - else if (choice == 2) { - int index, element; - printf("Enter the index at which you want to insert the new element: "); - scanf("%d", &index); - printf("Enter the new element: "); - scanf("%d", &element); - - for (int i = size; i > index; i--) { - arr[i] = arr[i - 1]; - } - arr[index] = element; - size++; - } - else { - printf("Invalid choice"); - return 0; - } - - printf("Modified array: "); - printArray(arr, size); - - int arr_copy[size]; - for (int i = 0; i < size; i++) { - arr_copy[i] = arr[i]; - } - - clock_t start_time = clock(); - insertionSort(arr, size); - clock_t end_time = clock(); - double insertion_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Insertion Sort: "); - printArray(arr, size); - printf("Time taken by Insertion Sort: %f seconds\n", insertion_time); - - start_time = clock(); - mergeSort(arr_copy, 0, size - 1); - end_time = clock(); - double merge_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Merge Sort: "); - printArray(arr_copy, size); - printf("Time taken by Merge Sort: %f seconds\n", merge_time); - - return 0; -} \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj b/laboap1/laboap1/laboap1.vcxproj deleted file mode 100644 index 085cb5f..0000000 --- a/laboap1/laboap1/laboap1.vcxproj +++ /dev/null @@ -1,136 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {1f4724c2-6bc1-42c2-acc1-93aaa85ba624} - laboap1 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj.filters b/laboap1/laboap1/laboap1.vcxproj.filters deleted file mode 100644 index 2bff827..0000000 --- a/laboap1/laboap1/laboap1.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file -- 2.25.1