From 5e7e145d60a7c6ecb178b6ca08e5a9ddb3891cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 20 Sep 2022 21:09:37 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=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 --- .../GasolineTanker/DrawingGasolineTanker.cs | 5 +-- .../GasolineTanker/EnityGasolineTanker.cs | 2 +- .../FormGasolineTanker.Designer.cs | 45 ++++++++----------- .../GasolineTanker/FormGasolineTanker.cs | 3 +- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index 20b1dea..a80a5f2 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -16,10 +16,9 @@ namespace GasolineTanker private readonly int _gasolineTankerWidth = 160; private readonly int _gasolineTankerHeight = 55; - public void Init(int speed, float weight, Color bodyColor) + public DrawingGasolineTanker(int speed, float weight, Color bodyColor) { - GasolineTanker = new EnityGasolineTanker(); - GasolineTanker.Init(speed, weight, bodyColor); + GasolineTanker = new EnityGasolineTanker(speed, weight, bodyColor); } public void SetPosition(int x, int y, int width, int height) diff --git a/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs index e3f5b3b..dd369c1 100644 --- a/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs @@ -12,7 +12,7 @@ namespace GasolineTanker public float Weight { get; private set; } public Color BodyColor { get; private set; } public float Step => Speed * 100 / Weight; - public void Init(int speed, float weight, Color bodyColor) + public EnityGasolineTanker(int speed, float weight, Color bodyColor) { Random rnd = new Random(); Speed = speed <= 0 ? rnd.Next(50, 100) : speed; diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs index 462148b..101c56a 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -46,9 +46,8 @@ // this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); - this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; - this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574); + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428); this.pictureBoxGasolineTanker.TabIndex = 0; this.pictureBoxGasolineTanker.TabStop = false; // @@ -59,38 +58,36 @@ this.toolStripStatusSpeed, this.toolStripStatusWeight, this.toolStripStatusBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 574); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); - this.statusStrip1.Size = new System.Drawing.Size(922, 26); + this.statusStrip1.Size = new System.Drawing.Size(807, 22); this.statusStrip1.TabIndex = 1; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusSpeed // this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; - this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20); + this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); this.toolStripStatusSpeed.Text = "Speed"; // // toolStripStatusWeight // this.toolStripStatusWeight.Name = "toolStripStatusWeight"; - this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20); + this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); this.toolStripStatusWeight.Text = "Weight"; // // toolStripStatusBodyColor // this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; - this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20); + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); this.toolStripStatusBodyColor.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(14, 524); - this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCreate.Location = new System.Drawing.Point(12, 393); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(86, 31); + this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Create"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -101,10 +98,9 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(827, 515); - this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyDown.Location = new System.Drawing.Point(724, 386); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(34, 40); + this.keyDown.Size = new System.Drawing.Size(30, 30); this.keyDown.TabIndex = 3; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); @@ -114,10 +110,9 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(827, 467); - this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyUp.Location = new System.Drawing.Point(724, 350); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(34, 40); + this.keyUp.Size = new System.Drawing.Size(30, 30); this.keyUp.TabIndex = 4; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -127,10 +122,9 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(786, 515); - this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyLeft.Location = new System.Drawing.Point(688, 386); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(34, 40); + this.keyLeft.Size = new System.Drawing.Size(30, 30); this.keyLeft.TabIndex = 5; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -140,19 +134,18 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(868, 515); - this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyRight.Location = new System.Drawing.Point(760, 386); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(34, 40); + this.keyRight.Size = new System.Drawing.Size(30, 30); this.keyRight.TabIndex = 6; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // // FormGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(922, 600); + this.ClientSize = new System.Drawing.Size(807, 450); this.Controls.Add(this.keyRight); this.Controls.Add(this.keyLeft); this.Controls.Add(this.keyUp); @@ -160,9 +153,9 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxGasolineTanker); this.Controls.Add(this.statusStrip1); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormGasolineTanker"; this.Text = "Gasoline tanker"; + this.Load += new System.EventHandler(this.FormGasolineTanker_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index 46d150d..da801f3 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -23,8 +23,7 @@ namespace GasolineTanker private void buttonCreate_Click_1(object sender, EventArgs e) { Random rnd = new(); - _gasolineTanker = new DrawingGasolineTanker(); - _gasolineTanker.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _gasolineTanker.SetPosition(rnd.Next(10, 100),rnd.Next(50, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; -- 2.25.1 From 588e670457ac85a0031adff9ea34df59b1025354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 20 Sep 2022 22:42:52 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GasolineTanker/DrawingGasolineTanker.cs | 15 ++++-- .../DrawingImprovedGasolineTanker.cs | 48 +++++++++++++++++++ .../EntityImprovedGasolineTanker.cs | 22 +++++++++ .../FormGasolineTanker.Designer.cs | 14 +++++- .../GasolineTanker/FormGasolineTanker.cs | 23 +++++++-- 5 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs create mode 100644 GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index a80a5f2..3a16ac1 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -8,9 +8,9 @@ namespace GasolineTanker { internal class DrawingGasolineTanker { - public EnityGasolineTanker GasolineTanker { get; private set; } - private float _startPosX; - private float _startPosY; + public EnityGasolineTanker GasolineTanker { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _gasolineTankerWidth = 160; @@ -21,6 +21,13 @@ namespace GasolineTanker GasolineTanker = new EnityGasolineTanker(speed, weight, bodyColor); } + protected DrawingGasolineTanker(int speed, float weight, Color bodyColor, int gasolineTankerWidth, int gasolineTankerHeight) : + this(speed, weight, bodyColor) + { + _gasolineTankerWidth = gasolineTankerWidth; + _gasolineTankerHeight = gasolineTankerHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x >= 0 && x + _gasolineTankerWidth <= width && y >= 0 && y + _gasolineTankerHeight <= height) @@ -70,7 +77,7 @@ namespace GasolineTanker break; } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs new file mode 100644 index 0000000..7e5228d --- /dev/null +++ b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class DrawingImprovedGasolineTanker : DrawingGasolineTanker + { + public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) : + base(speed, weight, bodyColor, 160, 55) + { + GasolineTanker = new EntityImprovedGasolineTanker(speed, weight, bodyColor, dopColor, bodyKit, ornamentWheels); + } + public override void DrawTransport(Graphics g) + { + if (GasolineTanker is not EntityImprovedGasolineTanker improvedGasolineTanker) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(improvedGasolineTanker.DopColor); + + if (improvedGasolineTanker.BodyKit) + { + Brush brOrange = new SolidBrush(Color.Orange); + g.FillRectangle(brOrange, _startPosX + 25, _startPosY + 5, 100, 35); + } + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (improvedGasolineTanker.OrnamentWheels) + { + Pen penGray = new(Color.Gray); + Brush brBlack = new SolidBrush(Color.Gray); + g.DrawEllipse(penGray, _startPosX + 140, _startPosY + 50, 20, 5); + g.DrawEllipse(penGray, _startPosX + 40, _startPosY + 50, 20, 5); + g.DrawEllipse(penGray, _startPosX + 20, _startPosY + 50, 20, 5); + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs new file mode 100644 index 0000000..161e86e --- /dev/null +++ b/GasolineTanker/GasolineTanker/EntityImprovedGasolineTanker.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class EntityImprovedGasolineTanker : EnityGasolineTanker + { + public Color DopColor { get; private set; } + public bool BodyKit { get; private set; } + public bool OrnamentWheels { get; private set; } + public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + OrnamentWheels = ornamentWheels; + } + } +} diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs index 101c56a..5be7d04 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -38,6 +38,7 @@ this.keyUp = new System.Windows.Forms.Button(); this.keyLeft = new System.Windows.Forms.Button(); this.keyRight = new System.Windows.Forms.Button(); + this.ButtonCreateImproved = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,22 @@ this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // ButtonCreateImproved + // + this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); + this.ButtonCreateImproved.Name = "ButtonCreateImproved"; + this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); + this.ButtonCreateImproved.TabIndex = 7; + this.ButtonCreateImproved.Text = "Improved"; + this.ButtonCreateImproved.UseVisualStyleBackColor = true; + this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click); + // // FormGasolineTanker // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(807, 450); + this.Controls.Add(this.ButtonCreateImproved); this.Controls.Add(this.keyRight); this.Controls.Add(this.keyLeft); this.Controls.Add(this.keyUp); @@ -155,7 +167,6 @@ this.Controls.Add(this.statusStrip1); this.Name = "FormGasolineTanker"; this.Text = "Gasoline tanker"; - this.Load += new System.EventHandler(this.FormGasolineTanker_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); @@ -176,5 +187,6 @@ private Button keyUp; private Button keyLeft; private Button keyRight; + private Button ButtonCreateImproved; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index da801f3..c7d0f1e 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -14,6 +14,14 @@ namespace GasolineTanker _gasolineTanker?.DrawTransport(gr); pictureBoxGasolineTanker.Image = bmp; } + private void SetData() + { + Random rnd = new(); + _gasolineTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; + toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; + toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}"; + } private void PictureBoxCar_Resize(object sender, EventArgs e) { _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); @@ -25,9 +33,7 @@ namespace GasolineTanker Random rnd = new(); _gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _gasolineTanker.SetPosition(rnd.Next(10, 100),rnd.Next(50, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); - toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; - toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; - toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}"; + SetData(); Draw(); } @@ -58,5 +64,16 @@ namespace GasolineTanker _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); Draw(); } + + private void ButtonCreateImproved_Click(object sender, EventArgs e) + { + Random rnd = new(); + _gasolineTanker = new DrawingImprovedGasolineTanker(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(); + Draw(); + } } } \ No newline at end of file -- 2.25.1 From 7425d24b87ba72d50d392c916e578289d4929bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Wed, 21 Sep 2022 00:12:00 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20+?= =?UTF-8?q?=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GasolineTanker/GasolineTanker/AbstractMap.cs | 85 +++++++ GasolineTanker/GasolineTanker/Direction.cs | 1 + .../GasolineTanker/DrawingGasolineTanker.cs | 5 + .../DrawingObjectGasolineTanker.cs | 40 ++++ .../GasolineTanker/FormMap.Designer.cs | 207 ++++++++++++++++++ GasolineTanker/GasolineTanker/FormMap.cs | 83 +++++++ GasolineTanker/GasolineTanker/FormMap.resx | 63 ++++++ .../GasolineTanker/IDrawingObject.cs | 17 ++ GasolineTanker/GasolineTanker/Program.cs | 2 +- GasolineTanker/GasolineTanker/SimpleMap.cs | 47 ++++ 10 files changed, 549 insertions(+), 1 deletion(-) create mode 100644 GasolineTanker/GasolineTanker/AbstractMap.cs create mode 100644 GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs create mode 100644 GasolineTanker/GasolineTanker/FormMap.Designer.cs create mode 100644 GasolineTanker/GasolineTanker/FormMap.cs create mode 100644 GasolineTanker/GasolineTanker/FormMap.resx create mode 100644 GasolineTanker/GasolineTanker/IDrawingObject.cs create mode 100644 GasolineTanker/GasolineTanker/SimpleMap.cs diff --git a/GasolineTanker/GasolineTanker/AbstractMap.cs b/GasolineTanker/GasolineTanker/AbstractMap.cs new file mode 100644 index 0000000..a89cc45 --- /dev/null +++ b/GasolineTanker/GasolineTanker/AbstractMap.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal abstract class AbstractMap + { + private IDrawingObject _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, IDrawingObject drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Bitmap MoveObject(Direction direction) + { + // TODO проверка, что объект может переместится в требуемом направлении + if (true) + { + _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); + // TODO првоерка, что объект не "накладывается" на закрытые участки + 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/GasolineTanker/GasolineTanker/Direction.cs b/GasolineTanker/GasolineTanker/Direction.cs index 8fd3c1c..c76c46a 100644 --- a/GasolineTanker/GasolineTanker/Direction.cs +++ b/GasolineTanker/GasolineTanker/Direction.cs @@ -8,6 +8,7 @@ namespace GasolineTanker { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index 3a16ac1..1922061 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -127,5 +127,10 @@ namespace GasolineTanker _startPosY = _pictureHeight.Value - _gasolineTankerHeight; } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _gasolineTankerWidth, _startPosY + _gasolineTankerHeight); + } } } diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs new file mode 100644 index 0000000..c68eae8 --- /dev/null +++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class DrawingObjectGasolineTanker : IDrawingObject + { + private DrawingGasolineTanker _gasolineTanker = null; + + public DrawingObjectGasolineTanker(DrawingGasolineTanker gasolineTanker) + { + _gasolineTanker = gasolineTanker; + } + + public float Step => _gasolineTanker?.GasolineTanker?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _gasolineTanker?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _gasolineTanker?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _gasolineTanker.SetPosition(x, y, width, height); + } + + void IDrawingObject.DrawningObject(Graphics g) + { + // TODO + } + } +} diff --git a/GasolineTanker/GasolineTanker/FormMap.Designer.cs b/GasolineTanker/GasolineTanker/FormMap.Designer.cs new file mode 100644 index 0000000..19516ef --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormMap.Designer.cs @@ -0,0 +1,207 @@ +namespace GasolineTanker +{ + 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.pictureBoxGasolineTanker = new System.Windows.Forms.PictureBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.keyDown = new System.Windows.Forms.Button(); + this.keyUp = new System.Windows.Forms.Button(); + this.keyLeft = new System.Windows.Forms.Button(); + this.keyRight = new System.Windows.Forms.Button(); + this.ButtonCreateImproved = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxGasolineTanker + // + this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); + this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428); + this.pictureBoxGasolineTanker.TabIndex = 0; + this.pictureBoxGasolineTanker.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusSpeed, + this.toolStripStatusWeight, + this.toolStripStatusBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(807, 22); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusSpeed + // + this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; + this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusSpeed.Text = "Speed"; + // + // toolStripStatusWeight + // + this.toolStripStatusWeight.Name = "toolStripStatusWeight"; + this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); + this.toolStripStatusWeight.Text = "Weight"; + // + // toolStripStatusBodyColor + // + this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusBodyColor.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, 393); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Create"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1); + // + // keyDown + // + this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; + this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyDown.Location = new System.Drawing.Point(724, 386); + this.keyDown.Name = "keyDown"; + this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.TabIndex = 3; + this.keyDown.UseVisualStyleBackColor = true; + this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // keyUp + // + this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; + this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyUp.Location = new System.Drawing.Point(724, 350); + this.keyUp.Name = "keyUp"; + this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.TabIndex = 4; + this.keyUp.UseVisualStyleBackColor = true; + this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // keyLeft + // + this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; + this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyLeft.Location = new System.Drawing.Point(688, 386); + this.keyLeft.Name = "keyLeft"; + this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.TabIndex = 5; + this.keyLeft.UseVisualStyleBackColor = true; + this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // keyRight + // + this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; + this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyRight.Location = new System.Drawing.Point(760, 386); + this.keyRight.Name = "keyRight"; + this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.TabIndex = 6; + this.keyRight.UseVisualStyleBackColor = true; + this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonCreateImproved + // + this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); + this.ButtonCreateImproved.Name = "ButtonCreateImproved"; + this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); + this.ButtonCreateImproved.TabIndex = 7; + this.ButtonCreateImproved.Text = "Improved"; + this.ButtonCreateImproved.UseVisualStyleBackColor = true; + this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Simple map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(807, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.ButtonCreateImproved); + this.Controls.Add(this.keyRight); + this.Controls.Add(this.keyLeft); + this.Controls.Add(this.keyUp); + this.Controls.Add(this.keyDown); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxGasolineTanker); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.Text = "Map"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxGasolineTanker; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusSpeed; + private ToolStripStatusLabel toolStripStatusWeight; + private ToolStripStatusLabel toolStripStatusBodyColor; + private Button buttonCreate; + private Button keyDown; + private Button keyUp; + private Button keyLeft; + private Button keyRight; + private Button ButtonCreateImproved; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMap.cs b/GasolineTanker/GasolineTanker/FormMap.cs new file mode 100644 index 0000000..37d5ac9 --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormMap.cs @@ -0,0 +1,83 @@ +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 GasolineTanker +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + private void SetData(DrawingGasolineTanker gasolineTanker) + { + toolStripStatusSpeed.Text = $"Speed {gasolineTanker.GasolineTanker.Speed}"; + toolStripStatusWeight.Text = $"Weight {gasolineTanker.GasolineTanker.Weight}"; + toolStripStatusBodyColor.Text = $"Color {gasolineTanker.GasolineTanker.BodyColor.Name}"; + pictureBoxGasolineTanker.Image = _abstractMap.CreateMap(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height, + new DrawingObjectGasolineTanker(gasolineTanker)); + } + + private void buttonCreate_Click_1(object sender, EventArgs e) + { + Random rnd = new(); + var gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(gasolineTanker); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "keyUp": + dir = Direction.Up; + break; + case "keyDown": + dir = Direction.Down; + break; + case "keyLeft": + dir = Direction.Left; + break; + case "keyRight": + dir = Direction.Right; + break; + } + pictureBoxGasolineTanker.Image = _abstractMap?.MoveObject(dir); + } + + private void ButtonCreateImproved_Click(object sender, EventArgs e) + { + Random rnd = new(); + var gasolineTanker = new DrawingImprovedGasolineTanker(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(gasolineTanker); + } + + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Simple map": + _abstractMap = new SimpleMap(); + break; + } + } + + } +} + diff --git a/GasolineTanker/GasolineTanker/FormMap.resx b/GasolineTanker/GasolineTanker/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/IDrawingObject.cs b/GasolineTanker/GasolineTanker/IDrawingObject.cs new file mode 100644 index 0000000..43f1a65 --- /dev/null +++ b/GasolineTanker/GasolineTanker/IDrawingObject.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal interface IDrawingObject + { + 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(); + } +} diff --git a/GasolineTanker/GasolineTanker/Program.cs b/GasolineTanker/GasolineTanker/Program.cs index 1b6a3e0..b920f1e 100644 --- a/GasolineTanker/GasolineTanker/Program.cs +++ b/GasolineTanker/GasolineTanker/Program.cs @@ -11,7 +11,7 @@ namespace GasolineTanker // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormGasolineTanker()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/SimpleMap.cs b/GasolineTanker/GasolineTanker/SimpleMap.cs new file mode 100644 index 0000000..e3009aa --- /dev/null +++ b/GasolineTanker/GasolineTanker/SimpleMap.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + 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 ac95e05cf4b8de30260e3f85384bf1d6ad8d4bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Wed, 21 Sep 2022 10:27:38 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GasolineTanker/GasolineTanker/AbstractMap.cs | 75 ++++++++++++++++++- GasolineTanker/GasolineTanker/BoxMap.cs | 56 ++++++++++++++ .../DrawingImprovedGasolineTanker.cs | 2 + .../DrawingObjectGasolineTanker.cs | 2 +- .../GasolineTanker/FormMap.Designer.cs | 57 ++++++++------ GasolineTanker/GasolineTanker/FormMap.cs | 3 + 6 files changed, 168 insertions(+), 27 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/BoxMap.cs diff --git a/GasolineTanker/GasolineTanker/AbstractMap.cs b/GasolineTanker/GasolineTanker/AbstractMap.cs index a89cc45..ecfbe80 100644 --- a/GasolineTanker/GasolineTanker/AbstractMap.cs +++ b/GasolineTanker/GasolineTanker/AbstractMap.cs @@ -18,6 +18,47 @@ namespace GasolineTanker protected readonly int _freeRoad = 0; protected readonly int _barrier = 1; + private Direction GetOpositDirection(Direction d) + { + switch (d) + { + case Direction.None: + return Direction.None; + case Direction.Up: + return Direction.Down; + case Direction.Down: + return Direction.Up; + case Direction.Left: + return Direction.Right; + case Direction.Right: + return Direction.Left; + } + return Direction.None; + } + + private int CheckCollision(float Left, float Right, float Top, float Bottom) + { + int starCellX = (int)(Left / _size_x); + int starCellY = (int)(Right / _size_y); + int endCellX = (int)(Top / _size_x); + int endCellY = (int)(Bottom / _size_y); + if (starCellX < 0 || starCellY < 0 || endCellX >= _map.GetLength(1) || endCellY >= _map.GetLength(0)) + { + return 2; + } + for (int x = starCellX; x <= endCellX; x++) + { + for (int y = starCellY; y <= endCellY; y++) + { + if (_map[x, y] == _barrier) + { + return 1; + } + } + } + return 0; + } + public Bitmap CreateMap(int width, int height, IDrawingObject drawningObject) { _width = width; @@ -30,13 +71,18 @@ namespace GasolineTanker } return DrawMapWithObject(); } + public Bitmap MoveObject(Direction direction) { - // TODO проверка, что объект может переместится в требуемом направлении if (true) { _drawningObject.MoveObject(direction); } + (float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition(); + if (CheckCollision(Left, Right, Top, Bottom) != 0) + { + _drawningObject.MoveObject(GetOpositDirection(direction)); + } return DrawMapWithObject(); } private bool SetObjectOnMap() @@ -48,8 +94,31 @@ namespace GasolineTanker int x = _random.Next(0, 10); int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки - return true; + (float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition(); + float nowX = Left; + float nowY = Right; + float lenX = Top - Left; + float lenY = Bottom - Right; + while (CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY) != 2) + { + int resout; + do + { + resout = CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY); + if (resout == 0) + { + _drawningObject.SetObject((int)nowX, (int)nowY, _width, _height); + return true; + } + else + { + nowX += _size_x; + } + } while (resout != 2); + nowX = x; + nowY += _size_y; + } + return false; } private Bitmap DrawMapWithObject() { diff --git a/GasolineTanker/GasolineTanker/BoxMap.cs b/GasolineTanker/GasolineTanker/BoxMap.cs new file mode 100644 index 0000000..3b5e7f6 --- /dev/null +++ b/GasolineTanker/GasolineTanker/BoxMap.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class BoxMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Blue); + 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, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + 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 < 10) + { + int sx = _random.Next(0, 100); + int sy = _random.Next(0, 100); + int ex = sx + _random.Next(0, 100 - sx); + int ey = sy + _random.Next(0, 100 - sy); + for (int i = sx; i <= ex; ++i) + { + _map[i, ey] = _barrier; + } + for (int i = sy; i <= ey; i++) + { + _map[sx, i] = _barrier; + } + counter++; + } + } + } +} + diff --git a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs index 7e5228d..3bc9e09 100644 --- a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs @@ -27,6 +27,8 @@ namespace GasolineTanker { Brush brOrange = new SolidBrush(Color.Orange); g.FillRectangle(brOrange, _startPosX + 25, _startPosY + 5, 100, 35); + Brush brRed = new SolidBrush(Color.Red); + g.FillRectangle(brRed, _startPosX + 80, _startPosY, 10, 5); } _startPosX += 10; diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs index c68eae8..d2e3fdf 100644 --- a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs @@ -34,7 +34,7 @@ namespace GasolineTanker void IDrawingObject.DrawningObject(Graphics g) { - // TODO + _gasolineTanker.DrawTransport(g); } } } diff --git a/GasolineTanker/GasolineTanker/FormMap.Designer.cs b/GasolineTanker/GasolineTanker/FormMap.Designer.cs index 19516ef..a9e4119 100644 --- a/GasolineTanker/GasolineTanker/FormMap.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMap.Designer.cs @@ -48,8 +48,9 @@ // this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); + this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; - this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428); + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574); this.pictureBoxGasolineTanker.TabIndex = 0; this.pictureBoxGasolineTanker.TabStop = false; // @@ -60,36 +61,38 @@ this.toolStripStatusSpeed, this.toolStripStatusWeight, this.toolStripStatusBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Location = new System.Drawing.Point(0, 574); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(807, 22); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); + this.statusStrip1.Size = new System.Drawing.Size(922, 26); this.statusStrip1.TabIndex = 1; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusSpeed // this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; - this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20); this.toolStripStatusSpeed.Text = "Speed"; // // toolStripStatusWeight // this.toolStripStatusWeight.Name = "toolStripStatusWeight"; - this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); + this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20); this.toolStripStatusWeight.Text = "Weight"; // // toolStripStatusBodyColor // this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; - this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20); this.toolStripStatusBodyColor.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, 393); + this.buttonCreate.Location = new System.Drawing.Point(14, 524); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.Size = new System.Drawing.Size(86, 31); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Create"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -100,9 +103,10 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(724, 386); + this.keyDown.Location = new System.Drawing.Point(827, 515); + this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.Size = new System.Drawing.Size(34, 40); this.keyDown.TabIndex = 3; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); @@ -112,9 +116,10 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(724, 350); + this.keyUp.Location = new System.Drawing.Point(827, 467); + this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.Size = new System.Drawing.Size(34, 40); this.keyUp.TabIndex = 4; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -124,9 +129,10 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(688, 386); + this.keyLeft.Location = new System.Drawing.Point(786, 515); + this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.Size = new System.Drawing.Size(34, 40); this.keyLeft.TabIndex = 5; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -136,18 +142,20 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(760, 386); + this.keyRight.Location = new System.Drawing.Point(869, 515); + this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.Size = new System.Drawing.Size(34, 40); this.keyRight.TabIndex = 6; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // // ButtonCreateImproved // - this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); + this.ButtonCreateImproved.Location = new System.Drawing.Point(106, 524); + this.ButtonCreateImproved.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ButtonCreateImproved.Name = "ButtonCreateImproved"; - this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); + this.ButtonCreateImproved.Size = new System.Drawing.Size(86, 31); this.ButtonCreateImproved.TabIndex = 7; this.ButtonCreateImproved.Text = "Improved"; this.ButtonCreateImproved.UseVisualStyleBackColor = true; @@ -158,18 +166,20 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Simple map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + "Simple map", + "Box map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 16); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28); this.comboBoxSelectorMap.TabIndex = 8; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); // // FormMap // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(807, 450); + this.ClientSize = new System.Drawing.Size(922, 600); this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.ButtonCreateImproved); this.Controls.Add(this.keyRight); @@ -179,6 +189,7 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxGasolineTanker); this.Controls.Add(this.statusStrip1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMap"; this.Text = "Map"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); diff --git a/GasolineTanker/GasolineTanker/FormMap.cs b/GasolineTanker/GasolineTanker/FormMap.cs index 37d5ac9..2efd27f 100644 --- a/GasolineTanker/GasolineTanker/FormMap.cs +++ b/GasolineTanker/GasolineTanker/FormMap.cs @@ -75,6 +75,9 @@ namespace GasolineTanker case "Simple map": _abstractMap = new SimpleMap(); break; + case "Box map": + _abstractMap = new BoxMap(); + break; } } -- 2.25.1 From 74bedf29c8d9c2cf886bf08440bddf0ddeeb647c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 22 Sep 2022 23:45:36 +0400 Subject: [PATCH 5/5] Lab Work 2 --- GasolineTanker/GasolineTanker/AbstractMap.cs | 37 ++++++------ .../GasolineTanker/FormMap.Designer.cs | 56 ++++++++----------- GasolineTanker/GasolineTanker/FormMap.cs | 4 +- .../GasolineTanker/{BoxMap.cs => LongMap.cs} | 25 +++------ 4 files changed, 51 insertions(+), 71 deletions(-) rename GasolineTanker/GasolineTanker/{BoxMap.cs => LongMap.cs} (66%) diff --git a/GasolineTanker/GasolineTanker/AbstractMap.cs b/GasolineTanker/GasolineTanker/AbstractMap.cs index ecfbe80..8b1c8a5 100644 --- a/GasolineTanker/GasolineTanker/AbstractMap.cs +++ b/GasolineTanker/GasolineTanker/AbstractMap.cs @@ -38,17 +38,17 @@ namespace GasolineTanker private int CheckCollision(float Left, float Right, float Top, float Bottom) { - int starCellX = (int)(Left / _size_x); - int starCellY = (int)(Right / _size_y); - int endCellX = (int)(Top / _size_x); - int endCellY = (int)(Bottom / _size_y); - if (starCellX < 0 || starCellY < 0 || endCellX >= _map.GetLength(1) || endCellY >= _map.GetLength(0)) + int starCoordinateX = (int)(Left / _size_x); + int starCoordinateY = (int)(Right / _size_y); + int endCoordinateX = (int)(Top / _size_x); + int endCoordinateY = (int)(Bottom / _size_y); + if (starCoordinateX < 0 || starCoordinateY < 0 || endCoordinateX >= _map.GetLength(1) || endCoordinateY >= _map.GetLength(0)) { return 2; } - for (int x = starCellX; x <= endCellX; x++) + for (int x = starCoordinateX; x <= endCoordinateX; x++) { - for (int y = starCellY; y <= endCellY; y++) + for (int y = starCoordinateY; y <= endCoordinateY; y++) { if (_map[x, y] == _barrier) { @@ -95,28 +95,25 @@ namespace GasolineTanker int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); (float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition(); - float nowX = Left; - float nowY = Right; - float lenX = Top - Left; - float lenY = Bottom - Right; - while (CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY) != 2) + + while (CheckCollision(Left, Right, Top, Bottom) != 2) { - int resout; + int resoult; do { - resout = CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY); - if (resout == 0) + resoult = CheckCollision(Left, Right, Top, Bottom); + if (resoult == 0) { - _drawningObject.SetObject((int)nowX, (int)nowY, _width, _height); + _drawningObject.SetObject((int)Left, (int)Right, _width, _height); return true; } else { - nowX += _size_x; + Left += _size_x; } - } while (resout != 2); - nowX = x; - nowY += _size_y; + } while (resoult != 2); + Left = x; + Right += _size_y; } return false; } diff --git a/GasolineTanker/GasolineTanker/FormMap.Designer.cs b/GasolineTanker/GasolineTanker/FormMap.Designer.cs index a9e4119..a10c10d 100644 --- a/GasolineTanker/GasolineTanker/FormMap.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMap.Designer.cs @@ -48,9 +48,8 @@ // this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); - this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; - this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574); + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428); this.pictureBoxGasolineTanker.TabIndex = 0; this.pictureBoxGasolineTanker.TabStop = false; // @@ -61,38 +60,36 @@ this.toolStripStatusSpeed, this.toolStripStatusWeight, this.toolStripStatusBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 574); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); - this.statusStrip1.Size = new System.Drawing.Size(922, 26); + this.statusStrip1.Size = new System.Drawing.Size(807, 22); this.statusStrip1.TabIndex = 1; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusSpeed // this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; - this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20); + this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); this.toolStripStatusSpeed.Text = "Speed"; // // toolStripStatusWeight // this.toolStripStatusWeight.Name = "toolStripStatusWeight"; - this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20); + this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); this.toolStripStatusWeight.Text = "Weight"; // // toolStripStatusBodyColor // this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; - this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20); + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); this.toolStripStatusBodyColor.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(14, 524); - this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCreate.Location = new System.Drawing.Point(12, 393); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(86, 31); + this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Create"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -103,10 +100,9 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(827, 515); - this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyDown.Location = new System.Drawing.Point(724, 386); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(34, 40); + this.keyDown.Size = new System.Drawing.Size(30, 30); this.keyDown.TabIndex = 3; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); @@ -116,10 +112,9 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(827, 467); - this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyUp.Location = new System.Drawing.Point(724, 350); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(34, 40); + this.keyUp.Size = new System.Drawing.Size(30, 30); this.keyUp.TabIndex = 4; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -129,10 +124,9 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(786, 515); - this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyLeft.Location = new System.Drawing.Point(688, 386); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(34, 40); + this.keyLeft.Size = new System.Drawing.Size(30, 30); this.keyLeft.TabIndex = 5; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -142,20 +136,18 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(869, 515); - this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyRight.Location = new System.Drawing.Point(760, 386); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(34, 40); + this.keyRight.Size = new System.Drawing.Size(30, 30); this.keyRight.TabIndex = 6; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // // ButtonCreateImproved // - this.ButtonCreateImproved.Location = new System.Drawing.Point(106, 524); - this.ButtonCreateImproved.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); this.ButtonCreateImproved.Name = "ButtonCreateImproved"; - this.ButtonCreateImproved.Size = new System.Drawing.Size(86, 31); + this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); this.ButtonCreateImproved.TabIndex = 7; this.ButtonCreateImproved.Text = "Improved"; this.ButtonCreateImproved.UseVisualStyleBackColor = true; @@ -167,19 +159,18 @@ this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { "Simple map", - "Box map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 16); - this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + "Long map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28); + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.TabIndex = 8; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); // // FormMap // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(922, 600); + this.ClientSize = new System.Drawing.Size(807, 450); this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.ButtonCreateImproved); this.Controls.Add(this.keyRight); @@ -189,7 +180,6 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxGasolineTanker); this.Controls.Add(this.statusStrip1); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMap"; this.Text = "Map"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); diff --git a/GasolineTanker/GasolineTanker/FormMap.cs b/GasolineTanker/GasolineTanker/FormMap.cs index 2efd27f..5a322c0 100644 --- a/GasolineTanker/GasolineTanker/FormMap.cs +++ b/GasolineTanker/GasolineTanker/FormMap.cs @@ -75,8 +75,8 @@ namespace GasolineTanker case "Simple map": _abstractMap = new SimpleMap(); break; - case "Box map": - _abstractMap = new BoxMap(); + case "Long map": + _abstractMap = new LongMap(); break; } } diff --git a/GasolineTanker/GasolineTanker/BoxMap.cs b/GasolineTanker/GasolineTanker/LongMap.cs similarity index 66% rename from GasolineTanker/GasolineTanker/BoxMap.cs rename to GasolineTanker/GasolineTanker/LongMap.cs index 3b5e7f6..3bb6102 100644 --- a/GasolineTanker/GasolineTanker/BoxMap.cs +++ b/GasolineTanker/GasolineTanker/LongMap.cs @@ -6,12 +6,9 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal class BoxMap : AbstractMap + internal class LongMap : AbstractMap { - /// - /// Цвет участка закрытого - /// - private readonly Brush barrierColor = new SolidBrush(Color.Blue); + 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) { @@ -34,20 +31,16 @@ namespace GasolineTanker _map[i, j] = _freeRoad; } } - while (counter < 10) + while (counter < 5) { - int sx = _random.Next(0, 100); - int sy = _random.Next(0, 100); - int ex = sx + _random.Next(0, 100 - sx); - int ey = sy + _random.Next(0, 100 - sy); - for (int i = sx; i <= ex; ++i) + int xStart = _random.Next(0, 100); + int xEnd = _random.Next(80, 100); + + for (int i = xStart; i <= xEnd; ++i) { - _map[i, ey] = _barrier; - } - for (int i = sy; i <= ey; i++) - { - _map[sx, i] = _barrier; + _map[i, xStart] = _barrier; } + counter++; } } -- 2.25.1