From 013dcd954da175cdd05d9d4c60af659bc072ea97 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 5 Oct 2022 21:57:34 +0400 Subject: [PATCH 1/5] Generic classes. --- Airbus/Airbus/Airbus.csproj | 4 + Airbus/Airbus/MapWithSetPlanesGeneric.cs | 144 +++++++++++++++++++++++ Airbus/Airbus/SetPlanesGeneric.cs | 61 ++++++++++ 3 files changed, 209 insertions(+) create mode 100644 Airbus/Airbus/MapWithSetPlanesGeneric.cs create mode 100644 Airbus/Airbus/SetPlanesGeneric.cs diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 13ee123..f2a984c 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -23,4 +23,8 @@ + + + + \ No newline at end of file diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs new file mode 100644 index 0000000..ef66b81 --- /dev/null +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + //карта с набором объектов под неё + internal class MapWithSetPlanesGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + //ширина окна отрисовки + private readonly int _pictureWidth; + //высота окна отрисовки + private readonly int _pictureHeight; + //размер занимаемого объектом места (ширина) + private readonly int _placeSizeWidth = 210; + //размер занимаемого объектом места (высота) + private readonly int _placeSizeHeight = 90; + //набор объектов + private readonly SetPlanesGeneric _setPlanes; + //карта + private readonly U _map; + + //конструктор + public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setPlanes = new SetPlanesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + + //пеергрузка оператора сложения + public static bool operator +(MapWithSetPlanesGeneric map, T plane) + { + return map._setPlanes.Insert(plane); + } + + //перегрузка оператора вычитания + public static bool operator -(MapWithSetPlanesGeneric map, int position) + { + return map._setPlanes.Remove(position); + } + + //вывод всего набора объектов + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawPlanes(gr); + return bmp; + } + + //просмотр объекта на карте + public Bitmap ShowOnMap() + { + Shaking(); + + for(int i = 0; i < _setPlanes.Count; i++) + { + var plane = _setPlanes.Get(i); + + if(plane != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, plane); + } + } + + return new(_pictureWidth, _pictureHeight); + } + + //пеермещение объекта по карте + public Bitmap MoveObject(Direction direction) + { + if(_map != null) + { + return _map.MoveObject(direction); + } + + return new(_pictureWidth, _pictureHeight); + } + + //"взламываем" набор, чтобы все элементы оказались в начале + private void Shaking() + { + int j = _setPlanes.Count - 1; + + for (int i = 0; i < _setPlanes.Count; i++) + { + if (_setPlanes.Get(i) == null) + { + for (; j > i; j--) + { + var car = _setPlanes.Get(j); + + if (car != null) + { + _setPlanes.Insert(car, i); + _setPlanes.Remove(j); + break; + } + } + + if (j <= i) + { + return; + } + } + } + } + + //метод отрисовки фона + public void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + + 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); + } + + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + + //метод прорисовки объеков + public void DrawPlanes(Graphics g) + { + for(int i = 0; i < _setPlanes.Count; i++) + { + //TODO установка позиции + _setPlanes.Get(i)?.DrawningObject(g); + } + } + } +} diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs new file mode 100644 index 0000000..2f20084 --- /dev/null +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class SetPlanesGeneric + where T: class + { + //массив объектов, которые храним + private readonly T[] _places; + + //количество объектов в массиве + public int Count => _places.Length; + + //конструктор + public SetPlanesGeneric(int count) + { + _places = new T[count]; + } + + //добавление объекта в набор + public bool Insert(T plane) + { + //TODO вставка в начало набора + return true; + } + + //добавление объекта в набор на конкретную позицию + public bool Insert(T plane, int position) + { + //TODO проверка позиции + //TODO проверка, что элемент массива на этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех элементов, находящихся справа от позиции до первого пустого элемента + //TODO втсавка по позиции + + _places[position] = plane; + return true; + } + + //удаление объекта из набора с конкретной позиции + public bool Remove(int position) + { + //TODO проверка позиции + //TODO удаление объекта из массива, присвоив элементу массива значение null + + return true; + } + + //получение объекта из набора по позиции + public T Get(int position) + { + //TODO проверка позиции + + return _places[position]; + } + } +} -- 2.25.1 From a62a94f1d17af6e51e50669ad925b02945e709db Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 5 Oct 2022 23:08:51 +0400 Subject: [PATCH 2/5] Changes forms. --- Airbus/Airbus/Direction.cs | 2 +- Airbus/Airbus/DrawningAirbus.cs | 2 +- Airbus/Airbus/EntityAirbus.cs | 2 +- Airbus/Airbus/FormAirbus.Designer.cs | 13 ++ Airbus/Airbus/FormAirbus.cs | 9 + Airbus/Airbus/FormMap.Designer.cs | 211 ------------------ Airbus/Airbus/FormMap.cs | 96 -------- .../Airbus/FormMapWithSetPlanes.Designer.cs | 205 +++++++++++++++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 151 +++++++++++++ ...FormMap.resx => FormMapWithSetPlanes.resx} | 3 - Airbus/Airbus/MapWithSetPlanesGeneric.cs | 5 + Airbus/Airbus/Program.cs | 2 +- 12 files changed, 387 insertions(+), 314 deletions(-) delete mode 100644 Airbus/Airbus/FormMap.Designer.cs delete mode 100644 Airbus/Airbus/FormMap.cs create mode 100644 Airbus/Airbus/FormMapWithSetPlanes.Designer.cs create mode 100644 Airbus/Airbus/FormMapWithSetPlanes.cs rename Airbus/Airbus/{FormMap.resx => FormMapWithSetPlanes.resx} (93%) diff --git a/Airbus/Airbus/Direction.cs b/Airbus/Airbus/Direction.cs index 7e54263..1e92fc1 100644 --- a/Airbus/Airbus/Direction.cs +++ b/Airbus/Airbus/Direction.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Airbus { //направление перемещения - internal enum Direction + public enum Direction { Up = 1, Down = 2, diff --git a/Airbus/Airbus/DrawningAirbus.cs b/Airbus/Airbus/DrawningAirbus.cs index 40b09ad..06df580 100644 --- a/Airbus/Airbus/DrawningAirbus.cs +++ b/Airbus/Airbus/DrawningAirbus.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Airbus { //класс, отвечающий за прорисовку и перемещение объекта - internal class DrawningAirbus + public class DrawningAirbus { public EntityAirbus Airbus { get; protected set; } //класс-сущность diff --git a/Airbus/Airbus/EntityAirbus.cs b/Airbus/Airbus/EntityAirbus.cs index e09d934..3b63b0d 100644 --- a/Airbus/Airbus/EntityAirbus.cs +++ b/Airbus/Airbus/EntityAirbus.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Airbus { //класс-сущность аэробус - internal class EntityAirbus + public class EntityAirbus { public int Speed { get; private set; } //скорость diff --git a/Airbus/Airbus/FormAirbus.Designer.cs b/Airbus/Airbus/FormAirbus.Designer.cs index 8f24a42..898118b 100644 --- a/Airbus/Airbus/FormAirbus.Designer.cs +++ b/Airbus/Airbus/FormAirbus.Designer.cs @@ -40,6 +40,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectPlane = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -155,11 +156,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // + // buttonSelectPlane + // + this.buttonSelectPlane.Location = new System.Drawing.Point(504, 392); + this.buttonSelectPlane.Name = "buttonSelectPlane"; + this.buttonSelectPlane.Size = new System.Drawing.Size(94, 29); + this.buttonSelectPlane.TabIndex = 8; + this.buttonSelectPlane.Text = "Выбрать"; + this.buttonSelectPlane.UseVisualStyleBackColor = true; + this.buttonSelectPlane.Click += new System.EventHandler(this.buttonSelectPlane_Click); + // // Form1 // 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.buttonSelectPlane); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -191,5 +203,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonCreateModif; + private Button buttonSelectPlane; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormAirbus.cs b/Airbus/Airbus/FormAirbus.cs index 1f8e0a0..ff30d83 100644 --- a/Airbus/Airbus/FormAirbus.cs +++ b/Airbus/Airbus/FormAirbus.cs @@ -14,6 +14,9 @@ namespace Airbus { private DrawningAirbus _airbus; + //выбранный объект + public DrawningAirbus SelectedPlane { get; set; } + public Form1() { InitializeComponent(); @@ -88,5 +91,11 @@ namespace Airbus SetData(); Draw(); } + + private void buttonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _airbus; + DialogResult = DialogResult.OK; + } } } diff --git a/Airbus/Airbus/FormMap.Designer.cs b/Airbus/Airbus/FormMap.Designer.cs deleted file mode 100644 index 3d2f24b..0000000 --- a/Airbus/Airbus/FormMap.Designer.cs +++ /dev/null @@ -1,211 +0,0 @@ -namespace Airbus -{ - 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.pictureBoxAirbus = 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.toolStripStatusLabelCorpusColor = 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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxAirbus - // - this.pictureBoxAirbus.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxAirbus.Location = new System.Drawing.Point(0, 0); - this.pictureBoxAirbus.Name = "pictureBoxAirbus"; - this.pictureBoxAirbus.Size = new System.Drawing.Size(800, 424); - this.pictureBoxAirbus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxAirbus.TabIndex = 0; - this.pictureBoxAirbus.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.toolStripStatusLabelCorpusColor}); - 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(76, 20); - this.toolStripStatusLabelSpeed.Text = "Скорость:"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20); - this.toolStripStatusLabelWeight.Text = "Вес:"; - // - // toolStripStatusLabelCorpusColor - // - this.toolStripStatusLabelCorpusColor.Name = "toolStripStatusLabelCorpusColor"; - this.toolStripStatusLabelCorpusColor.Size = new System.Drawing.Size(45, 20); - this.toolStripStatusLabelCorpusColor.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, 392); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(95, 30); - 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::Airbus.Properties.Resources.Up; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(692, 325); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(45, 45); - 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::Airbus.Properties.Resources.Left; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(641, 376); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(45, 45); - 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::Airbus.Properties.Resources.Down; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(692, 376); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(45, 45); - 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::Airbus.Properties.Resources.Right; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(743, 376); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(45, 45); - this.buttonRight.TabIndex = 6; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // 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(112, 392); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(120, 30); - this.buttonCreateModif.TabIndex = 7; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_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(151, 28); - this.comboBoxSelectorMap.TabIndex = 8; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_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.comboBoxSelectorMap); - 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.pictureBoxAirbus); - this.Controls.Add(this.statusStrip1); - this.Name = "FormMap"; - this.Text = "Карта"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxAirbus; - private StatusStrip statusStrip1; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelCorpusColor; - private Button buttonCreate; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private Button buttonCreateModif; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/Airbus/Airbus/FormMap.cs b/Airbus/Airbus/FormMap.cs deleted file mode 100644 index 23fadff..0000000 --- a/Airbus/Airbus/FormMap.cs +++ /dev/null @@ -1,96 +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 Airbus -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - //заполнение информации по объекту - private void SetData(DrawningAirbus airbus) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {airbus.Airbus?.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {airbus.Airbus?.Weight}"; - toolStripStatusLabelCorpusColor.Text = $"Цвет: {airbus.Airbus?.CorpusColor.Name}"; - - pictureBoxAirbus.Image = _abstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height, - new DrawningObjectPlane(airbus)); - - } - - //обработка нажатия кнопки "Создать" - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(airbus); - } - - 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; - } - - pictureBoxAirbus.Image = _abstractMap?.MoveObject(dir); - } - - //обработка нажития кнопки "Модификация" - private void ButtonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var airbus = new DrawningSuperAirbus(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(airbus); - } - - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Буря в пустыне": - _abstractMap = new DesertStormMap(); - break; - case "Звёздные войны": - _abstractMap = new StarWarsMap(); - break; - } - } - } -} - diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs new file mode 100644 index 0000000..d92608e --- /dev/null +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -0,0 +1,205 @@ +namespace Airbus +{ + partial class FormMapWithSetPlanes + { + /// + /// 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.groupBoxTools = 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.buttonRemovePlane = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddPlane = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemovePlane); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonAddPlane); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(729, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(250, 549); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(158, 484); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(45, 45); + this.buttonRight.TabIndex = 9; + this.buttonRight.UseVisualStyleBackColor = true; + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(107, 484); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(45, 45); + this.buttonDown.TabIndex = 8; + this.buttonDown.UseVisualStyleBackColor = true; + // + // buttonLeft + // + this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(56, 484); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(45, 45); + this.buttonLeft.TabIndex = 7; + this.buttonLeft.UseVisualStyleBackColor = true; + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(107, 433); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(45, 45); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(20, 360); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(218, 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(20, 287); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(218, 29); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click); + // + // buttonRemovePlane + // + this.buttonRemovePlane.Location = new System.Drawing.Point(20, 211); + this.buttonRemovePlane.Name = "buttonRemovePlane"; + this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29); + this.buttonRemovePlane.TabIndex = 3; + this.buttonRemovePlane.Text = "Удалить самолёт"; + this.buttonRemovePlane.UseVisualStyleBackColor = true; + this.buttonRemovePlane.Click += new System.EventHandler(this.ButtonRemovePlane_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 178); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddPlane + // + this.buttonAddPlane.Location = new System.Drawing.Point(20, 120); + this.buttonAddPlane.Name = "buttonAddPlane"; + this.buttonAddPlane.Size = new System.Drawing.Size(218, 29); + this.buttonAddPlane.TabIndex = 1; + this.buttonAddPlane.Text = "Добавить самолёт"; + this.buttonAddPlane.UseVisualStyleBackColor = true; + this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(20, 37); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 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(729, 549); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetPlanes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(979, 549); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetPlanes"; + this.Text = "FormMapWithSetPlanes"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemovePlane; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddPlane; + private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs new file mode 100644 index 0000000..52ee4c8 --- /dev/null +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -0,0 +1,151 @@ +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 Airbus +{ + public partial class FormMapWithSetPlanes : Form + { + //объект от класса карты с набором объектов + private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric; + + public FormMapWithSetPlanes() + { + InitializeComponent(); + } + + //выбор карты + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + + if(map != null) + { + _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapPlanesCollectionGeneric = null; + } + } + + //добавление объекта + private void ButtonAddPlane_Click(object sender, EventArgs e) + { + if(_mapPlanesCollectionGeneric == null) + { + return; + } + + Form1 form = new(); + + if(form.ShowDialog() == DialogResult.OK) + { + DrawningObjectPlane plane = new(form.SelectedPlane); + + if(_mapPlanesCollectionGeneric + plane) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemovePlane_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(_mapPlanesCollectionGeneric - pos) + { + MessageBox.Show("Объект удалён"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + //вывод набора + private void buttonShowStorage_Click(object sender, EventArgs e) + { + if(_mapPlanesCollectionGeneric == null) + { + return; + } + + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + + //вывод карты + private void buttonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + + pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); + } + + //перемещение + private void ButtonMove_Click(object sender, EventArgs e) + { + if(_mapPlanesCollectionGeneric == null) + { + return; + } + + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + + pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/Airbus/Airbus/FormMap.resx b/Airbus/Airbus/FormMapWithSetPlanes.resx similarity index 93% rename from Airbus/Airbus/FormMap.resx rename to Airbus/Airbus/FormMapWithSetPlanes.resx index 5cb320f..f298a7b 100644 --- a/Airbus/Airbus/FormMap.resx +++ b/Airbus/Airbus/FormMapWithSetPlanes.resx @@ -57,7 +57,4 @@ 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/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index ef66b81..07b52c6 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -13,14 +13,19 @@ namespace Airbus { //ширина окна отрисовки private readonly int _pictureWidth; + //высота окна отрисовки private readonly int _pictureHeight; + //размер занимаемого объектом места (ширина) private readonly int _placeSizeWidth = 210; + //размер занимаемого объектом места (высота) private readonly int _placeSizeHeight = 90; + //набор объектов private readonly SetPlanesGeneric _setPlanes; + //карта private readonly U _map; diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 3c7e1fb..5166800 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -11,7 +11,7 @@ namespace Airbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetPlanes()); } } } \ No newline at end of file -- 2.25.1 From 9bba0b1a346419e5f9effc7e5533c732aae820ae Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 6 Oct 2022 14:36:55 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B0=20FormMapWithSetPlannes=20=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Airbus/FormMapWithSetPlanes.Designer.cs | 11 +- Airbus/Airbus/FormMapWithSetPlanes.cs | 11 +- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 105 ++++++++++++++++-- Airbus/Airbus/SetPlanesGeneric.cs | 71 +++++++++--- 4 files changed, 172 insertions(+), 26 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index d92608e..cd80382 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -73,6 +73,7 @@ this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.TabIndex = 9; this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonDown // @@ -83,6 +84,7 @@ this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.TabIndex = 8; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonLeft // @@ -93,6 +95,7 @@ this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.TabIndex = 7; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonUp // @@ -113,7 +116,7 @@ this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.UseVisualStyleBackColor = true; - this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click); + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // // buttonShowStorage // @@ -123,7 +126,7 @@ this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.UseVisualStyleBackColor = true; - this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click); + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); // // buttonRemovePlane // @@ -156,6 +159,10 @@ // comboBoxSelectorMap // this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Буря в пустыне", + "Звёздные войны"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(20, 37); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 28); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 52ee4c8..0977f9d 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -30,6 +30,12 @@ namespace Airbus case "Простая карта": map = new SimpleMap(); break; + case "Буря в пустыне": + map = new DesertStormMap(); + break; + case "Звёздные войны": + map = new StarWarsMap(); + break; } if(map != null) @@ -69,6 +75,7 @@ namespace Airbus } } + //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) @@ -96,7 +103,7 @@ namespace Airbus } //вывод набора - private void buttonShowStorage_Click(object sender, EventArgs e) + private void ButtonShowStorage_Click(object sender, EventArgs e) { if(_mapPlanesCollectionGeneric == null) { @@ -107,7 +114,7 @@ namespace Airbus } //вывод карты - private void buttonShowOnMap_Click(object sender, EventArgs e) + private void ButtonShowOnMap_Click(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 07b52c6..909a633 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; +using System.Runtime.Intrinsics.Arm; using System.Text; using System.Threading.Tasks; @@ -43,13 +45,30 @@ namespace Airbus //пеергрузка оператора сложения public static bool operator +(MapWithSetPlanesGeneric map, T plane) { - return map._setPlanes.Insert(plane); + if (map._setPlanes.Insert(plane) != -1) + { + return true; + } + else + { + return false; + } + //return map._setPlanes.Insert(plane); } //перегрузка оператора вычитания public static bool operator -(MapWithSetPlanesGeneric map, int position) { - return map._setPlanes.Remove(position); + if (map._setPlanes.Remove(position) != null) + { + return true; + } + else + { + return false; + } + + //return map._setPlanes.Remove(position); } //вывод всего набора объектов @@ -124,25 +143,97 @@ namespace Airbus public void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); + Pen marcupPen = new(Color.White, 5); + Pen signalFirePen = new(Color.OrangeRed, 5); + Brush concreteBrush = new SolidBrush(Color.LightGray); + Brush asphaltBrush = new SolidBrush(Color.DarkGray); + Brush marcupBrush = new SolidBrush(Color.White); - for(int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight); //заливаем область в цвет бетона + + for(int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++) { - for(int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + for(int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) {//линия разметки места - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, _placeSizeHeight * 2, i * _placeSizeWidth + 5, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + + //отрисовка разметки взлётной полосы + g.FillRectangle(marcupBrush, _placeSizeWidth * 2 + 30, 0, 185, _pictureHeight); + g.FillRectangle(asphaltBrush, _placeSizeWidth * 2 + 35, 0, 175, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 210, 0, _placeSizeWidth * 2 + 210, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 35, 0, _placeSizeWidth * 2 + 35, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 215, 0, _placeSizeWidth * 2 + 215, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 30, 0, _placeSizeWidth * 2 + 30, _pictureHeight); + + for (int i = 0; i < _pictureHeight / _placeSizeHeight; ++i) + { + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 125, 20 + i * _placeSizeHeight, _placeSizeWidth * 2 + 125, (i + 1) * _placeSizeHeight - 20); + } + + for(int i = 0; i < _pictureHeight / 20; i++) + { + g.DrawLine(signalFirePen, _placeSizeWidth * 2 + 15, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 2 + 15, (i + 1) * _placeSizeHeight / 2 - 20); + g.DrawLine(signalFirePen, _placeSizeWidth * 3 + 20, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 + 20, (i + 1) * _placeSizeHeight / 2 - 20); + } + + //отрисовка сочков + Brush pinkBrush = new SolidBrush(Color.LightPink); + for(int i = 1; i < 6; i++) + { + Point[] point = new Point[] + { + new Point((i * 70 - 10) + 45, 30), + new Point(i * 70 - 10, 50), + new Point( i * 70 - 10 , 10) + }; + g.FillPolygon(pinkBrush, point); + + g.DrawLine(pen, i * 70 - 10, 10, i * 70 - 10, 80); + g.DrawLine(pen, i * 70 - 10, 10, (i * 70 - 10) + 45, 30); + g.DrawLine(pen, i * 70 - 10, 50, (i * 70 - 10) + 45, 30); + } } //метод прорисовки объеков public void DrawPlanes(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int currentWidth = 0; + int currentHeight = 0; + for(int i = 0; i < _setPlanes.Count; i++) { - //TODO установка позиции + int bias = 0; //величина смещения + + if (currentWidth > 0 && currentHeight > 0) + { + bias = width; + } + + _setPlanes.Get(i)?.SetObject(_pictureWidth - currentWidth, _pictureHeight - height * currentHeight, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawningObject(g); + + if (currentWidth < width - 1) + { + currentWidth++; + } + else + { + currentWidth = 0; + currentHeight++; + } + + if (currentHeight > height) + { + return; + } } } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 2f20084..59935f1 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -22,38 +22,79 @@ namespace Airbus } //добавление объекта в набор - public bool Insert(T plane) + public int Insert(T plane) { - //TODO вставка в начало набора - return true; + return Insert(plane, 0); } //добавление объекта в набор на конкретную позицию - public bool Insert(T plane, int position) + public int Insert(T plane, int position) { - //TODO проверка позиции - //TODO проверка, что элемент массива на этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех элементов, находящихся справа от позиции до первого пустого элемента - //TODO втсавка по позиции + // проверка позиции + if (position >= _places.Length || position < 0) + { + return -1; + } + //проверка, что элемент массива по этой позиции пустой, если нет, то + if (_places[position] == null) + { + _places[position] = plane; + return position; + } + + //проверка, что после вставляемого элемента в массиве есть пустой элемент + int findEmptyPos = -1; + + for (int i = position + 1; i < Count; i++) + { + if (_places[i] == null) + { + findEmptyPos = i; + break; + } + } + + if (findEmptyPos < 0) + { + return -1; + } + + //сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + for (int i = findEmptyPos; i > position; i--) + { + _places[i] = _places[i - 1]; + } + + // вставка по позиции _places[position] = plane; - return true; + + return position; } //удаление объекта из набора с конкретной позиции - public bool Remove(int position) + public T Remove(int position) { - //TODO проверка позиции - //TODO удаление объекта из массива, присвоив элементу массива значение null + // проверка позиции + if (position >= _places.Length || position < 0) + { + return null; + } - return true; + // удаление объекта из массива, присовив элементу массива значение null + T temp = _places[position]; + _places[position] = null; + + return temp; } //получение объекта из набора по позиции public T Get(int position) { - //TODO проверка позиции + if (position >= _places.Length || position < 0) + { + return null; + } return _places[position]; } -- 2.25.1 From 31e27532f24804934ff8114b4186686554497c92 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 00:41:27 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 4 +- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 59 ++++++++++-------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 0977f9d..826e5a6 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -63,7 +63,7 @@ namespace Airbus { DrawningObjectPlane plane = new(form.SelectedPlane); - if(_mapPlanesCollectionGeneric + plane) + if(_mapPlanesCollectionGeneric + plane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -91,7 +91,7 @@ namespace Airbus int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if(_mapPlanesCollectionGeneric - pos) + if(_mapPlanesCollectionGeneric - pos != null) { MessageBox.Show("Объект удалён"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 909a633..b1e12fe 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -43,32 +43,33 @@ namespace Airbus } //пеергрузка оператора сложения - public static bool operator +(MapWithSetPlanesGeneric map, T plane) - { - if (map._setPlanes.Insert(plane) != -1) + public static int operator +(MapWithSetPlanesGeneric map, T plane) + { + /*if (map._setPlanes.Insert(plane) != -1) { return true; } else { return false; - } - //return map._setPlanes.Insert(plane); + }*/ + + return map._setPlanes.Insert(plane); } //перегрузка оператора вычитания - public static bool operator -(MapWithSetPlanesGeneric map, int position) + public static T operator -(MapWithSetPlanesGeneric map, int position) { - if (map._setPlanes.Remove(position) != null) + /*if (map._setPlanes.Remove(position) != null) { return true; } else { return false; - } + }*/ - //return map._setPlanes.Remove(position); + return map._setPlanes.Remove(position); } //вывод всего набора объектов @@ -121,11 +122,11 @@ namespace Airbus { for (; j > i; j--) { - var car = _setPlanes.Get(j); + var plane = _setPlanes.Get(j); - if (car != null) + if (plane != null) { - _setPlanes.Insert(car, i); + _setPlanes.Insert(plane, i); _setPlanes.Remove(j); break; } @@ -202,37 +203,25 @@ namespace Airbus //метод прорисовки объеков public void DrawPlanes(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; + int position = 0; + int currentWidth = 1; + int currentHeight = 5; - int currentWidth = 0; - int currentHeight = 0; - - for(int i = 0; i < _setPlanes.Count; i++) + for (int i = 0; i < _setPlanes.Count; i++) { - int bias = 0; //величина смещения - - if (currentWidth > 0 && currentHeight > 0) - { - bias = width; - } - - _setPlanes.Get(i)?.SetObject(_pictureWidth - currentWidth, _pictureHeight - height * currentHeight, _pictureWidth, _pictureHeight); + _setPlanes.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawningObject(g); - if (currentWidth < width - 1) + if(position % 2 == 0) { - currentWidth++; + position++; + currentWidth--; } else { - currentWidth = 0; - currentHeight++; - } - - if (currentHeight > height) - { - return; + position = 0; + currentWidth = 1; + currentHeight--; } } } -- 2.25.1 From 1e6608220022c275f2b3fbe8dc5a4e6740f7e23e Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 09:50:00 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/DrawningAirbus.cs | 15 ++++++------ Airbus/Airbus/FormAirbus.cs | 31 ++++++++++++++++++++---- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 18 -------------- Airbus/Airbus/SetPlanesGeneric.cs | 4 +++ 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/Airbus/Airbus/DrawningAirbus.cs b/Airbus/Airbus/DrawningAirbus.cs index 06df580..aa08d78 100644 --- a/Airbus/Airbus/DrawningAirbus.cs +++ b/Airbus/Airbus/DrawningAirbus.cs @@ -102,16 +102,17 @@ namespace Airbus } Pen pen = new(Color.Black); - Brush darkBrush = new SolidBrush(Color.DarkKhaki); + Brush selectedBrush = new SolidBrush(Airbus.CorpusColor); Brush darcBlue = new SolidBrush(Color.DarkSlateBlue); + Brush darkBrush = new SolidBrush(Color.Black); //корпус - g.FillRectangle(darkBrush, _startPosX, _startPosY + 10, 40, 10); + g.FillRectangle(selectedBrush, _startPosX, _startPosY + 10, 40, 10); g.DrawRectangle(pen, _startPosX, _startPosY + 10, 40, 10); //крыло - g.FillRectangle(darkBrush, _startPosX + 10, _startPosY + 13, 20, 2); - g.FillRectangle(darkBrush, _startPosX + 12, _startPosY + 15, 16, 2); + g.FillRectangle(selectedBrush, _startPosX + 10, _startPosY + 13, 20, 2); + g.FillRectangle(selectedBrush, _startPosX + 12, _startPosY + 15, 16, 2); g.DrawRectangle(pen, _startPosX + 10, _startPosY + 13, 20, 2); g.DrawRectangle(pen, _startPosX + 12, _startPosY + 15, 16, 2); @@ -124,12 +125,12 @@ namespace Airbus new Point((int)_startPosX, (int)_startPosY + 10) }; - g.FillPolygon(darkBrush, point_tailWing); + g.FillPolygon(selectedBrush, point_tailWing); g.DrawLine(pen, _startPosX, _startPosY + 10, _startPosX, _startPosY); g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 10, _startPosY + 10); //заднее поперечное крыло - g.FillEllipse(darkBrush, _startPosX - 3, _startPosY + 7, 10, 5); + g.FillEllipse(selectedBrush, _startPosX - 3, _startPosY + 7, 10, 5); g.DrawEllipse(pen, _startPosX - 3, _startPosY + 7, 10, 5); //нос самолёта @@ -152,7 +153,7 @@ namespace Airbus }; g.FillPolygon(darcBlue, point_upperBow); - g.FillPolygon(darkBrush, point_lowerBow); + g.FillPolygon(selectedBrush, point_lowerBow); g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 16); g.DrawLine(pen, _startPosX + 40, _startPosY + 10, _startPosX + 47, _startPosY + 15); g.DrawLine(pen, _startPosX + 40, _startPosY + 20, _startPosX + 50, _startPosY + 15); diff --git a/Airbus/Airbus/FormAirbus.cs b/Airbus/Airbus/FormAirbus.cs index ff30d83..8dde536 100644 --- a/Airbus/Airbus/FormAirbus.cs +++ b/Airbus/Airbus/FormAirbus.cs @@ -45,8 +45,15 @@ namespace Airbus private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + _airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color); SetData(); Draw(); } @@ -84,9 +91,23 @@ namespace Airbus private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _airbus = new DrawningSuperAirbus(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)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + + if(dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogAdd = new(); + + if(dialogAdd.ShowDialog() == DialogResult.OK) + { + addColor = dialogAdd.Color; + } + + _airbus = new DrawningSuperAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, addColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index b1e12fe..9b3ea1f 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -45,30 +45,12 @@ namespace Airbus //пеергрузка оператора сложения public static int operator +(MapWithSetPlanesGeneric map, T plane) { - /*if (map._setPlanes.Insert(plane) != -1) - { - return true; - } - else - { - return false; - }*/ - return map._setPlanes.Insert(plane); } //перегрузка оператора вычитания public static T operator -(MapWithSetPlanesGeneric map, int position) { - /*if (map._setPlanes.Remove(position) != null) - { - return true; - } - else - { - return false; - }*/ - return map._setPlanes.Remove(position); } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 59935f1..9c9a974 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -92,6 +92,10 @@ namespace Airbus public T Get(int position) { if (position >= _places.Length || position < 0) + { + return null; + } + else if (_places[position] == null) { return null; } -- 2.25.1