From 3348c036dd89e2e00cd0bd84ba052340a0e40bb2 Mon Sep 17 00:00:00 2001 From: BoiledMilk123 Date: Mon, 11 Mar 2024 23:38:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project1/Project1.sln | 31 +++ Project1/Project1/Project1.vcxproj | 135 +++++++++++ Project1/Project1/Project1.vcxproj.filters | 22 ++ Project1/Project1/sove.cpp | 56 +++++ .../{ => Drawnings}/DirectionType.cs | 2 +- .../Drawnings/DrawningElectricLocomotive.cs | 84 +++++++ .../DrawningLocomotive.cs} | 210 +++++++++--------- .../EntityElectricLocomotive.cs | 32 +-- .../Entities/EntityLocomotive.cs | 45 ++++ .../FormElectricLocomotive.Designer.cs | 20 +- .../FormElectricLocomotive.cs | 68 ++++-- 11 files changed, 540 insertions(+), 165 deletions(-) create mode 100644 Project1/Project1.sln create mode 100644 Project1/Project1/Project1.vcxproj create mode 100644 Project1/Project1/Project1.vcxproj.filters create mode 100644 Project1/Project1/sove.cpp rename ProjectElectricLocomotive/ProjectElectricLocomotive/{ => Drawnings}/DirectionType.cs (90%) create mode 100644 ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningElectricLocomotive.cs rename ProjectElectricLocomotive/ProjectElectricLocomotive/{DrawningElectricLocomotive.cs => Drawnings/DrawningLocomotive.cs} (57%) rename ProjectElectricLocomotive/ProjectElectricLocomotive/{ => Entities}/EntityElectricLocomotive.cs (57%) create mode 100644 ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityLocomotive.cs diff --git a/Project1/Project1.sln b/Project1/Project1.sln new file mode 100644 index 0000000..4149998 --- /dev/null +++ b/Project1/Project1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}" +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 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x64.ActiveCfg = Debug|x64 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x64.Build.0 = Debug|x64 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x86.ActiveCfg = Debug|Win32 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x86.Build.0 = Debug|Win32 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x64.ActiveCfg = Release|x64 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x64.Build.0 = Release|x64 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x86.ActiveCfg = Release|Win32 + {51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {188BD3AE-A59B-46F9-AEC9-A67BF38B0430} + EndGlobalSection +EndGlobal diff --git a/Project1/Project1/Project1.vcxproj b/Project1/Project1/Project1.vcxproj new file mode 100644 index 0000000..96fe319 --- /dev/null +++ b/Project1/Project1/Project1.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {51322afd-5d22-49a7-bc85-ac24dacbaee8} + Project1 + 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/Project1/Project1/Project1.vcxproj.filters b/Project1/Project1/Project1.vcxproj.filters new file mode 100644 index 0000000..61be7de --- /dev/null +++ b/Project1/Project1/Project1.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/Project1/Project1/sove.cpp b/Project1/Project1/sove.cpp new file mode 100644 index 0000000..e966ec7 --- /dev/null +++ b/Project1/Project1/sove.cpp @@ -0,0 +1,56 @@ +#define _USE_MATH_DEFINES +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace std; + + +typedef long long ll; +typedef unsigned long long ull; +typedef unsigned int uint; +typedef long double ld; +typedef pair pll; +typedef pair pii; + + +const ll LINF = 100090009990; +const int INF = 1009000999; +const int N = 1002; +const int M = 1002; +const ld PI = 3.1415926535; +const ld E = 2.7182818284; +const ll MOD = 1000000007; +const int MAX = 150010; +const ld EPS = 1e-10; + + + + +int main() +{ + vector Buttons{ "A", "B","C", "D", "L1", "L2", "R1", "R2" }; + vector ButtonsAns{ "A", "B","C", "D", "L1", "L2", "R1", "R2" }; + vector used, unused; + int stick; + + + return 0; +} \ No newline at end of file diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/DirectionType.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DirectionType.cs similarity index 90% rename from ProjectElectricLocomotive/ProjectElectricLocomotive/DirectionType.cs rename to ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DirectionType.cs index 17ab51c..44c4914 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/DirectionType.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DirectionType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectElectricLocomotive; +namespace ProjectElectricLocomotive.Drawnings; public enum DirectionType { diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningElectricLocomotive.cs new file mode 100644 index 0000000..aafc9d9 --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningElectricLocomotive.cs @@ -0,0 +1,84 @@ + +using ProjectElectricLocomotive.Entities; + +namespace ProjectElectricLocomotive.Drawnings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта - сущности +/// +public class DrawningElectricLocomotive : DrawningLocomotive +{ + /// + /// Конструктор + /// + /// + /// + /// + /// + /// + /// + /// + public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) : base(83,45) + { + EntityLocomotive = new EntityElectricLocomotive(speed, weight, bodyColor, additionalColor, electricHorns, batteryPlacement); + } + + public override void DrawTransport(Graphics g) + { + if (EntityLocomotive == null || EntityLocomotive is not EntityElectricLocomotive electricLocomotive || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + //Создание перьев и кистей для прорисовки электровоза + Brush blackBrush = new SolidBrush(Color.Black); + Pen penSolid = new(Color.Black, 2); + Pen penSolidYellow = new(Color.Yellow, 0.5f); + Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor); + + //Прорисовка дополнительного элемента (рогов) + if (electricLocomotive.ElectricHorns) + { + + + //Инициализация опорных точек для прорисовки "рогов" + Point pointHorns1 = new Point(_startPosX.Value + 13, _startPosY.Value + 5); + Point pointHorns2 = new Point(_startPosX.Value + 16, _startPosY.Value + 2); + Point pointHorns3 = new Point(_startPosX.Value + 11, _startPosY.Value); + + //Прорисовка "рогов" электровоза + g.DrawLine(penSolid, pointHorns1, pointHorns2); + g.DrawLine(penSolid, pointHorns2, pointHorns3); + } + //Прорисовка дополнительного элемента (места под батарею) + if (electricLocomotive.BatteryPlacement) + { + //Инициализация опорных точек для прорисовки молнии на хранилище батарей + Point pointLightning1 = new Point(_startPosX.Value + 39, _startPosY.Value + 37); + Point pointLightning2 = new Point(_startPosX.Value + 37, _startPosY.Value + 39); + Point pointLightning3 = new Point(_startPosX.Value + 39, _startPosY.Value + 40); + Point pointLightning4 = new Point(_startPosX.Value + 37, _startPosY.Value + 41); + + //Прорисовка "хранилища батарей" электровоза + g.FillRectangle(blackBrush, _startPosX.Value + 36, _startPosY.Value + 37, 8, 4.5f); + g.DrawLine(penSolidYellow, pointLightning1, pointLightning2); + g.DrawLine(penSolidYellow, pointLightning2, pointLightning3); + g.DrawLine(penSolidYellow, pointLightning3, pointLightning4); + + } + + _startPosY += 5; + base.DrawTransport(g); + _startPosY -= 5; + + //Опциональная прорисовка цвета передних колёс + g.FillEllipse(additionalBrush, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8); + g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8); + + //Опциональная прорисовка цвета задних колёс + g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8); + g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 37, 8, 8); + + } + +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawningElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs similarity index 57% rename from ProjectElectricLocomotive/ProjectElectricLocomotive/DrawningElectricLocomotive.cs rename to ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs index b3298c0..a5afd18 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawningElectricLocomotive.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs @@ -1,15 +1,18 @@ - -namespace ProjectElectricLocomotive; +using ProjectElectricLocomotive.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -/// -/// Класс, отвечающий за прорисовку и перемещение объекта - сущности -/// -public class DrawningElectricLocomotive +namespace ProjectElectricLocomotive.Drawnings; + +public class DrawningLocomotive { /// /// Класс-сущность /// - public EntityElectricLocomotive? EntityElectricLocomotive { get; private set; } + public EntityLocomotive? EntityLocomotive { get; protected set; } /// /// Ширина окна @@ -22,47 +25,59 @@ public class DrawningElectricLocomotive private int? _pictureHeight; /// - /// Левая координата прорисовки электровоза + /// Левая координата прорисовки локомотива /// - private int? _startPosX; + protected int? _startPosX; /// - /// Верхняя координата прорисовки электровоза + /// Верхняя координата прорисовки локомотива /// - private int? _startPosY; + protected int? _startPosY; /// - /// Ширина прорисовки электровоза + /// Ширина прорисовки локомотива /// private readonly int _drawningElectricLocomotiveWidth = 83; /// - /// Высота прорисовки электровоза + /// Высота прорисовки локомотива /// - private readonly int _drawningElectricLocomotiveHeight = 45; + private readonly int _drawningElectricLocomotiveHeight = 40; /// - /// Инициализация свойств + /// Пустой конструктор /// - /// - /// - /// - /// - /// - /// - /// - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) + private DrawningLocomotive() { - EntityElectricLocomotive = new EntityElectricLocomotive(); - - EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, electricHorns, batteryPlacement); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// + /// + /// + public DrawningLocomotive(int speed, double weight, Color bodyColor) : this() + { + EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки локомотива + /// Высота прорисовки локомотива + protected DrawningLocomotive(int drawningElectricLocomotiveWidth, int drawningElectricLocomotiveHeight) : this() + { + _drawningElectricLocomotiveWidth = drawningElectricLocomotiveWidth; + _drawningElectricLocomotiveHeight = drawningElectricLocomotiveHeight; + } + /// /// Установка границ поля /// @@ -71,17 +86,17 @@ public class DrawningElectricLocomotive /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - if(_drawningElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width) + if (_drawningElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width) { return false; } _pictureWidth = width; _pictureHeight = height; - if (_startPosY.HasValue && _startPosY + _drawningElectricLocomotiveHeight < _pictureHeight ) + if (_startPosY.HasValue && _startPosY + _drawningElectricLocomotiveHeight < _pictureHeight) { - _startPosY = _pictureHeight - _drawningElectricLocomotiveHeight; + _startPosY = _pictureHeight - _drawningElectricLocomotiveHeight; } - if (_startPosX.HasValue && _startPosX + _drawningElectricLocomotiveWidth < _pictureWidth ) + if (_startPosX.HasValue && _startPosX + _drawningElectricLocomotiveWidth < _pictureWidth) { _startPosX = _pictureWidth - _drawningElectricLocomotiveWidth; } @@ -95,7 +110,8 @@ public class DrawningElectricLocomotive /// Координата Y public void SetPosition(int x, int y) { - if(!_pictureHeight.HasValue || !_pictureWidth.HasValue) { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { return; } @@ -104,12 +120,12 @@ public class DrawningElectricLocomotive _startPosY = y; - - if ( _drawningElectricLocomotiveHeight + y > _pictureHeight) + + if (_drawningElectricLocomotiveHeight + y > _pictureHeight) { _startPosY = _pictureHeight - _drawningElectricLocomotiveHeight; } - if ( _drawningElectricLocomotiveWidth + x > _pictureWidth) + if (_drawningElectricLocomotiveWidth + x > _pictureWidth) { _startPosX = _pictureWidth - _drawningElectricLocomotiveWidth; } @@ -133,39 +149,39 @@ public class DrawningElectricLocomotive /// true - перемещение выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if(EntityElectricLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } - switch(direction) + switch (direction) { //влево case DirectionType.Left: - if(_startPosX.Value - EntityElectricLocomotive.Step > 0) + if (_startPosX.Value - EntityLocomotive.Step > 0) { - _startPosX -= (int)EntityElectricLocomotive.Step; + _startPosX -= (int)EntityLocomotive.Step; } return true; //вверх case DirectionType.Up: - if(_startPosY.Value - EntityElectricLocomotive.Step > 0) + if (_startPosY.Value - EntityLocomotive.Step > 0) { - _startPosY -= (int)EntityElectricLocomotive.Step; - } + _startPosY -= (int)EntityLocomotive.Step; + } return true; //вправо case DirectionType.Right: - if (_startPosX.Value + _drawningElectricLocomotiveWidth + EntityElectricLocomotive.Step < _pictureWidth) + if (_startPosX.Value + _drawningElectricLocomotiveWidth + EntityLocomotive.Step < _pictureWidth) { - _startPosX += (int)EntityElectricLocomotive.Step; + _startPosX += (int)EntityLocomotive.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + _drawningElectricLocomotiveHeight + EntityElectricLocomotive.Step < _pictureHeight) + if (_startPosY.Value + _drawningElectricLocomotiveHeight + EntityLocomotive.Step < _pictureHeight) { - _startPosY += (int)EntityElectricLocomotive.Step; + _startPosY += (int)EntityLocomotive.Step; } return true; default: @@ -177,9 +193,9 @@ public class DrawningElectricLocomotive /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityElectricLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } @@ -189,34 +205,33 @@ public class DrawningElectricLocomotive Pen penSolid = new(Color.Black, 2); Pen penSolidYellow = new(Color.Yellow, 0.5f); Pen windowPen = new(Color.DeepSkyBlue); - Brush additionalBrush = new SolidBrush(EntityElectricLocomotive.AdditionalColor); Brush blackBrush = new SolidBrush(Color.Black); Brush whiteBrush = new SolidBrush(Color.White); //Инициализация опорных точек для прорисовки корпуса - Point pointStart = new Point(_startPosX.Value + 75, _startPosY.Value + 20); - Point point1 = new Point(_startPosX.Value + 75, _startPosY.Value + 5); - Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value + 5); - Point pointFinish = new Point(_startPosX.Value + 5, _startPosY.Value + 20); + Point pointStart = new Point(_startPosX.Value + 75, _startPosY.Value + 15); + Point point1 = new Point(_startPosX.Value + 75, _startPosY.Value); + Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value); + Point pointFinish = new Point(_startPosX.Value + 5, _startPosY.Value + 15); //Инициализация опорных точек для прорисовки первой "юбки" - Point point3 = new Point(_startPosX.Value + 7, _startPosY.Value + 37); - Point point4 = new Point(_startPosX.Value + 0, _startPosY.Value + 37 +6 ); - Point point5 = new Point(_startPosX.Value + 7, _startPosY.Value + 37 + 6 ); + Point point3 = new Point(_startPosX.Value + 7, _startPosY.Value + 32); + Point point4 = new Point(_startPosX.Value, _startPosY.Value + 32 + 6); + Point point5 = new Point(_startPosX.Value + 7, _startPosY.Value + 32 + 6); //Инициализация опорных точек для прорисовки второй "юбки" - Point point6 = new Point(_startPosX.Value + 69, _startPosY.Value + 37); - Point point7 = new Point(_startPosX.Value + 75 + 7, _startPosY.Value + 37 + 6); - Point point8 = new Point(_startPosX.Value + 69, _startPosY.Value + 37 + 6); - + Point point6 = new Point(_startPosX.Value + 69, _startPosY.Value + 32); + Point point7 = new Point(_startPosX.Value + 75 + 7, _startPosY.Value + 32 + 6); + Point point8 = new Point(_startPosX.Value + 69, _startPosY.Value + 32 + 6); + //Совокупность точек полигона уголка первой "юбки" Point[] firstTrianglePoints = { - + point3, point4, point5, - + }; //Совокупность точек полигона уголка второй "юбки" Point[] secondTrianglePoints = @@ -233,77 +248,50 @@ public class DrawningElectricLocomotive g.FillPolygon(blackBrush, secondTrianglePoints); //Прорисовка корпуса - g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 70, 17); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 15, 70, 17); g.DrawLine(pen, point3, point4); - + g.DrawLine(pen, pointStart, point1); g.DrawLine(pen, point1, point2); g.DrawLine(pen, point2, pointFinish); Brush brWhite = new SolidBrush(Color.White); - g.DrawRectangle(windowPen, _startPosX.Value + 24.3f, _startPosY.Value + 9, 8, 8); + g.DrawRectangle(windowPen, _startPosX.Value + 24.3f, _startPosY.Value + 4, 8, 8); - g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 14, 8, 12); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 9, 8, 12); - g.FillRectangle(brWhite, _startPosX.Value + 36, _startPosY.Value + 16, 7, 10); + g.FillRectangle(brWhite, _startPosX.Value + 36, _startPosY.Value + 11, 7, 10); //Прорисовка передней и задней "юбки" - g.FillRectangle(blackBrush, _startPosX.Value + 7, _startPosY.Value + 37, 25, 5.3f); - g.FillRectangle(blackBrush, _startPosX.Value + 47, _startPosY.Value + 37, 22, 5.3f); + g.FillRectangle(blackBrush, _startPosX.Value + 7, _startPosY.Value + 32, 25, 5.3f); + g.FillRectangle(blackBrush, _startPosX.Value + 47, _startPosY.Value + 32, 22, 5.3f); //Прорисовка двух передних колёс - g.FillEllipse(whiteBrush, _startPosX.Value + 6.3f, _startPosY.Value + 37, 10, 10); - g.DrawEllipse(penSolid, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8); - g.FillEllipse(additionalBrush, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8); - g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8); - g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8); + g.FillEllipse(whiteBrush, _startPosX.Value + 6.3f, _startPosY.Value + 32, 10, 10); + g.DrawEllipse(penSolid, _startPosX.Value + 9, _startPosY.Value + 32, 8, 8); + g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 32, 8, 8); + //Прорисовка двух задних колёс - g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 38, _startPosY.Value + 37, 10, 10); - g.DrawEllipse(penSolid, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8); - g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8); - g.DrawEllipse(penSolid, _startPosX.Value+ 25 + 37, _startPosY.Value + 37, 8, 8); - g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 37, 8, 8); + g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 38, _startPosY.Value + 32, 10, 10); + g.DrawEllipse(penSolid, _startPosX.Value + 25 + 26, _startPosY.Value + 32, 8, 8); + g.DrawEllipse(penSolid, _startPosX.Value + 25 + 37, _startPosY.Value + 32, 8, 8); //Прорисовка заднего "шлюза" - g.FillRectangle(blackBrush, _startPosX.Value + 75, _startPosY.Value + 9, 5.7f, 27.4f); + g.FillRectangle(blackBrush, _startPosX.Value + 75, _startPosY.Value + 4, 5.7f, 27.4f); //Прорисовка первого и третьего окна - g.DrawRectangle(windowPen, _startPosX.Value + 12, _startPosY.Value + 9, 8, 8); - g.DrawRectangle(windowPen, _startPosX.Value + 63, _startPosY.Value + 9, 8, 8); + g.DrawRectangle(windowPen, _startPosX.Value + 12, _startPosY.Value + 4, 8, 8); + g.DrawRectangle(windowPen, _startPosX.Value + 63, _startPosY.Value + 4, 8, 8); + //Опциональная прорисовка цвета передних колёс + g.FillEllipse(whiteBrush, _startPosX.Value + 9, _startPosY.Value + 32, 8, 8); + g.FillEllipse(whiteBrush, _startPosX.Value + 24, _startPosY.Value + 32, 8, 8); - - if (EntityElectricLocomotive.ElectricHorns) - { - - - //Инициализация опорных точек для прорисовки "рогов" - Point pointHorns1 = new Point(_startPosX.Value + 13, _startPosY.Value + 5); - Point pointHorns2 = new Point(_startPosX.Value + 16, _startPosY.Value + 2); - Point pointHorns3 = new Point(_startPosX.Value + 11, _startPosY.Value); - - //Прорисовка "рогов" электровоза - g.DrawLine(penSolid, pointHorns1, pointHorns2); - g.DrawLine(penSolid, pointHorns2, pointHorns3); - } - if(EntityElectricLocomotive.BatteryPlacement) - { - //Инициализация опорных точек для прорисовки молнии на хранилище батарей - Point pointLightning1 = new Point(_startPosX.Value + 39, _startPosY.Value + 37); - Point pointLightning2 = new Point(_startPosX.Value + 37, _startPosY.Value + 39); - Point pointLightning3 = new Point(_startPosX.Value + 39, _startPosY.Value + 40); - Point pointLightning4 = new Point(_startPosX.Value + 37, _startPosY.Value + 41); - - //Прорисовка "хранилища батарей" электровоза - g.FillRectangle(blackBrush, _startPosX.Value + 36, _startPosY.Value + 37, 8, 4.5f); - g.DrawLine(penSolidYellow, pointLightning1, pointLightning2); - g.DrawLine(penSolidYellow, pointLightning2, pointLightning3); - g.DrawLine(penSolidYellow, pointLightning3, pointLightning4); - - } - + //Опциональная прорисовка цвета задних колёс + g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 32, 8, 8); + g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 32, 8, 8); } } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityElectricLocomotive.cs similarity index 57% rename from ProjectElectricLocomotive/ProjectElectricLocomotive/EntityElectricLocomotive.cs rename to ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityElectricLocomotive.cs index 0a3040f..9c0ac12 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityElectricLocomotive.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityElectricLocomotive.cs @@ -1,26 +1,11 @@  -namespace ProjectElectricLocomotive; +namespace ProjectElectricLocomotive.Entities; /// -/// Класс-сущность "Тепловоз" +/// Класс-сущность "Электровоз" /// -public class EntityElectricLocomotive +public class EntityElectricLocomotive : EntityLocomotive { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет (для дополнительных элементов) /// @@ -36,11 +21,6 @@ public class EntityElectricLocomotive /// public bool BatteryPlacement { get; private set; } - /// - /// Шаг перемещения объекта - /// - public double Step => Speed * 100 / Weight; - /// /// Инициализация полей объекта-класса тепловоза /// @@ -51,14 +31,10 @@ public class EntityElectricLocomotive /// /// - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) + public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; ElectricHorns = electricHorns; BatteryPlacement = batteryPlacement; - } } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityLocomotive.cs new file mode 100644 index 0000000..52007b7 --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Entities/EntityLocomotive.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive.Entities; +/// +/// Класс-сущность "Локомотив" +/// +public class EntityLocomotive +{ + /// + /// Скорость + /// + 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 EntityLocomotive(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs index 577dbcc..dcf94c2 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs @@ -34,6 +34,7 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); + buttonCreateLocomotive = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit(); SuspendLayout(); // @@ -49,11 +50,11 @@ // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 430); + buttonCreate.Location = new Point(12, 436); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(104, 37); + buttonCreate.Size = new Size(150, 31); buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; + buttonCreate.Text = "Создать электровоз"; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += ButtonCreate_Click; // @@ -109,11 +110,23 @@ buttonUp.UseVisualStyleBackColor = false; buttonUp.Click += ButtonMove_Click; // + // buttonCreateLocomotive + // + buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateLocomotive.Location = new Point(187, 436); + buttonCreateLocomotive.Name = "buttonCreateLocomotive"; + buttonCreateLocomotive.Size = new Size(150, 31); + buttonCreateLocomotive.TabIndex = 6; + buttonCreateLocomotive.Text = "Создать локомотив"; + buttonCreateLocomotive.UseVisualStyleBackColor = true; + buttonCreateLocomotive.Click += buttonCreateLocomotive_Click; + // // FormElectricLocomotive // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(866, 479); + Controls.Add(buttonCreateLocomotive); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -134,5 +147,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateLocomotive; } } \ No newline at end of file diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs index d788b47..52bc870 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs @@ -1,4 +1,5 @@ -using System; +using ProjectElectricLocomotive.Drawnings; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,7 +13,7 @@ namespace ProjectElectricLocomotive; public partial class FormElectricLocomotive : Form { - private DrawningElectricLocomotive? _drawningElectricLocomotive; + private DrawningLocomotive? _drawningLocomotive; public FormElectricLocomotive() { @@ -24,34 +25,55 @@ public partial class FormElectricLocomotive : Form /// private void Draw() { - if (_drawningElectricLocomotive == null) + if (_drawningLocomotive == null) { return; } Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningElectricLocomotive.DrawTransport(gr); + _drawningLocomotive.DrawTransport(gr); pictureBoxElectricLocomotive.Image = bmp; } - private void ButtonCreate_Click(object sender, EventArgs e) + private void CreateObject(string type) { Random random = new(); - _drawningElectricLocomotive = new DrawningElectricLocomotive(); - _drawningElectricLocomotive.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))); - _drawningElectricLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height); - _drawningElectricLocomotive.SetPosition(random.Next(0,pictureBoxElectricLocomotive.Width), random.Next(0,pictureBoxElectricLocomotive.Height)); - - Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningElectricLocomotive.DrawTransport(gr); - pictureBoxElectricLocomotive.Image = bmp; + switch (type) + { + case nameof(DrawningLocomotive): + _drawningLocomotive = new DrawningLocomotive(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(DrawningElectricLocomotive): + _drawningLocomotive = new DrawningElectricLocomotive(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; + } + _drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height); + _drawningLocomotive.SetPosition(random.Next(10,100), random.Next(10,100)); + Draw(); } + /// + /// Обработка нажатия кнопки "Создать электровоз" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive)); + + /// + /// Обработка нажатия кнопки "Создать локомотив" + /// + /// + /// + private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); + + /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -59,7 +81,7 @@ public partial class FormElectricLocomotive : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningElectricLocomotive == null) + if (_drawningLocomotive == null) { return; } @@ -69,19 +91,19 @@ public partial class FormElectricLocomotive : Form { case "buttonUp": result = - _drawningElectricLocomotive.MoveTransport(DirectionType.Up); + _drawningLocomotive.MoveTransport(DirectionType.Up); break; case "buttonDown": result = - _drawningElectricLocomotive.MoveTransport(DirectionType.Down); + _drawningLocomotive.MoveTransport(DirectionType.Down); break; case "buttonLeft": result = - _drawningElectricLocomotive.MoveTransport(DirectionType.Left); + _drawningLocomotive.MoveTransport(DirectionType.Left); break; case "buttonRight": result = - _drawningElectricLocomotive.MoveTransport(DirectionType.Right); + _drawningLocomotive.MoveTransport(DirectionType.Right); break; } if (result) @@ -89,6 +111,8 @@ public partial class FormElectricLocomotive : Form Draw(); } } + + }