From d0f8f3c1b89f708cbee65de74a30a68dfb2824b5 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:56:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractor.Designer.cs | 134 ------------- .../RPP_FirstLaba_Tractor/FormTractor.cs | 186 ++++++++++++++++++ 2 files changed, 186 insertions(+), 134 deletions(-) delete mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs deleted file mode 100644 index 1429b67..0000000 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.Designer.cs +++ /dev/null @@ -1,134 +0,0 @@ -namespace RPP_FirstLaba_Tractor -{ - partial class FormTractor - { - /// - /// 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.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.buttonTop = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonCreate = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox1 - // - this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox1.Location = new System.Drawing.Point(0, 0); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(882, 453); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - // - // buttonTop - // - this.buttonTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTop.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowUp; - this.buttonTop.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonTop.Location = new System.Drawing.Point(804, 376); - this.buttonTop.Name = "buttonTop"; - this.buttonTop.Size = new System.Drawing.Size(30, 30); - this.buttonTop.TabIndex = 1; - this.buttonTop.UseVisualStyleBackColor = true; - // - // button2 - // - this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button2.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowLeft; - this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.button2.Location = new System.Drawing.Point(768, 411); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(30, 30); - this.button2.TabIndex = 2; - this.button2.UseVisualStyleBackColor = true; - // - // button3 - // - this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button3.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowDown; - this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.button3.Location = new System.Drawing.Point(804, 411); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(30, 30); - this.button3.TabIndex = 3; - this.button3.UseVisualStyleBackColor = true; - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(840, 411); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 4; - this.buttonRight.UseVisualStyleBackColor = true; - // - // 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, 412); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(93, 30); - this.buttonCreate.TabIndex = 5; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - // - // FormTractor - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(882, 453); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.button3); - this.Controls.Add(this.button2); - this.Controls.Add(this.buttonTop); - this.Controls.Add(this.pictureBox1); - this.Name = "FormTractor"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "FormTractor"; - this.Load += new System.EventHandler(this.FormTractor_Load); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBox1; - private Button buttonTop; - private Button button2; - private Button button3; - private Button buttonRight; - private Button buttonCreate; - } -} \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs index efa948a..23c4cac 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs @@ -1,11 +1,197 @@ namespace RPP_FirstLaba_Tractor { + /// + /// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñïîðòèâíûé àâòîìîáèëü" + /// public partial class FormTractor : Form { + private PictureBox pictureBoxTractor; + private Button buttonCreate; + private Button buttonTop; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + + public int getPictureWidth() + { + return pictureBoxTractor.Width; + } + public int getPictureHeight() + { + return pictureBoxTractor.Height; + } + + /// + /// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà + /// + private DrawningTractor? _drawningTractor; + /// + /// Èíèöèàëèçàöèÿ ôîðìû + /// public FormTractor() { InitializeComponent(); } + /// + /// Ìåòîä ïðîðèñîâêè ìàøèíû + /// + private void Draw() + { + if (_drawningTractor == null) + { + return; + } + Bitmap bmp = new(pictureBoxTractor.Width, + pictureBoxTractor.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningTractor.DrawTransport(gr); + pictureBoxTractor.Image = bmp; + } + /// + /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningTractor = new DrawningTractor(); + _drawningTractor.Init(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + pictureBoxTractor.Width, pictureBoxTractor.Height); + _drawningTractor.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + + /// + /// Èçìåíåíèå ðàçìåðîâ ôîðìû + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningTractor == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonTop": + _drawningTractor.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningTractor.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningTractor.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningTractor.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + + private void InitializeComponent() + { + this.pictureBoxTractor = new System.Windows.Forms.PictureBox(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonTop = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit(); + this.SuspendLayout(); + // + // pictureBoxTractor + // + this.pictureBoxTractor.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxTractor.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTractor.Name = "pictureBoxTractor"; + this.pictureBoxTractor.Size = new System.Drawing.Size(891, 490); + this.pictureBoxTractor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxTractor.TabIndex = 0; + this.pictureBoxTractor.TabStop = false; + // + // 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, 440); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(94, 29); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Ñîçäàòü"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonTop + // + this.buttonTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonTop.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowUp; + this.buttonTop.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonTop.Location = new System.Drawing.Point(813, 412); + this.buttonTop.Name = "buttonTop"; + this.buttonTop.Size = new System.Drawing.Size(30, 30); + this.buttonTop.TabIndex = 2; + this.buttonTop.UseVisualStyleBackColor = true; + this.buttonTop.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(777, 448); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 3; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(813, 448); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 4; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(849, 448); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 5; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // FormTractor + // + this.ClientSize = new System.Drawing.Size(891, 490); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonTop); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxTractor); + this.Name = "FormTractor"; + this.Load += new System.EventHandler(this.FormTractor_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } private void FormTractor_Load(object sender, EventArgs e) {