From 8449b14ffcd466ac85445f46aef373d61c246ccf Mon Sep 17 00:00:00 2001 From: PIBD14CHERTOVANDREY Date: Thu, 14 Mar 2024 09:39:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => Drawnings}/DirectionType.cs | 2 +- .../Drawnings/DrawningRoadTrain.cs | 53 +++++++++++++++ .../DrawningTrain.cs} | 67 ++++++++++--------- .../Entities/EntityRoadTrain.cs | 18 +++++ .../ProjectRoadTrain/Entities/EntityTrain.cs | 22 ++++++ .../ProjectRoadTrain/EntityRoadTrain.cs | 24 ------- .../FormRoadTrain.Designer.cs | 18 ++++- .../ProjectRoadTrain/FormRoadTrain.cs | 64 ++++++++++++------ 8 files changed, 189 insertions(+), 79 deletions(-) rename ProjectRoadTrain/ProjectRoadTrain/{ => Drawnings}/DirectionType.cs (84%) create mode 100644 ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs rename ProjectRoadTrain/ProjectRoadTrain/{DrawningRoadTrain.cs => Drawnings/DrawningTrain.cs} (62%) create mode 100644 ProjectRoadTrain/ProjectRoadTrain/Entities/EntityRoadTrain.cs create mode 100644 ProjectRoadTrain/ProjectRoadTrain/Entities/EntityTrain.cs delete mode 100644 ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs diff --git a/ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DirectionType.cs similarity index 84% rename from ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs rename to ProjectRoadTrain/ProjectRoadTrain/Drawnings/DirectionType.cs index 54ea441..45f811f 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DirectionType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectRoadTrain; +namespace ProjectRoadTrain.Drawnings; public enum DirectionType { diff --git a/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs new file mode 100644 index 0000000..f648595 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectRoadTrain.Entities; + +namespace ProjectRoadTrain.Drawnings; + +public class DrawningRoadTrain : DrawningTrain +{ + + + public DrawningRoadTrain(int speed, double weight, Color bodycolor, Color bodytankcolor, bool watertank, bool cleanbrush) : base(230, 115) + { + EntityTrain = new EntityRoadTrain(speed, weight, bodycolor, bodytankcolor, watertank, cleanbrush); + } + + + + public override void DrawTransport(Graphics g) + { + if (EntityTrain == null || EntityTrain is not EntityRoadTrain roadTrain || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush bodytankcolor = new SolidBrush(roadTrain.BodyTankColor); + Brush blackcolor = new SolidBrush(Color.Black); + Brush bodycolor = new SolidBrush(roadTrain.BodyColor); + + if (roadTrain.WaterTank || roadTrain.CleanBrush) + { + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 70, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 75, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 65, 100, 2); + g.FillEllipse(bodytankcolor, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); + } + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 170, 20); + g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value, 50, 60); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); + // 120 высота + // 270 ширина + g.FillRectangle(blackcolor, _startPosX.Value, _startPosY.Value + 60, 170, 20); + g.FillRectangle(bodycolor, _startPosX.Value + 120, _startPosY.Value, 50, 60); + g.FillEllipse(blackcolor, _startPosX.Value + 120, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value + 49, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value, _startPosY.Value + 77, 48, 40); + + base.DrawTransport(g); + } +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs similarity index 62% rename from ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs rename to ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs index 1b481d7..1f93078 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs @@ -1,37 +1,45 @@ -using System; +using ProjectRoadTrain.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectRoadTrain; +namespace ProjectRoadTrain.Drawnings; -public class DrawningRoadTrain +public class DrawningTrain { - public EntityRoadTrain? EntityRoadTrain { get; private set; } + public EntityTrain? EntityTrain { get; protected set; } private int? _pictureWidth; private int? _pictureHight; - private int? _startPosX; + protected int? _startPosX; - private int? _startPosY; + protected int? _startPosY; - private readonly int _drawningRoadWidth = 230; + private readonly int _drawningRoadWidth = 270; - private readonly int _drawningRoadHeight = 115; + private readonly int _drawningRoadHeight = 117; - public void Init(int speed, double weight, Color bodycolor, Color bodytankcolor, bool watertank, bool cleanbrush) + + private DrawningTrain() { - EntityRoadTrain = new EntityRoadTrain(); - EntityRoadTrain.Init(speed, weight, bodycolor, bodytankcolor, watertank, cleanbrush); _pictureWidth = null; _pictureHight = null; _startPosX = null; _startPosY = null; } - + public DrawningTrain(int speed, double weight, Color bodycolor) : this() + { + EntityTrain = new EntityTrain(speed, weight, bodycolor); + } + protected DrawningTrain(int drawningRoadWidth, int drawningRoadHeight) : this() + { + _drawningRoadWidth = drawningRoadWidth; + _drawningRoadHeight = drawningRoadHeight; + } public bool SetPictureSize(int width, int hight) { if (width >= _drawningRoadWidth && hight >= _drawningRoadHeight) @@ -79,7 +87,7 @@ public class DrawningRoadTrain public bool MoveTransport(DirectionType direction) { - if (EntityRoadTrain == null || !_startPosX.HasValue || + if (EntityTrain == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; @@ -92,32 +100,32 @@ public class DrawningRoadTrain { //влево case DirectionType.Left: - if (_startPosX.Value - EntityRoadTrain.Step > 0) + if (_startPosX.Value - EntityTrain.Step > 0) { - _startPosX -= (int)EntityRoadTrain.Step; + _startPosX -= (int)EntityTrain.Step; } return true; //вверх case DirectionType.Up: - if (_startPosY.Value - EntityRoadTrain.Step > 0) + if (_startPosY.Value - EntityTrain.Step > 0) { - _startPosY -= (int)EntityRoadTrain.Step; + _startPosY -= (int)EntityTrain.Step; } return true; // вправо case DirectionType.Right: - if (_startPosX.Value + EntityRoadTrain.Step < _pictureWidth - _drawningRoadWidth) + if (_startPosX.Value + EntityTrain.Step < _pictureWidth - _drawningRoadWidth) { - _startPosX += (int)EntityRoadTrain.Step; + _startPosX += (int)EntityTrain.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + EntityRoadTrain.Step < _pictureHight - _drawningRoadHeight) + if (_startPosY.Value + EntityTrain.Step < _pictureHight - _drawningRoadHeight) { - _startPosY += (int)EntityRoadTrain.Step; + _startPosY += (int)EntityTrain.Step; } return true; @@ -127,25 +135,18 @@ public class DrawningRoadTrain } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityRoadTrain == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityTrain == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); - Brush bodytankcolor = new SolidBrush(EntityRoadTrain.BodyTankColor); Brush blackcolor = new SolidBrush(Color.Black); - Brush bodycolor = new SolidBrush(EntityRoadTrain.BodyColor); + Brush bodycolor = new SolidBrush(EntityTrain.BodyColor); - if (EntityRoadTrain.WaterTank || EntityRoadTrain.CleanBrush) - { - g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 70, 100, 2); - g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 75, 100, 2); - g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 65, 100, 2); - g.FillEllipse(bodytankcolor, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); - } + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 170, 20); g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value, 50, 60); g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); @@ -158,3 +159,5 @@ public class DrawningRoadTrain g.FillEllipse(blackcolor, _startPosX.Value, _startPosY.Value + 77, 48, 40); } } + + diff --git a/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityRoadTrain.cs new file mode 100644 index 0000000..29670fc --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityRoadTrain.cs @@ -0,0 +1,18 @@ +namespace ProjectRoadTrain.Entities; + +internal class EntityRoadTrain : EntityTrain +{ + public Color BodyTankColor { get; private set; } + public bool WaterTank { get; private set; } + public bool CleanBrush { get; private set; } + public double Step => Speed * 50 / Weight; + + public EntityRoadTrain(int speed, double weight, Color bodycolor, Color bodytankcolor, + bool watertank, bool cleanbrush) : base(speed, weight, bodycolor) + { + BodyTankColor = bodytankcolor; + WaterTank = watertank; + CleanBrush = cleanbrush; + } + +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityTrain.cs new file mode 100644 index 0000000..cea52ba --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/Entities/EntityTrain.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRoadTrain.Entities; + +public class EntityTrain +{ + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public double Step => Speed * 50 / Weight; + + public EntityTrain(int speed, double weight, Color bodycolor) + { + Speed = speed; + Weight = weight; + BodyColor = bodycolor; + } +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs deleted file mode 100644 index 6d9c8c8..0000000 --- a/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace ProjectRoadTrain; - -public class EntityRoadTrain -{ - public int Speed { get; private set; } - public double Weight { get; private set; } - public Color BodyColor { get; private set; } - public Color BodyTankColor { get; private set; } - public bool WaterTank { get; private set; } - public bool CleanBrush { get; private set; } - public double Step => Speed * 50 / Weight; - - public void Init(int speed, double weight, Color bodycolor, Color bodytankcolor, - bool watertank, bool cleanbrush) - { - Speed = speed; - Weight = weight; - BodyColor = bodycolor; - BodyTankColor = bodytankcolor; - WaterTank = watertank; - CleanBrush = cleanbrush; - } - -} diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs index cdadb17..9549cdc 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs @@ -34,6 +34,7 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); + buttonCreateTrain = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Location = new Point(12, 495); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(94, 29); + buttonCreate.Size = new Size(184, 29); buttonCreate.TabIndex = 1; - buttonCreate.Text = "создать"; + buttonCreate.Text = "создать моющий камаз"; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += buttonCreate_Click; // @@ -105,11 +106,23 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += buttonMove_Click; // + // buttonCreateTrain + // + buttonCreateTrain.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateTrain.Location = new Point(215, 495); + buttonCreateTrain.Name = "buttonCreateTrain"; + buttonCreateTrain.Size = new Size(122, 29); + buttonCreateTrain.TabIndex = 6; + buttonCreateTrain.Text = "создать камаз"; + buttonCreateTrain.UseVisualStyleBackColor = true; + buttonCreateTrain.Click += buttonCreateTrain_Click; + // // FormRoadTrain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(923, 536); + Controls.Add(buttonCreateTrain); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -130,5 +143,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateTrain; } } \ No newline at end of file diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs index bd4b5d1..9bc36bb 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs @@ -1,8 +1,11 @@ -namespace ProjectRoadTrain; +using ProjectRoadTrain.Drawnings; +using ProjectRoadTrain.Entities; + +namespace ProjectRoadTrain; public partial class FormRoadTrain : Form { - private DrawningRoadTrain? _drawningRoadTrain; + private DrawningTrain? _drawningTrain; public FormRoadTrain() { InitializeComponent(); @@ -10,33 +13,52 @@ public partial class FormRoadTrain : Form private void Draw() { - if (_drawningRoadTrain == null) + if (_drawningTrain == null) { return; } - Bitmap bmp = new (pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); + Bitmap bmp = new(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningRoadTrain.DrawTransport(gr); + _drawningTrain.DrawTransport(gr); pictureBoxRoadTrain.Image = bmp; } + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningTrain): + _drawningTrain = new DrawningTrain(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawningRoadTrain): + _drawningTrain = new DrawningRoadTrain(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + _drawningTrain.SetPictureSize(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); + _drawningTrain.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } private void buttonCreate_Click(object sender, EventArgs e) { - Random random = new(); - _drawningRoadTrain = new DrawningRoadTrain(); - _drawningRoadTrain.Init(random.Next(100, 300), random.Next(1200, 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))); - _drawningRoadTrain.SetPictureSize(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); - _drawningRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } + CreateObject(nameof(DrawningRoadTrain)); + } + private void buttonCreateTrain_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningTrain)); + } private void buttonMove_Click(object sender, EventArgs e) { - if (_drawningRoadTrain == null) + if (_drawningTrain == null) { return; } @@ -46,16 +68,16 @@ public partial class FormRoadTrain : Form switch (name) { case "buttonUp": - result = _drawningRoadTrain.MoveTransport(DirectionType.Up); + result = _drawningTrain.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningRoadTrain.MoveTransport(DirectionType.Down); + result = _drawningTrain.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningRoadTrain.MoveTransport(DirectionType.Left); + result = _drawningTrain.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningRoadTrain.MoveTransport(DirectionType.Right); + result = _drawningTrain.MoveTransport(DirectionType.Right); break; } @@ -64,4 +86,6 @@ public partial class FormRoadTrain : Form Draw(); } } + + }