From 38040108d6c444fac67e76ca0f5415c148201fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 20 Oct 2022 16:34:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotives/Locomotives/FormMap.Designer.cs | 239 ------------------ Locomotives/Locomotives/FormMap.cs | 121 --------- Locomotives/Locomotives/FormMap.resx | 63 ----- .../Locomotives/FormMapWithSetLocomotives.cs | 4 +- .../MapWithSetLocomotivesGeneric.cs | 10 +- .../Locomotives/SetLocomotivesGeneric.cs | 20 +- Locomotives/Locomotives/SimpleMap.cs | 20 +- 7 files changed, 28 insertions(+), 449 deletions(-) delete mode 100644 Locomotives/Locomotives/FormMap.Designer.cs delete mode 100644 Locomotives/Locomotives/FormMap.cs delete mode 100644 Locomotives/Locomotives/FormMap.resx diff --git a/Locomotives/Locomotives/FormMap.Designer.cs b/Locomotives/Locomotives/FormMap.Designer.cs deleted file mode 100644 index 1d77af6..0000000 --- a/Locomotives/Locomotives/FormMap.Designer.cs +++ /dev/null @@ -1,239 +0,0 @@ -namespace Locomotives -{ - 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.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); - this.statusStrip = 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.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxLocomotive - // - this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); - this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1); - this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; - this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450); - this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxLocomotive.TabIndex = 0; - this.pictureBoxLocomotive.TabStop = false; - // - // statusStrip - // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor, - this.toolStripStatusLabelAdditionalColor, - this.toolStripStatusLabelHasPipe, - this.toolStripStatusLabelHasFuelTank}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость: "; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); - this.toolStripStatusLabelWeight.Text = "Вес: "; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет: "; - // - // toolStripStatusLabelAdditionalColor - // - this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; - this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); - this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; - // - // toolStripStatusLabelHasPipe - // - this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; - this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); - this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; - // - // toolStripStatusLabelHasFuelTank - // - this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; - this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); - this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: "; - // - // 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, 395); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(90, 30); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Locomotives.Properties.Resources.ArrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(758, 395); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 3; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.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::Locomotives.Properties.Resources.ArrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(686, 395); - 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::Locomotives.Properties.Resources.ArrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(722, 395); - 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); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Locomotives.Properties.Resources.ArrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(722, 359); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 6; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Карта с крестом", - "Карта с дорожками"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(141, 23); - this.comboBoxSelectorMap.TabIndex = 7; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); - this.comboBoxSelectorMap.SelectedIndex = 0; - // - // buttonCreateModif - // - this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreateModif.Location = new System.Drawing.Point(108, 395); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(109, 30); - this.buttonCreateModif.TabIndex = 8; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.statusStrip); - this.Controls.Add(this.pictureBoxLocomotive); - this.Name = "FormMap"; - this.Text = "Локомотив"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxLocomotive; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreate; - private Button buttonRight; - private Button buttonLeft; - private Button buttonDown; - private Button buttonUp; - private ComboBox comboBoxSelectorMap; - private Button buttonCreateModif; - private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; - private ToolStripStatusLabel toolStripStatusLabelHasPipe; - private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; - } -} \ No newline at end of file diff --git a/Locomotives/Locomotives/FormMap.cs b/Locomotives/Locomotives/FormMap.cs deleted file mode 100644 index 96188d1..0000000 --- a/Locomotives/Locomotives/FormMap.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace Locomotives -{ - public partial class FormMap : Form - { - /// - /// Создание объекта от абстрактного класса карты - /// - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Заполнение информации по объекту - /// - /// Объект от класса отрисовки или его наследника - private void SetData(DrawningLocomotive locomotive) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}"; - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д"; - pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, - new DrawningObjectLocomotive(locomotive)); - } - /// - /// Заполнение дополнительной информации по объекту (только для усложнённого объекта) - /// - /// Объект от наследника класса отрисовки - private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive) - { - if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive) - { - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}"; - } - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(locomotive); - } - /// - /// Перемещение объекта по форме - /// - /// - /// - 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; - } - pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void ButtonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - 160, 85, - 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(locomotive); - SetAdditionalData(locomotive); - } - /// - /// Смена карты - /// - /// - /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Карта с крестом": - _abstractMap = new CrossMap(); - break; - case "Карта с дорожками": - _abstractMap = new RoadsMap(); - break; - default: - break; - } - } - } -} diff --git a/Locomotives/Locomotives/FormMap.resx b/Locomotives/Locomotives/FormMap.resx deleted file mode 100644 index 2c0949d..0000000 --- a/Locomotives/Locomotives/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/Locomotives/Locomotives/FormMapWithSetLocomotives.cs b/Locomotives/Locomotives/FormMapWithSetLocomotives.cs index 3473ca9..9b1e87c 100644 --- a/Locomotives/Locomotives/FormMapWithSetLocomotives.cs +++ b/Locomotives/Locomotives/FormMapWithSetLocomotives.cs @@ -63,7 +63,7 @@ if (form.ShowDialog() == DialogResult.OK) { DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); - if (_mapCarsCollectionGeneric + locomotive) + if ((_mapCarsCollectionGeneric + locomotive) > -1) { MessageBox.Show("Объект добавлен"); pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); @@ -90,7 +90,7 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapCarsCollectionGeneric - pos) + if ((_mapCarsCollectionGeneric - pos) > -1) { MessageBox.Show("Объект удален"); pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); diff --git a/Locomotives/Locomotives/MapWithSetLocomotivesGeneric.cs b/Locomotives/Locomotives/MapWithSetLocomotivesGeneric.cs index 324414a..e26b025 100644 --- a/Locomotives/Locomotives/MapWithSetLocomotivesGeneric.cs +++ b/Locomotives/Locomotives/MapWithSetLocomotivesGeneric.cs @@ -49,7 +49,7 @@ /// /// /// - public static bool operator +(MapWithSetLocomotivesGeneric map, T locomotive) + public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive) { return map._setLocomotives.Insert(locomotive); } @@ -59,7 +59,7 @@ /// /// /// - public static bool operator -(MapWithSetLocomotivesGeneric map, int position) + public static int operator -(MapWithSetLocomotivesGeneric map, int position) { return map._setLocomotives.Remove(position); } @@ -138,11 +138,13 @@ /// private void DrawBackground(Graphics g) { - Pen pen = new(Color.Black, 3); + Pen pen = new(Color.Brown, 3); + Brush brBackground = new SolidBrush(Color.Yellow); + g.FillRectangle(brBackground, 0, 0, _pictureWidth, _pictureHeight); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) - {//линия рамзетки места + {//линия разметки места g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } diff --git a/Locomotives/Locomotives/SetLocomotivesGeneric.cs b/Locomotives/Locomotives/SetLocomotivesGeneric.cs index 4acfef9..e5e0bb2 100644 --- a/Locomotives/Locomotives/SetLocomotivesGeneric.cs +++ b/Locomotives/Locomotives/SetLocomotivesGeneric.cs @@ -24,7 +24,7 @@ /// /// Добавляемый локомотив /// - public bool Insert(T locomotive) + public int Insert(T locomotive) { // TODO проверка на наличие свободных мест T testLocomotive = _places[0]; @@ -37,14 +37,14 @@ } if (testLocomotive != null) { - return false; + return -1; } for (int i = Count - 2; i >= 0; i--) { _places[i + 1] = _places[i]; } _places[0] = locomotive; - return true; + return 0; } /// /// Добавление объекта в набор на конкретную позицию @@ -52,7 +52,7 @@ /// Добавляемый локомотив /// Позиция /// - public bool Insert(T locomotive, int position) + public int Insert(T locomotive, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то @@ -61,14 +61,14 @@ // TODO вставка по позиции if (position < 0 || position >= Count) { - return false; + return position; } int ClosestNullElementIndex = position; while (_places[ClosestNullElementIndex] != null) { if (ClosestNullElementIndex == Count) { - return false; + return position; } ClosestNullElementIndex++; } @@ -78,23 +78,23 @@ ClosestNullElementIndex--; } _places[position] = locomotive; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public bool Remove(int position) + public int Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присовив элементу массива значение null if (_places[position] == null) { - return false; + return -1; } _places[position] = null; - return true; + return position; } /// /// Получение объекта из набора по позиции diff --git a/Locomotives/Locomotives/SimpleMap.cs b/Locomotives/Locomotives/SimpleMap.cs index 1acc472..0a3969b 100644 --- a/Locomotives/Locomotives/SimpleMap.cs +++ b/Locomotives/Locomotives/SimpleMap.cs @@ -34,16 +34,16 @@ _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++; - // } - //} + 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++; + } + } } } }