From d4d7eb2b95af6fa5912fc42e80c10d46a92efa43 Mon Sep 17 00:00:00 2001 From: TEma Date: Tue, 4 Feb 2025 13:56:16 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201,=20=D0=A1?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrLaba1/PrLaba1/Direction.cs | 22 ++ PrLaba1/PrLaba1/DiselLoko.cs | 53 ++++ PrLaba1/PrLaba1/DrawningDiselLoko.cs | 238 ++++++++++++++++++ PrLaba1/PrLaba1/Form1.Designer.cs | 39 --- PrLaba1/PrLaba1/Form1.cs | 10 - PrLaba1/PrLaba1/FormDiselLoko.Designer.cs | 121 +++++++++ PrLaba1/PrLaba1/FormDiselLoko.cs | 20 ++ PrLaba1/PrLaba1/FormDiselLoko.resx | 154 ++++++++++++ PrLaba1/PrLaba1/PrLaba1.csproj | 15 ++ .../PrLaba1/Properties/Resources.Designer.cs | 63 +++++ .../{Form1.resx => Properties/Resources.resx} | 0 11 files changed, 686 insertions(+), 49 deletions(-) create mode 100644 PrLaba1/PrLaba1/Direction.cs create mode 100644 PrLaba1/PrLaba1/DiselLoko.cs create mode 100644 PrLaba1/PrLaba1/DrawningDiselLoko.cs delete mode 100644 PrLaba1/PrLaba1/Form1.Designer.cs delete mode 100644 PrLaba1/PrLaba1/Form1.cs create mode 100644 PrLaba1/PrLaba1/FormDiselLoko.Designer.cs create mode 100644 PrLaba1/PrLaba1/FormDiselLoko.cs create mode 100644 PrLaba1/PrLaba1/FormDiselLoko.resx create mode 100644 PrLaba1/PrLaba1/Properties/Resources.Designer.cs rename PrLaba1/PrLaba1/{Form1.resx => Properties/Resources.resx} (100%) diff --git a/PrLaba1/PrLaba1/Direction.cs b/PrLaba1/PrLaba1/Direction.cs new file mode 100644 index 0000000..613ab90 --- /dev/null +++ b/PrLaba1/PrLaba1/Direction.cs @@ -0,0 +1,22 @@ +namespace PrLaba1; + +public enum Direction +{ + /// + ///Вверх + /// + Up = 1, + /// + ///Вниз + /// + Down = 2, + /// + ///Влево + /// + Left = 3, + /// + /// Направо + /// + Right = 4 + +} diff --git a/PrLaba1/PrLaba1/DiselLoko.cs b/PrLaba1/PrLaba1/DiselLoko.cs new file mode 100644 index 0000000..a382ca3 --- /dev/null +++ b/PrLaba1/PrLaba1/DiselLoko.cs @@ -0,0 +1,53 @@ +using System.Drawing; + +namespace PrLaba1; +public class DiselLoko +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// вес + /// + public double Weight { get; private set; } + /// + /// Цвет тела + /// + public Color ColorBody { get; private set; } + /// + /// цвет колеса + /// + public Color ColorWheel { get; private set; } + /// + /// Признак езды + /// + public bool IsTube { get; private set; } + /// + /// Признак заполненности + /// + public bool IsComportament { get; private set; } + /// + /// шаг, перемещенние обьекта + /// + public double Step => Speed * 100 / Weight; + + /// + /// + /// + /// + /// + /// + /// + /// + /// + public void Init(int speed, double weight, Color colorBody, Color colorWheel, bool isTube, bool isComportament) + { + Speed = speed; + Weight = weight; + ColorBody = colorBody; + ColorWheel = colorWheel; + IsTube = isTube; + IsComportament = isComportament; + } +} diff --git a/PrLaba1/PrLaba1/DrawningDiselLoko.cs b/PrLaba1/PrLaba1/DrawningDiselLoko.cs new file mode 100644 index 0000000..5e5aa59 --- /dev/null +++ b/PrLaba1/PrLaba1/DrawningDiselLoko.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrLaba1; + +public class DrawningDiselLoko +{ + /// + ///Класс-сущность + /// + public DiselLoko? DiselLoko { get; private set; } + + /// + ///Ширина окна + /// + private int? _pictureWidth; + + /// + ///Высота окна + /// + private int? _pictureHeight; + + /// + ///Левая координата прорисовки тепловоза + /// + private int? _startPosX; + + /// + ///Верхняя координата прорисовки тепловоза + /// + private int? _startPosY; + + /// + ///Ширина прорисовки тепловоза + /// + private readonly int _drawingCarWidth = 0; + + /// + ///Высота прорисовки тепловоза + /// + private readonly int _drawingCarHeight = 0; + + /// + ///Иницилизация + /// + /// Скорость + /// Вес + /// Цвет тела + /// Цвет колёс + /// Признак езды + /// Признак заполнености + + public void Init(int speed, double weight, Color colorBody, Color colorWheel, bool isTube, bool isComportament) + { + DiselLoko = new DiselLoko(); + DiselLoko.Init(speed, weight, colorBody, colorWheel, isTube, isComportament); + _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(Direction direction) + { + if (DiselLoko == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case Direction.Left: + if (_startPosX.Value - DiselLoko.Step > 0) + { + _startPosX -= (int)DiselLoko.Step; + } + return true; + //вверх + case Direction.Up: + if (_startPosY.Value - DiselLoko.Step > 0) + { + _startPosY -= (int)DiselLoko.Step; + } + return true; + // вправо + case Direction.Right: + //TODO прописать логику сдвига в право + return true; + //вниз + case Direction.Down: + //TODO прописать логику сдвига в вниз + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (DiselLoko == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(DiselLoko.ColorBody); + + // труба + if (DiselLoko.IsTube) + { + g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, 15, 15); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15); + + g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value, 20, 20); + g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15); + + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20); + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, 20, 20); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 20, 40); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value, 14, 15); + g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 14, 15); + + g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 20, 20); + g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 1, _startPosY.Value + 10, 25, 40); + g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15); + + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 39, 15); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 45, 39, 15); + + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 1, 40, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 45, 40, 15); + } + + //границы автомобиля + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20); + g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, 30); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30); + g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, 52); + + //задние фары + Brush brRed = new SolidBrush(Color.Red); + g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20); + g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); + + //передние фары + Brush brYellow = new SolidBrush(Color.Yellow); + g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20); + g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20); + + //кузов + Brush br = new SolidBrush(DiselLoko.ColorBody); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, 30); + g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30); + g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, 50); + + //стекла + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10, 5, 40); + g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10, 5, 40); + g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8, 35, 2); + g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51, 35, 2); + + //выделяем рамкой крышу + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10, 35, 40); + g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15, 25, 30); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 15, 30); + + // отсек + if (DiselLoko.IsComportament) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 23, 25, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 23, 35, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 23, 20, 15); + } + + //// крыло + //if (DiselLoko.Wing) + //{ + // g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 5, 10, 50); + // g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 10, 50); + //} + } +} diff --git a/PrLaba1/PrLaba1/Form1.Designer.cs b/PrLaba1/PrLaba1/Form1.Designer.cs deleted file mode 100644 index 2abd3f6..0000000 --- a/PrLaba1/PrLaba1/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PrLaba1 -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/PrLaba1/PrLaba1/Form1.cs b/PrLaba1/PrLaba1/Form1.cs deleted file mode 100644 index 62c39d4..0000000 --- a/PrLaba1/PrLaba1/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PrLaba1 -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs b/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs new file mode 100644 index 0000000..020be6c --- /dev/null +++ b/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs @@ -0,0 +1,121 @@ +namespace PrLaba1 +{ + partial class FormDiselLoko + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDiselLoko)); + pictureBoxDiselLoko = new PictureBox(); + button1 = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + ButtonLeft = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).BeginInit(); + SuspendLayout(); + // + // pictureBoxDiselLoko + // + pictureBoxDiselLoko.Dock = DockStyle.Fill; + pictureBoxDiselLoko.Location = new Point(0, 0); + pictureBoxDiselLoko.Name = "pictureBoxDiselLoko"; + pictureBoxDiselLoko.Size = new Size(800, 450); + pictureBoxDiselLoko.TabIndex = 0; + pictureBoxDiselLoko.TabStop = false; + // + // button1 + // + button1.Location = new Point(12, 415); + button1.Name = "button1"; + button1.Size = new Size(75, 23); + button1.TabIndex = 1; + button1.Text = "Создать"; + button1.UseVisualStyleBackColor = true; + // + // buttonUp + // + buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); + buttonUp.Location = new Point(721, 372); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 2; + buttonUp.UseVisualStyleBackColor = true; + // + // buttonDown + // + buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); + buttonDown.Location = new Point(721, 403); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 3; + buttonDown.UseVisualStyleBackColor = true; + // + // buttonRight + // + buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); + buttonRight.Location = new Point(753, 403); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + // + // ButtonLeft + // + ButtonLeft.BackgroundImage = (Image)resources.GetObject("ButtonLeft.BackgroundImage"); + ButtonLeft.Location = new Point(689, 403); + ButtonLeft.Name = "ButtonLeft"; + ButtonLeft.Size = new Size(35, 35); + ButtonLeft.TabIndex = 5; + ButtonLeft.UseVisualStyleBackColor = true; + // + // FormDiselLoko + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(ButtonLeft); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(button1); + Controls.Add(pictureBoxDiselLoko); + Name = "FormDiselLoko"; + Text = "Тепловоз"; + ((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxDiselLoko; + private Button button1; + private Button buttonUp; + private Button buttonDown; + private Button buttonRight; + private Button ButtonLeft; + } +} \ No newline at end of file diff --git a/PrLaba1/PrLaba1/FormDiselLoko.cs b/PrLaba1/PrLaba1/FormDiselLoko.cs new file mode 100644 index 0000000..fed2d63 --- /dev/null +++ b/PrLaba1/PrLaba1/FormDiselLoko.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrLaba1 +{ + public partial class FormDiselLoko : Form + { + public FormDiselLoko() + { + InitializeComponent(); + } + } +} diff --git a/PrLaba1/PrLaba1/FormDiselLoko.resx b/PrLaba1/PrLaba1/FormDiselLoko.resx new file mode 100644 index 0000000..d39db97 --- /dev/null +++ b/PrLaba1/PrLaba1/FormDiselLoko.resx @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAAIdJREFUSEvtzFsOgCAMRFH3v2kkcjUFC6U+MCacP+jMLOE1c7rgmF42PDr0RtNu + wpelK8ekwKHJDjGW49Z0cTriXGckmKkgVPHRNANNRDXVG1ULac3d6YjCiX6g1I1abuw0cSfKQvlF0I++ + 8Nh0xMRu4HRE0ImyoHwdKDUR1czpwpwu/HE6hBWbVcKS8nHq8gAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAAIVJREFUSEvtzFsKgDAMRFH3v+k6yBXsI22iUkF6PpOZ2ZJtcyDasqYLa7rwm2lK + QZQvyhPBW5g4TZwWgnH0T69NU75onIS4G7Xc9Gmh5EChYj6E6gjpytNpoi29nzBgIGT4blqYqfC2jRPC + WI6f7eY0jy5XSJg8cBrx5iS0K4Fo1JrOpLQD0c/CkunHhukAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAAIZJREFUSEvtzUkOgCAMQFHuf2lM4JMgMnSAuOHtbMs3xGNuuvFfOhR8a8zeUC2Y + iinSGTsBdTrjYopTAwJj3JmR6eHCidgbOz96FRZbkCyY7kI1YbQL1YTRFiQLpn70Kiw8KH2wNiPTw4UB + gTHLb1mvqNPsBBRppmKLB7ZoZnwmcdONY+kYH/QlwpJxqZGzAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wgAADsIBFShKgAAAAJNJREFUSEvt0EEOgCAMBVHuf2k0MBiRr0CLiQvfjraZBSG+5k9ffC8dEh43ptM5 + emCqTKSJ1dgpo2lKDdZKP03DgIDChRmZBmsPSics/OgVTJcgmTBahWrCaBWqBdMlSJ6w8KNXY+dETOHC + jMw97gwIPOJU4UIZSmfEauyUiXRGsmCqTKd3VHufaUkP+tMXr6Vj3AB4/8KSzy1jIwAAAABJRU5ErkJg + gg== + + + \ No newline at end of file diff --git a/PrLaba1/PrLaba1/PrLaba1.csproj b/PrLaba1/PrLaba1/PrLaba1.csproj index 663fdb8..af03d74 100644 --- a/PrLaba1/PrLaba1/PrLaba1.csproj +++ b/PrLaba1/PrLaba1/PrLaba1.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/PrLaba1/PrLaba1/Properties/Resources.Designer.cs b/PrLaba1/PrLaba1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d610289 --- /dev/null +++ b/PrLaba1/PrLaba1/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace PrLaba1.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PrLaba1.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/PrLaba1/PrLaba1/Form1.resx b/PrLaba1/PrLaba1/Properties/Resources.resx similarity index 100% rename from PrLaba1/PrLaba1/Form1.resx rename to PrLaba1/PrLaba1/Properties/Resources.resx -- 2.25.1 From ac77bf9edc7c21a793c0f9be8678ecb4bf608678 Mon Sep 17 00:00:00 2001 From: TEma Date: Tue, 4 Feb 2025 14:41:30 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202,=20=D0=B4?= =?UTF-8?q?=D0=B2=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D1=88?= =?UTF-8?q?=D0=B8=D0=BD=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrLaba1/PrLaba1/DrawningDiselLoko.cs | 14 ++-- PrLaba1/PrLaba1/FormDiselLoko.Designer.cs | 25 ++++--- PrLaba1/PrLaba1/FormDiselLoko.cs | 87 ++++++++++++++++++++--- PrLaba1/PrLaba1/FormDiselLoko.resx | 8 +-- PrLaba1/PrLaba1/Program.cs | 2 +- 5 files changed, 106 insertions(+), 30 deletions(-) diff --git a/PrLaba1/PrLaba1/DrawningDiselLoko.cs b/PrLaba1/PrLaba1/DrawningDiselLoko.cs index 5e5aa59..6238264 100644 --- a/PrLaba1/PrLaba1/DrawningDiselLoko.cs +++ b/PrLaba1/PrLaba1/DrawningDiselLoko.cs @@ -36,12 +36,12 @@ public class DrawningDiselLoko /// ///Ширина прорисовки тепловоза /// - private readonly int _drawingCarWidth = 0; + private readonly int _drawingCarWidth = 110; /// ///Высота прорисовки тепловоза /// - private readonly int _drawingCarHeight = 0; + private readonly int _drawingCarHeight = 60; /// ///Иницилизация @@ -124,11 +124,17 @@ public class DrawningDiselLoko return true; // вправо case Direction.Right: - //TODO прописать логику сдвига в право + if (_startPosX.Value - DiselLoko.Step > 0) + { + _startPosX += (int)DiselLoko.Step; + } return true; //вниз case Direction.Down: - //TODO прописать логику сдвига в вниз + if (_startPosX.Value - DiselLoko.Step > 0) + { + _startPosY += (int)DiselLoko.Step; + } return true; default: return false; diff --git a/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs b/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs index 020be6c..c96b099 100644 --- a/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs +++ b/PrLaba1/PrLaba1/FormDiselLoko.Designer.cs @@ -30,7 +30,7 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDiselLoko)); pictureBoxDiselLoko = new PictureBox(); - button1 = new Button(); + create = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); @@ -47,14 +47,15 @@ pictureBoxDiselLoko.TabIndex = 0; pictureBoxDiselLoko.TabStop = false; // - // button1 + // create // - button1.Location = new Point(12, 415); - button1.Name = "button1"; - button1.Size = new Size(75, 23); - button1.TabIndex = 1; - button1.Text = "Создать"; - button1.UseVisualStyleBackColor = true; + create.Location = new Point(12, 415); + create.Name = "create"; + create.Size = new Size(75, 23); + create.TabIndex = 1; + create.Text = "Создать"; + create.UseVisualStyleBackColor = true; + create.Click += ButtonCreate_Click; // // buttonUp // @@ -64,6 +65,7 @@ buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 2; buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; // // buttonDown // @@ -73,6 +75,7 @@ buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 3; buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; // // buttonRight // @@ -82,6 +85,7 @@ buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 4; buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; // // ButtonLeft // @@ -91,6 +95,7 @@ ButtonLeft.Size = new Size(35, 35); ButtonLeft.TabIndex = 5; ButtonLeft.UseVisualStyleBackColor = true; + ButtonLeft.Click += ButtonMove_Click; // // FormDiselLoko // @@ -101,7 +106,7 @@ Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); - Controls.Add(button1); + Controls.Add(create); Controls.Add(pictureBoxDiselLoko); Name = "FormDiselLoko"; Text = "Тепловоз"; @@ -112,7 +117,7 @@ #endregion private PictureBox pictureBoxDiselLoko; - private Button button1; + private Button create; private Button buttonUp; private Button buttonDown; private Button buttonRight; diff --git a/PrLaba1/PrLaba1/FormDiselLoko.cs b/PrLaba1/PrLaba1/FormDiselLoko.cs index fed2d63..8033581 100644 --- a/PrLaba1/PrLaba1/FormDiselLoko.cs +++ b/PrLaba1/PrLaba1/FormDiselLoko.cs @@ -1,20 +1,85 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace PrLaba1 +namespace PrLaba1 +/// +/// Форма работы с объектом "Тепловоз" +/// { public partial class FormDiselLoko : Form { + /// + /// Поле-объект для прорисовки объекта + /// + private DrawningDiselLoko? _drawningDiselLoko; + + /// + /// Метод прорисовки машины + /// + private void Draw() + { + if (_drawningDiselLoko == null) + { + return; + } + + Bitmap bmp = new(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningDiselLoko.DrawTransport(gr); + pictureBoxDiselLoko.Image = bmp; + } + + /// + /// Конструктор формы + /// public FormDiselLoko() { InitializeComponent(); } + + /// + /// Кнопка создать + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new Random(); + _drawningDiselLoko = new DrawningDiselLoko(); + _drawningDiselLoko.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))); + _drawningDiselLoko.SetPictureSize(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height); + _drawningDiselLoko.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningDiselLoko == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + bool result = false; + switch (name) + { + case "buttonUp": + result = _drawningDiselLoko.MoveTransport(Direction.Up); + break; + case "buttonDown": + result = _drawningDiselLoko.MoveTransport(Direction.Down); + break; + case "ButtonLeft": + result = _drawningDiselLoko.MoveTransport(Direction.Left); + break; + case "buttonRight": + result = _drawningDiselLoko.MoveTransport(Direction.Right); + break; + } + + if (result) + { + Draw(); + } + } } } diff --git a/PrLaba1/PrLaba1/FormDiselLoko.resx b/PrLaba1/PrLaba1/FormDiselLoko.resx index d39db97..7599b2b 100644 --- a/PrLaba1/PrLaba1/FormDiselLoko.resx +++ b/PrLaba1/PrLaba1/FormDiselLoko.resx @@ -121,7 +121,7 @@ iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAAIdJREFUSEvtzFsOgCAMRFH3v2kkcjUFC6U+MCacP+jMLOE1c7rgmF42PDr0RtNu + wAAADsABataJCQAAAIdJREFUSEvtzFsOgCAMRFH3v2kkcjUFC6U+MCacP+jMLOE1c7rgmF42PDr0RtNu wpelK8ekwKHJDjGW49Z0cTriXGckmKkgVPHRNANNRDXVG1ULac3d6YjCiX6g1I1abuw0cSfKQvlF0I++ 8Nh0xMRu4HRE0ImyoHwdKDUR1czpwpwu/HE6hBWbVcKS8nHq8gAAAABJRU5ErkJggg== @@ -129,7 +129,7 @@ iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAAIVJREFUSEvtzFsKgDAMRFH3v+k6yBXsI22iUkF6PpOZ2ZJtcyDasqYLa7rwm2lK + wAAADsABataJCQAAAIVJREFUSEvtzFsKgDAMRFH3v+k6yBXsI22iUkF6PpOZ2ZJtcyDasqYLa7rwm2lK QZQvyhPBW5g4TZwWgnH0T69NU75onIS4G7Xc9Gmh5EChYj6E6gjpytNpoi29nzBgIGT4blqYqfC2jRPC WI6f7eY0jy5XSJg8cBrx5iS0K4Fo1JrOpLQD0c/CkunHhukAAAAASUVORK5CYII= @@ -137,7 +137,7 @@ iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAAIZJREFUSEvtzUkOgCAMQFHuf2lM4JMgMnSAuOHtbMs3xGNuuvFfOhR8a8zeUC2Y + wAAADsABataJCQAAAIZJREFUSEvtzUkOgCAMQFHuf2lM4JMgMnSAuOHtbMs3xGNuuvFfOhR8a8zeUC2Y iinSGTsBdTrjYopTAwJj3JmR6eHCidgbOz96FRZbkCyY7kI1YbQL1YTRFiQLpn70Kiw8KH2wNiPTw4UB gTHLb1mvqNPsBBRppmKLB7ZoZnwmcdONY+kYH/QlwpJxqZGzAAAAAElFTkSuQmCC @@ -145,7 +145,7 @@ iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wgAADsIBFShKgAAAAJNJREFUSEvt0EEOgCAMBVHuf2k0MBiRr0CLiQvfjraZBSG+5k9ffC8dEh43ptM5 + wAAADsABataJCQAAAJNJREFUSEvt0EEOgCAMBVHuf2k0MBiRr0CLiQvfjraZBSG+5k9ffC8dEh43ptM5 emCqTKSJ1dgpo2lKDdZKP03DgIDChRmZBmsPSics/OgVTJcgmTBahWrCaBWqBdMlSJ6w8KNXY+dETOHC jMw97gwIPOJU4UIZSmfEauyUiXRGsmCqTKd3VHufaUkP+tMXr6Vj3AB4/8KSzy1jIwAAAABJRU5ErkJg gg== diff --git a/PrLaba1/PrLaba1/Program.cs b/PrLaba1/PrLaba1/Program.cs index cf70746..f958083 100644 --- a/PrLaba1/PrLaba1/Program.cs +++ b/PrLaba1/PrLaba1/Program.cs @@ -11,7 +11,7 @@ namespace PrLaba1 // 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 FormDiselLoko()); } } } \ No newline at end of file -- 2.25.1