From ede02decf3fe7a35ec980df0011dcb21d05fe7cc Mon Sep 17 00:00:00 2001 From: Itos Date: Tue, 28 Nov 2023 05:21:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=8F=D0=B3=D0=B0=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GasolineTanker/Form1.Designer.cs | 149 +++++++++--------- GasolineTanker/GasolineTanker/Form1.cs | 54 +++++++ 2 files changed, 131 insertions(+), 72 deletions(-) diff --git a/GasolineTanker/GasolineTanker/Form1.Designer.cs b/GasolineTanker/GasolineTanker/Form1.Designer.cs index 21a3360..220fc1f 100644 --- a/GasolineTanker/GasolineTanker/Form1.Designer.cs +++ b/GasolineTanker/GasolineTanker/Form1.Designer.cs @@ -28,94 +28,99 @@ /// private void InitializeComponent() { - this.Window = new System.Windows.Forms.PictureBox(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.Window)).BeginInit(); + this.PictureBoxGasolineTanker = new System.Windows.Forms.PictureBox(); + this.ButtonCreate = new System.Windows.Forms.Button(); + this.ButtonRight = new System.Windows.Forms.Button(); + this.ButtonDown = new System.Windows.Forms.Button(); + this.ButtonLeft = new System.Windows.Forms.Button(); + this.ButtonUp = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.PictureBoxGasolineTanker)).BeginInit(); this.SuspendLayout(); // - // Window + // PictureBoxGasolineTanker // - this.Window.Dock = System.Windows.Forms.DockStyle.Fill; - this.Window.Location = new System.Drawing.Point(0, 0); - this.Window.Name = "Window"; - this.Window.Size = new System.Drawing.Size(884, 461); - this.Window.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.Window.TabIndex = 0; - this.Window.TabStop = false; + 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(884, 461); + this.PictureBoxGasolineTanker.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.PictureBoxGasolineTanker.TabIndex = 0; + this.PictureBoxGasolineTanker.TabStop = false; // - // buttonCreate + // 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, 426); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); - this.buttonCreate.TabIndex = 1; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; + 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, 426); + this.ButtonCreate.Name = "ButtonCreate"; + this.ButtonCreate.Size = new System.Drawing.Size(75, 23); + this.ButtonCreate.TabIndex = 1; + this.ButtonCreate.Text = "Создать"; + this.ButtonCreate.UseVisualStyleBackColor = true; + this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); // - // buttonRight + // ButtonRight // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::GasolineTanker.Properties.Resources.right; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(842, 419); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 2; - this.buttonRight.UseVisualStyleBackColor = true; + this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRight.BackgroundImage = global::GasolineTanker.Properties.Resources.right; + this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.ButtonRight.Location = new System.Drawing.Point(842, 419); + this.ButtonRight.Name = "ButtonRight"; + this.ButtonRight.Size = new System.Drawing.Size(30, 30); + this.ButtonRight.TabIndex = 2; + this.ButtonRight.UseVisualStyleBackColor = true; + this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click); // - // buttonDown + // ButtonDown // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::GasolineTanker.Properties.Resources.down; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(806, 419); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 3; - this.buttonDown.UseVisualStyleBackColor = true; + this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDown.BackgroundImage = global::GasolineTanker.Properties.Resources.down; + this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.ButtonDown.Location = new System.Drawing.Point(806, 419); + this.ButtonDown.Name = "ButtonDown"; + this.ButtonDown.Size = new System.Drawing.Size(30, 30); + this.ButtonDown.TabIndex = 3; + this.ButtonDown.UseVisualStyleBackColor = true; + this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); // - // buttonLeft + // ButtonLeft // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.left; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(770, 419); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 4; - this.buttonLeft.UseVisualStyleBackColor = true; + this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.left; + this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.ButtonLeft.Location = new System.Drawing.Point(770, 419); + this.ButtonLeft.Name = "ButtonLeft"; + this.ButtonLeft.Size = new System.Drawing.Size(30, 30); + this.ButtonLeft.TabIndex = 4; + this.ButtonLeft.UseVisualStyleBackColor = true; + this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // - // buttonUp + // ButtonUp // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::GasolineTanker.Properties.Resources.up; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(806, 383); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 5; - this.buttonUp.UseVisualStyleBackColor = true; + this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUp.BackgroundImage = global::GasolineTanker.Properties.Resources.up; + this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.ButtonUp.Location = new System.Drawing.Point(806, 383); + this.ButtonUp.Name = "ButtonUp"; + this.ButtonUp.Size = new System.Drawing.Size(30, 30); + this.ButtonUp.TabIndex = 5; + this.ButtonUp.UseVisualStyleBackColor = true; + this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // GasolineTanker // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(884, 461); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.Window); + this.Controls.Add(this.ButtonUp); + this.Controls.Add(this.ButtonLeft); + this.Controls.Add(this.ButtonDown); + this.Controls.Add(this.ButtonRight); + this.Controls.Add(this.ButtonCreate); + this.Controls.Add(this.PictureBoxGasolineTanker); this.Name = "GasolineTanker"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "GasolineTanker"; - ((System.ComponentModel.ISupportInitialize)(this.Window)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PictureBoxGasolineTanker)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -123,11 +128,11 @@ #endregion - private PictureBox Window; - private Button buttonCreate; - private Button buttonRight; - private Button buttonDown; - private Button buttonLeft; - private Button buttonUp; + private PictureBox PictureBoxGasolineTanker; + private Button ButtonCreate; + private Button ButtonRight; + private Button ButtonDown; + private Button ButtonLeft; + private Button ButtonUp; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/Form1.cs b/GasolineTanker/GasolineTanker/Form1.cs index 6825dd1..dc907fb 100644 --- a/GasolineTanker/GasolineTanker/Form1.cs +++ b/GasolineTanker/GasolineTanker/Form1.cs @@ -2,9 +2,63 @@ namespace GasolineTanker { public partial class GasolineTanker : Form { + private DrawningGasolineTanker? _drawningGasolineTanker; public GasolineTanker() { InitializeComponent(); } + private void Draw() + { + if (_drawningGasolineTanker == null) + return; + + Bitmap bmp = new(PictureBoxGasolineTanker.Width, PictureBoxGasolineTanker.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningGasolineTanker.DrawTransport(gr); + PictureBoxGasolineTanker.Image = bmp; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningGasolineTanker = new DrawningGasolineTanker(); + _drawningGasolineTanker.Init(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + PictureBoxGasolineTanker.Width, PictureBoxGasolineTanker.Height); + _drawningGasolineTanker.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningGasolineTanker == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "ButtonUp": + _drawningGasolineTanker.MoveTransport(Direction.Up); + break; + case "ButtonDown": + _drawningGasolineTanker.MoveTransport(Direction.Down); + break; + case "ButtonLeft": + _drawningGasolineTanker.MoveTransport(Direction.Left); + break; + case "ButtonRight": + _drawningGasolineTanker.MoveTransport(Direction.Right); + break; + } + Draw(); + } + } } \ No newline at end of file