From da86c334a4c094cb074896963d62d4c9c0aa91ab Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 15:50:46 +0400 Subject: [PATCH 01/11] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 5 ++--- Locomotive/Locomotive/EntityLocomotive.cs | 2 +- Locomotive/Locomotive/FormLocomotive.cs | 5 +---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 7d8650e..e7c864b 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -25,10 +25,9 @@ namespace Locomotive private readonly int _locomotiveHeight = 50; /// Инициализация свойств - public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity) + public DrawningLocomotive(int speed, float weight, Color bodyColor) { - Locomotive = entity; - Locomotive.Init(speed, weight, bodyColor); + Locomotive = new EntityLocomotive(speed, weight, bodyColor); } /// Установка позиции локомотива public void SetPosition(int x, int y, int width, int height) diff --git a/Locomotive/Locomotive/EntityLocomotive.cs b/Locomotive/Locomotive/EntityLocomotive.cs index 1e407d0..a546746 100644 --- a/Locomotive/Locomotive/EntityLocomotive.cs +++ b/Locomotive/Locomotive/EntityLocomotive.cs @@ -17,7 +17,7 @@ namespace Locomotive /// Шаг перемещения локомотива public float Step => Speed * 100 / Weight; - public void Init(int speed, float weight, Color bodyColor) + public EntityLocomotive(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 211a8a6..cb904e7 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -3,7 +3,6 @@ namespace Locomotive public partial class FormLocomotive : Form { private DrawningLocomotive _locomotive; - private EntityLocomotive _entity; public FormLocomotive() { @@ -22,9 +21,7 @@ namespace Locomotive private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _locomotive = new DrawningLocomotive(); - _entity = new EntityLocomotive(); - _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), _entity); + _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; -- 2.25.1 From fc639a1deb13e39cf428c53f1b24e0c8c9038c80 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 17:06:29 +0400 Subject: [PATCH 02/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D1=86?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=BC=D0=BE=D1=82=D0=B8=D0=B2,=20=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 17 +++++-- .../Locomotive/DrawningWarmlyLocomotive.cs | 44 +++++++++++++++++++ .../Locomotive/EntityElectroLocomotive.cs | 28 ++++++++++++ .../Locomotive/FormLocomotive.Designer.cs | 14 +++++- Locomotive/Locomotive/FormLocomotive.cs | 25 +++++++++-- 5 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 Locomotive/Locomotive/DrawningWarmlyLocomotive.cs create mode 100644 Locomotive/Locomotive/EntityElectroLocomotive.cs diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index e7c864b..1aaa188 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -10,11 +10,11 @@ namespace Locomotive internal class DrawningLocomotive { /// Класс-сущность - public EntityLocomotive Locomotive { get; private set; } + public EntityLocomotive Locomotive { get; protected set; } /// Левая координата отрисовки локомотива - private float _startPosX; + protected float _startPosX; /// Верхняя координата отрисовки локомотива - private float _startPosY; + protected float _startPosY; /// Ширина окна отрисовки private int? _pictureWidth = null; /// Высота окна отрисовки @@ -29,6 +29,15 @@ namespace Locomotive { Locomotive = new EntityLocomotive(speed, weight, bodyColor); } + + // Новый конструктор + protected DrawningLocomotive (int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight) + : this (speed, weight, bodyColor) + { + _locomotiveWidth = locomotiveWidth; + _locomotiveHeight = locomotiveHeight; + } + /// Установка позиции локомотива public void SetPosition(int x, int y, int width, int height) { @@ -89,7 +98,7 @@ namespace Locomotive } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs new file mode 100644 index 0000000..9207836 --- /dev/null +++ b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class DrawningWarmlyLocomotive : DrawningLocomotive + { + public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool storage) + : base(speed, weight, bodyColor, locomotiveWidth: 110, locomotiveHeight: 50) + { + Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage); + } + + public override void DrawTransport(Graphics g) + { + if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive) + { + return; + } + + Pen pen = new(Color.Black); + Brush extraBrush = new SolidBrush(warmlyLocomotive.ExtraColor); + base.DrawTransport(g); + + if (warmlyLocomotive.Pipe) + { + //TODO + + } + + if (warmlyLocomotive.FuelStorage) + { + //TODO + + } + + + } + + } +} diff --git a/Locomotive/Locomotive/EntityElectroLocomotive.cs b/Locomotive/Locomotive/EntityElectroLocomotive.cs new file mode 100644 index 0000000..510b6f7 --- /dev/null +++ b/Locomotive/Locomotive/EntityElectroLocomotive.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class EntityWarmlyLocomotive : EntityLocomotive + { + //доп. цвет + public Color ExtraColor { get; private set; } + //признак наличия трубы + public bool Pipe { get; private set; } + //признак наличия отсека под топливо + public bool FuelStorage { get; private set; } + + public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool fuelStorage) + : base(speed, weight, bodyColor) + { + ExtraColor = extraColor; + Pipe = pipe; + FuelStorage = fuelStorage; + } + + + } +} diff --git a/Locomotive/Locomotive/FormLocomotive.Designer.cs b/Locomotive/Locomotive/FormLocomotive.Designer.cs index 4aec4a1..12c5cba 100644 --- a/Locomotive/Locomotive/FormLocomotive.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotive.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModified = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -51,7 +52,6 @@ this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxLocomotive.TabIndex = 0; this.pictureBoxLocomotive.TabStop = false; - this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize); // // statusStrip1 @@ -144,11 +144,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModified + // + this.buttonCreateModified.Location = new System.Drawing.Point(112, 377); + this.buttonCreateModified.Name = "buttonCreateModified"; + this.buttonCreateModified.Size = new System.Drawing.Size(94, 29); + this.buttonCreateModified.TabIndex = 7; + this.buttonCreateModified.Text = "Modified"; + this.buttonCreateModified.UseVisualStyleBackColor = true; + this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_Click); + // // FormLocomotive // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(778, 442); + this.Controls.Add(this.buttonCreateModified); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -178,5 +189,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonRight; + private Button buttonCreateModified; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index cb904e7..0785b8a 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -18,14 +18,19 @@ namespace Locomotive pictureBoxLocomotive.Image = bmp; } + private void SetData() + { + toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; + toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; + toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}"; + } + private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); - toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; - toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; - toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}"; + SetData(); Draw(); } @@ -56,5 +61,19 @@ namespace Locomotive _locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); Draw(); } + + private void buttonCreateModified_Click(object sender, EventArgs e) + { + Random rnd = new(); + _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0,1)), + Convert.ToBoolean(rnd.Next(0, 1))); + + _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + SetData(); + Draw(); + } } } \ No newline at end of file -- 2.25.1 From 760ccf35701512dbf093153b7603ffd9053b7ead Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 17:52:02 +0400 Subject: [PATCH 03/11] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D1=85=20=D1=87=D0=B0=D1=81=D1=82=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=BA=D0=BE=D0=BC=D0=BE=D1=82=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 2 +- .../Locomotive/DrawningWarmlyLocomotive.cs | 30 ++++++++++++------- Locomotive/Locomotive/FormLocomotive.cs | 4 +-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 1aaa188..1d24b24 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -107,7 +107,7 @@ namespace Locomotive } Pen pen = new(Color.Black); //тело - g.DrawRectangle(pen, _startPosX , _startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10); + g.DrawRectangle(pen, _startPosX , _startPosY, 110 - 10, 50 - 10); //окна g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10); g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10); diff --git a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs index 9207836..dbb2b78 100644 --- a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs +++ b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs @@ -9,7 +9,7 @@ namespace Locomotive internal class DrawningWarmlyLocomotive : DrawningLocomotive { public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool storage) - : base(speed, weight, bodyColor, locomotiveWidth: 110, locomotiveHeight: 50) + : base(speed, weight, bodyColor, locomotiveWidth: 130, locomotiveHeight: 70) { Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage); } @@ -23,21 +23,29 @@ namespace Locomotive Pen pen = new(Color.Black); Brush extraBrush = new SolidBrush(warmlyLocomotive.ExtraColor); - base.DrawTransport(g); - - if (warmlyLocomotive.Pipe) - { - //TODO - - } + if (warmlyLocomotive.FuelStorage) { - //TODO - + g.FillRectangle(extraBrush, _startPosX + 10, _startPosY, 30, 20); + g.FillRectangle(extraBrush, _startPosX + 60, _startPosY, 20, 20); + g.FillRectangle(extraBrush, _startPosX + 60, _startPosY + 10, 30, 10); } - + if (warmlyLocomotive.Pipe) + { + g.FillRectangle(extraBrush, _startPosX + 110, _startPosY + 10, 10, 50); + g.FillRectangle(extraBrush, _startPosX + 110, _startPosY + 40, 20, 20); + g.FillRectangle(extraBrush, _startPosX + 100, _startPosY, 30, 10); + } + + _startPosY += 20; + + base.DrawTransport(g); + + _startPosY -= 20; + + } } diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 0785b8a..4e56d30 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -68,8 +68,8 @@ namespace Locomotive _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Convert.ToBoolean(rnd.Next(0,1)), - Convert.ToBoolean(rnd.Next(0, 1))); + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2))); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); SetData(); -- 2.25.1 From 0991e912058cf18aa032f268dee952c8342ae00a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 19:41:17 +0400 Subject: [PATCH 04/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 5 +++ .../Locomotive/DrawningObjectLocomotive.cs | 40 +++++++++++++++++++ Locomotive/Locomotive/IDrawningObject.cs | 22 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 Locomotive/Locomotive/DrawningObjectLocomotive.cs create mode 100644 Locomotive/Locomotive/IDrawningObject.cs diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 1d24b24..d89816b 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -142,5 +142,10 @@ namespace Locomotive _startPosY = _pictureHeight.Value - _locomotiveHeight; } } + // Получение текущей позиции объекта + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight); + } } } diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs new file mode 100644 index 0000000..389e9c8 --- /dev/null +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class DrawningObjectLocomotive : IDrawningObject + { + private DrawningLocomotive _locomotive = null; + + public DrawningObjectLocomotive(DrawningLocomotive locomotive) + { + _locomotive = locomotive; + } + + public float Step => _locomotive?.Locomotive?.Step ?? 0; + + public void DrawningObject(Graphics g) + { + _locomotive?.DrawTransport(g); + } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _locomotive?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _locomotive?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _locomotive?.SetPosition(x, y, width, height); + } + } +} diff --git a/Locomotive/Locomotive/IDrawningObject.cs b/Locomotive/Locomotive/IDrawningObject.cs new file mode 100644 index 0000000..ad04e9e --- /dev/null +++ b/Locomotive/Locomotive/IDrawningObject.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal interface IDrawningObject + { + /// Шаг перемещения объекта + public float Step { get; } + /// Установка позиции объекта + void SetObject(int x, int y, int width, int height); + /// Изменение направления перемещения объекта + void MoveObject(Direction direction); + /// Отрисовка объекта + void DrawningObject(Graphics g); + /// Получение текущей позиции объекта + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} -- 2.25.1 From 65330aaf57e2e37cdfb4d6bfc0e407232d645c32 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 20:25:57 +0400 Subject: [PATCH 05/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B8=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/AbstractMap.cs | 171 ++++++++++++++++++++ Locomotive/Locomotive/DrawningLocomotive.cs | 2 +- Locomotive/Locomotive/SimpleMap.cs | 54 +++++++ 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 Locomotive/Locomotive/AbstractMap.cs create mode 100644 Locomotive/Locomotive/SimpleMap.cs diff --git a/Locomotive/Locomotive/AbstractMap.cs b/Locomotive/Locomotive/AbstractMap.cs new file mode 100644 index 0000000..f7aa68c --- /dev/null +++ b/Locomotive/Locomotive/AbstractMap.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + public Bitmap CreateMap(int width, int height, IDrawningObject + drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); // abstract void + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + + public Bitmap MoveObject(Direction direction) + { + // added logic must be checked! + bool isFree = true; + + int startPosX = (int)(_drawningObject.GetCurrentPosition().Left / _size_x); + int startPosY = (int)(_drawningObject.GetCurrentPosition().Top / _size_y); + + int objectWidth = (int)(_drawningObject.GetCurrentPosition().Right / _size_x); + int objectHeight = (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y); + + switch (direction) + { + case Direction.Right: + for (int i = objectWidth; i <= objectWidth + (int)(_drawningObject.Step / _size_x); i++) + { + for (int j = startPosY; j <= objectHeight; j++) + { + if (_map[i, j] == _barrier) + { + isFree = false; + break; + } + } + } + break; + + case Direction.Left: + for (int i = startPosX; i >= (int)(_drawningObject.Step / _size_x); i--) + { + for (int j = startPosY; j <= objectHeight; j++) + { + if (_map[i, j] == _barrier) + { + isFree = false; + break; + } + } + } + break; + + case Direction.Up: + for (int i = startPosX; i <= objectWidth; i++) + { + for (int j = startPosY; j >= (int)(_drawningObject.Step / _size_y); j--) + { + if (_map[i, j] == _barrier) + { + isFree = false; + break; + } + } + } + break; + + case Direction.Down: + for (int i = startPosX; i <= objectWidth; i++) + { + for (int j = objectHeight; j <= objectHeight + (int)(_drawningObject.Step / _size_y); j++) + { + if (_map[i, j] == _barrier) + { + isFree = false; + break; + } + } + } + break; + } + if (isFree) + { + _drawningObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + + // added logic must be checked! + + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (i * _size_x >= x && j * _size_y >= y && + i * _size_x <= x + _drawningObject.GetCurrentPosition().Right && + j * _size_y <= j + _drawningObject.GetCurrentPosition().Bottom) + { + if (_map[i,j] == _barrier) + { + return false; + } + } + } + } + + return true; + } + + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == null || _map == null) + { + return bmp; + } + Graphics gr = Graphics.FromImage(bmp); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + _drawningObject.DrawningObject(gr); + return bmp; + } + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + + } +} diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index d89816b..35c7c93 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -145,7 +145,7 @@ namespace Locomotive // Получение текущей позиции объекта public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight); + return (_startPosX, _startPosX + _locomotiveWidth, _startPosY, _startPosY + _locomotiveHeight); } } } diff --git a/Locomotive/Locomotive/SimpleMap.cs b/Locomotive/Locomotive/SimpleMap.cs new file mode 100644 index 0000000..c45dca8 --- /dev/null +++ b/Locomotive/Locomotive/SimpleMap.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class SimpleMap : AbstractMap + { + /// Цвет участка закрытого + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// Цвет участка открытого + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + + } +} -- 2.25.1 From c3947c5007b5dd1fdbbcbe663cf3b5b6d9775323 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 20:28:57 +0400 Subject: [PATCH 06/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=D1=8F=20=D0=BF=D1=83=D1=81=D1=82=D0=B0=D1=8F?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormMap.Designer.cs | 39 +++++++ Locomotive/Locomotive/FormMap.cs | 20 ++++ Locomotive/Locomotive/FormMap.resx | 120 ++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 Locomotive/Locomotive/FormMap.Designer.cs create mode 100644 Locomotive/Locomotive/FormMap.cs create mode 100644 Locomotive/Locomotive/FormMap.resx diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs new file mode 100644 index 0000000..bcff4fa --- /dev/null +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -0,0 +1,39 @@ +namespace Locomotive +{ + partial class FormMap + { + /// + /// 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 = "FormMap"; + } + + #endregion + } +} \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs new file mode 100644 index 0000000..2808099 --- /dev/null +++ b/Locomotive/Locomotive/FormMap.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 Locomotive +{ + public partial class FormMap : Form + { + public FormMap() + { + InitializeComponent(); + } + } +} diff --git a/Locomotive/Locomotive/FormMap.resx b/Locomotive/Locomotive/FormMap.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Locomotive/Locomotive/FormMap.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file -- 2.25.1 From f2a5a88b7826a90e8aa0b57c9018bc58911c9c20 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 20:53:25 +0400 Subject: [PATCH 07/11] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/Direction.cs | 1 + Locomotive/Locomotive/FormMap.Designer.cs | 174 +++++++++++++++++++++- Locomotive/Locomotive/FormMap.cs | 72 +++++++++ Locomotive/Locomotive/FormMap.resx | 65 +------- Locomotive/Locomotive/Program.cs | 2 +- 5 files changed, 249 insertions(+), 65 deletions(-) diff --git a/Locomotive/Locomotive/Direction.cs b/Locomotive/Locomotive/Direction.cs index c9c339e..81100fc 100644 --- a/Locomotive/Locomotive/Direction.cs +++ b/Locomotive/Locomotive/Direction.cs @@ -9,6 +9,7 @@ namespace Locomotive //Направление перемещения internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs index bcff4fa..5447710 100644 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -28,12 +28,180 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModified = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxLocomotive + // + this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); + this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; + this.pictureBoxLocomotive.Size = new System.Drawing.Size(778, 416); + this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxLocomotive.TabIndex = 0; + this.pictureBoxLocomotive.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 416); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(778, 26); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(51, 20); + this.toolStripStatusLabelSpeed.Text = "Speed"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(56, 20); + this.toolStripStatusLabelWeight.Text = "Weight"; + // + // toolStripStatusLabelColor + // + this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; + this.toolStripStatusLabelColor.Size = new System.Drawing.Size(45, 20); + this.toolStripStatusLabelColor.Text = "Color"; + // + // buttonCreate + // + this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreate.Location = new System.Drawing.Point(12, 377); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(94, 29); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Create "; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(680, 320); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(40, 40); + this.buttonUp.TabIndex = 3; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(634, 366); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(40, 40); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(680, 366); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(40, 40); + this.buttonDown.TabIndex = 5; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(726, 366); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(40, 40); + this.buttonRight.TabIndex = 6; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModified + // + this.buttonCreateModified.Location = new System.Drawing.Point(112, 377); + this.buttonCreateModified.Name = "buttonCreateModified"; + this.buttonCreateModified.Size = new System.Drawing.Size(94, 29); + this.buttonCreateModified.TabIndex = 7; + this.buttonCreateModified.Text = "Modified"; + this.buttonCreateModified.UseVisualStyleBackColor = true; + this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); + this.comboBoxSelectorMap.TabIndex = 8; + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormMap"; + this.ClientSize = new System.Drawing.Size(778, 442); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModified); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxLocomotive); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.Text = "Map"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private PictureBox pictureBoxLocomotive; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelColor; + private Button buttonCreate; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonCreateModified; + private ComboBox comboBoxSelectorMap; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs index 2808099..16d64d3 100644 --- a/Locomotive/Locomotive/FormMap.cs +++ b/Locomotive/Locomotive/FormMap.cs @@ -12,9 +12,81 @@ namespace Locomotive { public partial class FormMap : Form { + private AbstractMap _abstractMap; public FormMap() { InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + /// Заполнение информации по объекту + private void SetData(DrawningLocomotive locomotive) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}"; + toolStripStatusLabelColor.Text = $"Цвет: { locomotive.Locomotive.BodyColor.Name}"; + pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, + new DrawningObjectLocomotive(locomotive)); + } + + /// Обработка нажатия кнопки "Создать" + private void buttonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var car = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(car); + } + + /// Изменение размеров формы + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir); + } + + /// Обработка нажатия кнопки "Модификация" + private void buttonCreateModified_Click(object sender, EventArgs e) + { + Random rnd = new(); + var car = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, + 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, + 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, + 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, + 2))); + SetData(car); + } + + /// Смена карты + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, + EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } } } } diff --git a/Locomotive/Locomotive/FormMap.resx b/Locomotive/Locomotive/FormMap.resx index 1af7de1..5cb320f 100644 --- a/Locomotive/Locomotive/FormMap.resx +++ b/Locomotive/Locomotive/FormMap.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Locomotive/Locomotive/Program.cs b/Locomotive/Locomotive/Program.cs index 36de08b..5663e56 100644 --- a/Locomotive/Locomotive/Program.cs +++ b/Locomotive/Locomotive/Program.cs @@ -11,7 +11,7 @@ namespace Locomotive // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLocomotive()); + Application.Run(new FormMap()); } } } \ No newline at end of file -- 2.25.1 From 91a3a29949b5d23776011bd00d5083f870a8e473 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 26 Sep 2022 21:59:42 +0400 Subject: [PATCH 08/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=88=D0=B8=D0=BF=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormMap.Designer.cs | 4 +- Locomotive/Locomotive/FormMap.cs | 6 ++- Locomotive/Locomotive/SpikeMap.cs | 59 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 Locomotive/Locomotive/SpikeMap.cs diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs index 5447710..f3b9c62 100644 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -159,11 +159,13 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Карта с шипами"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); // // FormMap // diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs index 16d64d3..bfd3a2f 100644 --- a/Locomotive/Locomotive/FormMap.cs +++ b/Locomotive/Locomotive/FormMap.cs @@ -78,7 +78,7 @@ namespace Locomotive } /// Смена карты - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorMap.Text) @@ -86,6 +86,10 @@ namespace Locomotive case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Карта с шипами": + _abstractMap = new SpikeMap(); + break; + } } } diff --git a/Locomotive/Locomotive/SpikeMap.cs b/Locomotive/Locomotive/SpikeMap.cs new file mode 100644 index 0000000..8f03023 --- /dev/null +++ b/Locomotive/Locomotive/SpikeMap.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class SpikeMap : AbstractMap + { + /// Цвет участка закрытого + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// Цвет участка открытого + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 15) + { + int x = _random.Next(1, 99); + int y = _random.Next(1, 99); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + + if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier; + if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier; + if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier; + if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier; + + counter++; + } + } + } + } +} -- 2.25.1 From b740601834486a7f0ee898bc10901395a6d47f70 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 26 Sep 2022 22:07:05 +0400 Subject: [PATCH 09/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=80=D0=B5=D0=BB=D1=8C=D1=81=D0=B0=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormMap.Designer.cs | 3 +- Locomotive/Locomotive/FormMap.cs | 3 ++ Locomotive/Locomotive/RailroadMap.cs | 62 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Locomotive/Locomotive/RailroadMap.cs diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs index f3b9c62..e885489 100644 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -160,7 +160,8 @@ this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { "Простая карта", - "Карта с шипами"}); + "Карта с шипами", + "Карта с рельсами"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs index bfd3a2f..4333523 100644 --- a/Locomotive/Locomotive/FormMap.cs +++ b/Locomotive/Locomotive/FormMap.cs @@ -89,6 +89,9 @@ namespace Locomotive case "Карта с шипами": _abstractMap = new SpikeMap(); break; + case "Карта с рельсами": + _abstractMap = new RailroadMap(); + break; } } diff --git a/Locomotive/Locomotive/RailroadMap.cs b/Locomotive/Locomotive/RailroadMap.cs new file mode 100644 index 0000000..f532e07 --- /dev/null +++ b/Locomotive/Locomotive/RailroadMap.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class RailroadMap : AbstractMap + { + /// Цвет участка закрытого + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// Цвет участка открытого + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 1) + { + int y = _random.Next(0, 95); + + for(int x = 0; x < 99; x++) + { + _map[x, y] = _barrier; + _map[x, y + 5] = _barrier; + + if (x % 5 == 0) + { + _map[x, y + 1] = _barrier; + _map[x, y + 2] = _barrier; + _map[x, y + 3] = _barrier; + _map[x, y + 4] = _barrier; + } + } + counter += 1; + } + } + } +} -- 2.25.1 From 45bf8f801ac4c08123e97a7e3213aef048fcdccf Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 27 Sep 2022 15:56:36 +0400 Subject: [PATCH 10/11] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/AbstractMap.cs | 3 --- Locomotive/Locomotive/DrawningLocomotive.cs | 10 +++++----- Locomotive/Locomotive/RailroadMap.cs | 2 +- Locomotive/Locomotive/SpikeMap.cs | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Locomotive/Locomotive/AbstractMap.cs b/Locomotive/Locomotive/AbstractMap.cs index f7aa68c..d83050c 100644 --- a/Locomotive/Locomotive/AbstractMap.cs +++ b/Locomotive/Locomotive/AbstractMap.cs @@ -33,7 +33,6 @@ namespace Locomotive public Bitmap MoveObject(Direction direction) { - // added logic must be checked! bool isFree = true; int startPosX = (int)(_drawningObject.GetCurrentPosition().Left / _size_x); @@ -117,8 +116,6 @@ namespace Locomotive int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); - // added logic must be checked! - for (int i = 0; i < _map.GetLength(0); ++i) { for (int j = 0; j < _map.GetLength(1); ++j) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 35c7c93..ee0f470 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -107,7 +107,7 @@ namespace Locomotive } Pen pen = new(Color.Black); //тело - g.DrawRectangle(pen, _startPosX , _startPosY, 110 - 10, 50 - 10); + g.FillRectangle(new SolidBrush(Color.MediumBlue), _startPosX , _startPosY, 110 - 10, 50 - 10); //окна g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10); g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10); @@ -115,10 +115,10 @@ namespace Locomotive //дверь g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20); //колеса - g.DrawEllipse(pen, _startPosX, _startPosY + 40, 10, 10); - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 40, 10, 10); - g.DrawEllipse(pen, _startPosX + 70, _startPosY + 40, 10, 10); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 10, 10); + g.FillEllipse(new SolidBrush(Color.Black), _startPosX, _startPosY + 40, 10, 10); + g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 20, _startPosY + 40, 10, 10); + g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 70, _startPosY + 40, 10, 10); + g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 90, _startPosY + 40, 10, 10); //черный прямоугольник g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 100, _startPosY + 10, 10, 30); } diff --git a/Locomotive/Locomotive/RailroadMap.cs b/Locomotive/Locomotive/RailroadMap.cs index f532e07..ac2a5eb 100644 --- a/Locomotive/Locomotive/RailroadMap.cs +++ b/Locomotive/Locomotive/RailroadMap.cs @@ -11,7 +11,7 @@ namespace Locomotive /// Цвет участка закрытого private readonly Brush barrierColor = new SolidBrush(Color.Black); /// Цвет участка открытого - private readonly Brush roadColor = new SolidBrush(Color.Gray); + private readonly Brush roadColor = new SolidBrush(Color.Pink); protected override void DrawBarrierPart(Graphics g, int i, int j) { diff --git a/Locomotive/Locomotive/SpikeMap.cs b/Locomotive/Locomotive/SpikeMap.cs index 8f03023..9dcb666 100644 --- a/Locomotive/Locomotive/SpikeMap.cs +++ b/Locomotive/Locomotive/SpikeMap.cs @@ -11,7 +11,7 @@ namespace Locomotive /// Цвет участка закрытого private readonly Brush barrierColor = new SolidBrush(Color.Black); /// Цвет участка открытого - private readonly Brush roadColor = new SolidBrush(Color.Gray); + private readonly Brush roadColor = new SolidBrush(Color.Green); protected override void DrawBarrierPart(Graphics g, int i, int j) { -- 2.25.1 From c3c543ae46d6d2d6356d7a77a09b8efaf672da02 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 27 Sep 2022 15:58:43 +0400 Subject: [PATCH 11/11] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningObjectLocomotive.cs | 1 + Locomotive/Locomotive/IDrawningObject.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs index 389e9c8..4a518dc 100644 --- a/Locomotive/Locomotive/DrawningObjectLocomotive.cs +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -36,5 +36,6 @@ namespace Locomotive { _locomotive?.SetPosition(x, y, width, height); } + } } diff --git a/Locomotive/Locomotive/IDrawningObject.cs b/Locomotive/Locomotive/IDrawningObject.cs index ad04e9e..5a7c000 100644 --- a/Locomotive/Locomotive/IDrawningObject.cs +++ b/Locomotive/Locomotive/IDrawningObject.cs @@ -18,5 +18,6 @@ namespace Locomotive void DrawningObject(Graphics g); /// Получение текущей позиции объекта (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } } -- 2.25.1