diff --git a/WinFormsApp1.rar1 b/WinFormsApp1.rar1 index 25038de..cae724a 100644 Binary files a/WinFormsApp1.rar1 and b/WinFormsApp1.rar1 differ diff --git a/WinFormsApp1/Direction.cs b/WinFormsApp1/Direction.cs index 371a417..7a1c31b 100644 --- a/WinFormsApp1/Direction.cs +++ b/WinFormsApp1/Direction.cs @@ -4,7 +4,7 @@ using System.Text; namespace WinFormsApp1 { - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/WinFormsApp1/EntityTractor.cs b/WinFormsApp1/EntityTractor.cs index f401a35..d7fe3c3 100644 --- a/WinFormsApp1/EntityTractor.cs +++ b/WinFormsApp1/EntityTractor.cs @@ -7,7 +7,7 @@ using System.Drawing; namespace WinFormsApp1 { - class EntityTractor + public class EntityTractor { /// /// Скорость diff --git a/WinFormsApp1/FormMap.Designer.cs b/WinFormsApp1/FormMap.Designer.cs deleted file mode 100644 index 0da36fd..0000000 --- a/WinFormsApp1/FormMap.Designer.cs +++ /dev/null @@ -1,210 +0,0 @@ - -namespace WinFormsApp1 -{ - 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.pictureBoxTractor = new System.Windows.Forms.PictureBox(); - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - this.comboBoxSelectionMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit(); - this.statusStrip1.SuspendLayout(); - 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(800, 424); - this.pictureBoxTractor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxTractor.TabIndex = 0; - this.pictureBoxTractor.TabStop = false; - // - // statusStrip1 - // - this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 424); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(800, 26); - this.statusStrip1.TabIndex = 1; - this.statusStrip1.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(73, 20); - this.toolStripStatusLabelSpeed.Text = "Скорость"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 20); - this.toolStripStatusLabelWeight.Text = "вес"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(42, 20); - this.toolStripStatusLabelBodyColor.Text = "Цвет"; - this.toolStripStatusLabelBodyColor.Click += new System.EventHandler(this.ButtonMove_Click); - // - // 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(0, 378); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(94, 29); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(682, 296); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 3; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonLeft - // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(649, 332); - 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); - // - // buttonDown - // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(682, 332); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 5; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(718, 332); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 6; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonCreateModif - // - this.buttonCreateModif.Location = new System.Drawing.Point(111, 378); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(129, 27); - this.buttonCreateModif.TabIndex = 7; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); - // - // comboBoxSelectionMap - // - this.comboBoxSelectionMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectionMap.FormattingEnabled = true; - this.comboBoxSelectionMap.Items.AddRange(new object[] { - "Простая карта", - "Поле"}); - this.comboBoxSelectionMap.Location = new System.Drawing.Point(0, 0); - this.comboBoxSelectionMap.Name = "comboBoxSelectionMap"; - this.comboBoxSelectionMap.Size = new System.Drawing.Size(194, 28); - this.comboBoxSelectionMap.TabIndex = 8; - this.comboBoxSelectionMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectionMap_SelectedIndexChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.comboBoxSelectionMap); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.pictureBoxTractor); - this.Controls.Add(this.statusStrip1); - this.Name = "FormMap"; - this.Text = "FormMap"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private System.Windows.Forms.PictureBox pictureBoxTractor; - private System.Windows.Forms.StatusStrip statusStrip1; - private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed; - private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight; - private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor; - private System.Windows.Forms.Button buttonCreate; - private System.Windows.Forms.Button buttonUp; - private System.Windows.Forms.Button buttonLeft; - private System.Windows.Forms.Button buttonDown; - private System.Windows.Forms.Button buttonRight; - private System.Windows.Forms.Button buttonCreateModif; - private System.Windows.Forms.ComboBox comboBoxSelectionMap; - } -} \ No newline at end of file diff --git a/WinFormsApp1/FormMap.cs b/WinFormsApp1/FormMap.cs deleted file mode 100644 index 7f03745..0000000 --- a/WinFormsApp1/FormMap.cs +++ /dev/null @@ -1,90 +0,0 @@ -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 WinFormsApp1 -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - //Заполнение информации по объекту - private void SetData(TractorDraw tractor) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {tractor.Tractor.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {tractor.Tractor.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {tractor.Tractor.BodyColor.Name}"; - pictureBoxTractor.Image = _abstractMap.CreateMap(pictureBoxTractor.Width, pictureBoxTractor.Height, - new DrawningObjectTractor(tractor)); - } - - //Логика кнопки Создать - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random random = new(); - var tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - SetData(tractor); - } - - private void ButtonMove_Click(object sender, EventArgs e) - { - //получаем имя кнопки - string name = ((Button)sender)?.Name ?? string.Empty; - Direction dir = Direction.None; - switch (name) - { - case "buttonUp": - dir = Direction.Up; - break; - case "buttonDown": - dir = Direction.Down; - break; - case "buttonLeft": - dir = Direction.Left; - break; - case "buttonRight": - dir = Direction.Right; - break; - } - pictureBoxTractor.Image = _abstractMap?.MoveObject(dir); - } - - // Обработка нажатия кнопки "Модификация" - private void buttonCreateModif_Click(object sender, EventArgs e) - { - Random random = new Random(); - var _Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000), - 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))); - SetData(_Tractor); - } - - private void comboBoxSelectionMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectionMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Поле": - _abstractMap = new FieldMap(); - break; - } - - } - - - } -} diff --git a/WinFormsApp1/FormMap.resx b/WinFormsApp1/FormMap.resx deleted file mode 100644 index 5cb320f..0000000 --- a/WinFormsApp1/FormMap.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/WinFormsApp1/FormMapWithSetTraktor.Designer.cs b/WinFormsApp1/FormMapWithSetTraktor.Designer.cs new file mode 100644 index 0000000..ea8d8b2 --- /dev/null +++ b/WinFormsApp1/FormMapWithSetTraktor.Designer.cs @@ -0,0 +1,216 @@ +using System.Windows.Forms; + +namespace WinFormsApp1 +{ + partial class FormMapWithSetTraktor + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + 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(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonRemoveTraktor = new System.Windows.Forms.Button(); + this.buttonAddTraktor = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonShowOnMap); + this.groupBox1.Controls.Add(this.buttonShowStorage); + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.buttonRemoveTraktor); + this.groupBox1.Controls.Add(this.buttonAddTraktor); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox1.Location = new System.Drawing.Point(832, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(250, 518); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Инструменты"; + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(55, 426); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(40, 40); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(15, 466); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(40, 40); + this.buttonLeft.TabIndex = 8; + 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::Tractors.Properties.Resources.MbV2DYU_nPM; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(55, 466); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(40, 40); + this.buttonDown.TabIndex = 9; + 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::Tractors.Properties.Resources.RkYIe2_6DuQ; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(95, 466); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(40, 40); + this.buttonRight.TabIndex = 10; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(6, 281); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(193, 29); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(6, 246); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(193, 29); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122); + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27); + this.maskedTextBoxPosition.TabIndex = 11; + // + // buttonRemoveTraktor + // + this.buttonRemoveTraktor.Location = new System.Drawing.Point(6, 155); + this.buttonRemoveTraktor.Name = "buttonRemoveTraktor"; + this.buttonRemoveTraktor.Size = new System.Drawing.Size(151, 32); + this.buttonRemoveTraktor.TabIndex = 2; + this.buttonRemoveTraktor.Text = "Удалить трактор"; + this.buttonRemoveTraktor.UseVisualStyleBackColor = true; + this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveTraktor_Click); + // + // buttonAddTraktor + // + this.buttonAddTraktor.Location = new System.Drawing.Point(6, 83); + this.buttonAddTraktor.Name = "buttonAddTraktor"; + this.buttonAddTraktor.Size = new System.Drawing.Size(151, 33); + this.buttonAddTraktor.TabIndex = 1; + this.buttonAddTraktor.Text = "Добавить трактор"; + this.buttonAddTraktor.UseVisualStyleBackColor = true; + this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Поле"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(832, 518); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetTraktor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1082, 518); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetTraktor"; + this.Text = "Трактор"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRemoveTraktor; + private Button buttonAddTraktor; + private ComboBox comboBoxSelectorMap; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/WinFormsApp1/FormMapWithSetTraktor.cs b/WinFormsApp1/FormMapWithSetTraktor.cs new file mode 100644 index 0000000..2ab0829 --- /dev/null +++ b/WinFormsApp1/FormMapWithSetTraktor.cs @@ -0,0 +1,150 @@ +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; +using WinFormsApp1; + +namespace WinFormsApp1 +{ + public partial class FormMapWithSetTraktor : Form + { + private MapWithSetTraktorGeneric _mapTraktorCollectionGeneric; + + //DrawingBus SelectedBus { get; private set; } + + public FormMapWithSetTraktor() + { + InitializeComponent(); + AbstractMap map = new SimpleMap(); + _mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric( + pictureBox.Width, pictureBox.Height, map); + + } + + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Поле": + map = new FieldMap(); + break; + } + + if (map != null) + { + _mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric(pictureBox.Width, pictureBox.Height, map); + } + + else + { + _mapTraktorCollectionGeneric = null; + } + } + + private void ButtonAddTraktor_Click(object sender, EventArgs e) + { + if (_mapTraktorCollectionGeneric == null) + { + return; + } + FormTractor form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.SelectedTractor == null) + { + MessageBox.Show("Сначала создайте объект"); + return; + } + + DrawningObjectTractor bus = new(form.SelectedTractor); + + if (_mapTraktorCollectionGeneric + bus != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemoveTraktor_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapTraktorCollectionGeneric - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapTraktorCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); + } + + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapTraktorCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapTraktorCollectionGeneric.ShowOnMap(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapTraktorCollectionGeneric == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBox.Image = _mapTraktorCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/WinFormsApp1/FormMapWithSetTraktor.resx b/WinFormsApp1/FormMapWithSetTraktor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsApp1/FormMapWithSetTraktor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormsApp1/FormTractor.Designer.cs b/WinFormsApp1/FormTractor.Designer.cs index 1615d46..9952f70 100644 --- a/WinFormsApp1/FormTractor.Designer.cs +++ b/WinFormsApp1/FormTractor.Designer.cs @@ -40,6 +40,7 @@ namespace WinFormsApp1 this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectedTractor = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -156,11 +157,22 @@ namespace WinFormsApp1 this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); // + // buttonSelectedTractor + // + this.buttonSelectedTractor.Location = new System.Drawing.Point(262, 372); + this.buttonSelectedTractor.Name = "buttonSelectedTractor"; + this.buttonSelectedTractor.Size = new System.Drawing.Size(89, 35); + this.buttonSelectedTractor.TabIndex = 8; + this.buttonSelectedTractor.Text = "Выбрать"; + this.buttonSelectedTractor.UseVisualStyleBackColor = true; + this.buttonSelectedTractor.Click += new System.EventHandler(this.buttonSelectedTractor_Click); + // // FormTractor // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelectedTractor); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -192,6 +204,7 @@ namespace WinFormsApp1 private System.Windows.Forms.Button buttonDown; private System.Windows.Forms.Button buttonRight; private System.Windows.Forms.Button buttonCreateModif; + private System.Windows.Forms.Button buttonSelectedTractor; } } diff --git a/WinFormsApp1/FormTractor.cs b/WinFormsApp1/FormTractor.cs index cd79669..65dae70 100644 --- a/WinFormsApp1/FormTractor.cs +++ b/WinFormsApp1/FormTractor.cs @@ -14,6 +14,7 @@ namespace WinFormsApp1 { private TractorDraw _Tractor; + public TractorDraw SelectedTractor { get; private set; } public FormTractor() { InitializeComponent(); @@ -39,8 +40,13 @@ namespace WinFormsApp1 private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _Tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - SetData(); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _Tractor = new TractorDraw(random.Next(100, 300), random.Next(1000, 2000), color); SetData(); Draw(); } @@ -83,11 +89,30 @@ namespace WinFormsApp1 private void buttonCreateModif_Click(object sender, EventArgs e) { Random random = new Random(); - _Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000), - 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))); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + + _Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor); + SetData(); Draw(); } + + private void buttonSelectedTractor_Click(object sender, EventArgs e) + { + SelectedTractor = _Tractor; + DialogResult = DialogResult.OK; + } } } diff --git a/WinFormsApp1/MapWithSetTraktorGeneric.cs b/WinFormsApp1/MapWithSetTraktorGeneric.cs index 9ebc163..4fdf93d 100644 --- a/WinFormsApp1/MapWithSetTraktorGeneric.cs +++ b/WinFormsApp1/MapWithSetTraktorGeneric.cs @@ -13,8 +13,8 @@ namespace WinFormsApp1 { private readonly int _pictureWidth; private readonly int _pictureHeight; - private readonly int _placeSizeWidth = 180; - private readonly int _placeSizeHeight = 150; + private readonly int _placeSizeWidth = 250; + private readonly int _placeSizeHeight = 250; private readonly SetTraktorGeneric _setTraktors; private readonly U _map; @@ -122,7 +122,7 @@ namespace WinFormsApp1 for (int i = _setTraktors.Count; i >= 0; i--) { _setTraktors.Get(i)?.SetObject( - _pictureWidth - _placeSizeWidth * curWidth - 20, + _pictureWidth - _placeSizeWidth * curWidth - 60, curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight); _setTraktors.Get(i)?.DrawningObject(g); diff --git a/WinFormsApp1/Program.cs b/WinFormsApp1/Program.cs index d6c746a..8196d6e 100644 --- a/WinFormsApp1/Program.cs +++ b/WinFormsApp1/Program.cs @@ -17,7 +17,7 @@ namespace WinFormsApp1 Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetTraktor()); } } } diff --git a/WinFormsApp1/TractorDraw.cs b/WinFormsApp1/TractorDraw.cs index 635410f..d97024e 100644 --- a/WinFormsApp1/TractorDraw.cs +++ b/WinFormsApp1/TractorDraw.cs @@ -7,7 +7,7 @@ using System.Drawing; namespace WinFormsApp1 { - class TractorDraw + public class TractorDraw { //Сущность diff --git a/WinFormsApp1/Tractors.csproj b/WinFormsApp1/Tractors.csproj index c0aed77..2f866a5 100644 --- a/WinFormsApp1/Tractors.csproj +++ b/WinFormsApp1/Tractors.csproj @@ -2,7 +2,7 @@ WinExe - net5.0-windows + net6.0-windows true