From 5e18d0afbe5fe359f7bbee0ea108421b41362985 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:35:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/DirectionType.cs | 32 ++++ .../RPP_FirstLaba_Tractor/DrawingTractor.cs | 180 ++++++++++++++++++ ...m1.Designer.cs => FormTractor.Designer.cs} | 2 +- .../{Form1.cs => FormTractor.cs} | 4 +- .../{Form1.resx => FormTractor.resx} | 0 .../RPP_FirstLaba_Tractor/Program.cs | 2 +- .../RPP_FirstLaba_Tractor/Tractor.cs | 43 +++++ .../RPP_FirstLaba_Tractor/TypeDirection.cs | 8 + 8 files changed, 267 insertions(+), 4 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DirectionType.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawingTractor.cs rename RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/{Form1.Designer.cs => FormTractor.Designer.cs} (97%) rename RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/{Form1.cs => FormTractor.cs} (57%) rename RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/{Form1.resx => FormTractor.resx} (100%) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Tractor.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TypeDirection.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DirectionType.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DirectionType.cs new file mode 100644 index 0000000..0df4961 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DirectionType.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RPP_FirstLaba_Tractor +{ + /// + /// Направление перемещения + /// + public enum DirectionType + { + /// + /// /// Вверх + /// /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + + } +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawingTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawingTractor.cs new file mode 100644 index 0000000..d354f33 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawingTractor.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RPP_FirstLaba_Tractor +{ + internal class DrawningTractor + { + /// + /// Класс-сущность + /// + public EntityTractor? EntityTractor { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + private int _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + private readonly int _tractorWidth = 80; + /// + /// Высота прорисовки автомобиля + /// + private readonly int _tractorHeight = 60; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах + public bool Init(int speed, double weight, Color bodyColor, int width, int height) + { + + _pictureWidth = width; + _pictureHeight = height; + if (_tractorWidth > _pictureHeight || _tractorHeight > _pictureHeight) + { + _pictureWidth = 2 * _tractorWidth; + _pictureHeight = 2 * _tractorHeight; + + } + EntityTractor = new EntityTractor(); + EntityTractor.Init(speed, weight, bodyColor); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + _startPosX = x; + _startPosY = y; + + if ((x + _tractorWidth > _pictureWidth) || (y + _pictureHeight > _pictureHeight)) + { + Random random = new(); + x = random.Next(0, _pictureWidth); + x = random.Next(0, _pictureHeight); + } + } + /// + /// Изменение направления перемещения + /// + /// Направление + /// + + public void MoveTransport(DirectionType direction) + { + if (EntityTractor == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityTractor.Step > 0) + { + _startPosX -= (int)EntityTractor.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityTractor.Step > 0) + { + _startPosY -= (int)EntityTractor.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + _tractorWidth + EntityTractor.Step < _pictureWidth) + { + _startPosX += (int)EntityTractor.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + _tractorHeight + EntityTractor.Step < _pictureHeight) + { + _startPosY += (int)EntityTractor.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityTractor == null) + { + return; + } + Pen pen = new(Color.Black); + Brush brGray = new SolidBrush(Color.Gray); + Brush brBlack = new SolidBrush(Color.Black); + Brush additionalBrush = new + SolidBrush(EntityTractor.BodyColor); + + //Гусеницы + g.FillEllipse(brGray, _startPosX, _startPosY + 41, 25, 25); + g.FillEllipse(brGray, _startPosX + 55, _startPosY + 41, 25, 25); + g.FillRectangle(brGray, _startPosX + 13, _startPosY + 41, 54, 25); + //колеса + g.FillEllipse(brBlack, _startPosX, _startPosY + 45, 15, 15); + g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 45, 15, 15); + g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 55, 10, 10); + g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 55, 10, 10); + g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 55, 10, 10); + g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 40, 10, 10); + g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 40, 10, 10); + //кузов + g.FillRectangle(additionalBrush, _startPosX, _startPosY + 20, 80, 20); + g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY, 10, 20); + g.FillRectangle(additionalBrush, _startPosX, _startPosY, 40, 20); + + //Окно + Brush brBlue = new SolidBrush(Color.Blue); + g.FillRectangle(brBlue, _startPosX + 10, _startPosY + 3, 25, 15); + + //Колеса + g.FillEllipse(additionalBrush, _startPosX + 2, _startPosY + 47, 11, 11); + g.FillEllipse(additionalBrush, _startPosX + 67, _startPosY + 47, 11, 11); + g.FillEllipse(additionalBrush, _startPosX + 37, _startPosY + 57, 6, 6); + g.FillEllipse(additionalBrush, _startPosX + 22, _startPosY + 57, 6, 6); + g.FillEllipse(additionalBrush, _startPosX + 52, _startPosY + 57, 6, 6); + g.FillEllipse(additionalBrush, _startPosX + 27, _startPosY + 42, 6, 6); + g.FillEllipse(additionalBrush, _startPosX + 47, _startPosY + 42, 6, 6); + + //границы трактора + g.DrawRectangle(pen, _startPosX, _startPosY + 20, 80, 20); + g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20); + g.DrawRectangle(pen, _startPosX, _startPosY, 40, 20); + } + } +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs similarity index 97% rename from RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.Designer.cs rename to RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs index 25ca53f..37d6df4 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.Designer.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs @@ -1,6 +1,6 @@ namespace RPP_FirstLaba_Tractor { - partial class Form1 + partial class FormTractor { /// /// Required designer variable. diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs similarity index 57% rename from RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.cs rename to RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs index 4f2d728..4545fc6 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs @@ -1,8 +1,8 @@ namespace RPP_FirstLaba_Tractor { - public partial class Form1 : Form + public partial class FormTractor : Form { - public Form1() + public FormTractor() { InitializeComponent(); } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.resx b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.resx similarity index 100% rename from RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Form1.resx rename to RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.resx diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs index c61cbe8..7556447 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs @@ -11,7 +11,7 @@ namespace RPP_FirstLaba_Tractor // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormTractor()); } } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Tractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Tractor.cs new file mode 100644 index 0000000..843b95c --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Tractor.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RPP_FirstLaba_Tractor +{ + public class EntityTractor + { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + public double Step => (double)Speed * 100 / Weight; + /// + /// Инициализация полей объекта-класса спортивного автомобиля + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public void Init(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + + } +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TypeDirection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TypeDirection.cs new file mode 100644 index 0000000..d555ecb --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TypeDirection.cs @@ -0,0 +1,8 @@ +using System; + +public class Class1 +{ + public Class1() + { + } +}