From 5ccb3d550f039dd24af64d8a784dc331f34048ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 3 Oct 2022 20:10:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetPlains.Designer.cs | 48 +++++++------- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 16 +++-- .../FormMapWithSetPlains.resx | 62 +----------------- .../MapWithSetPlainGeneric.cs | 64 ++++++++++++++----- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 59 ++++++++++++++--- 5 files changed, 135 insertions(+), 114 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs index f87f8bc..60cdad9 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs @@ -30,14 +30,14 @@ { this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); - this.buttonRemoveCar = new System.Windows.Forms.Button(); + this.buttonRemovePlain = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = 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.buttonAddCar = new System.Windows.Forms.Button(); + this.buttonAddPlain = new System.Windows.Forms.Button(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBoxTools.SuspendLayout(); @@ -47,14 +47,14 @@ // groupBoxTools // this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); - this.groupBoxTools.Controls.Add(this.buttonRemoveCar); + this.groupBoxTools.Controls.Add(this.buttonRemovePlain); this.groupBoxTools.Controls.Add(this.buttonShowStorage); this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonShowOnMap); - this.groupBoxTools.Controls.Add(this.buttonAddCar); + this.groupBoxTools.Controls.Add(this.buttonAddPlain); this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(1057, 0); @@ -73,15 +73,15 @@ this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.ValidatingType = typeof(int); // - // buttonRemoveCar + // buttonRemovePlain // - this.buttonRemoveCar.Location = new System.Drawing.Point(17, 195); - this.buttonRemoveCar.Name = "buttonRemoveCar"; - this.buttonRemoveCar.Size = new System.Drawing.Size(175, 35); - this.buttonRemoveCar.TabIndex = 3; - this.buttonRemoveCar.Text = "Удалить автомобиль"; - this.buttonRemoveCar.UseVisualStyleBackColor = true; - this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click); + this.buttonRemovePlain.Location = new System.Drawing.Point(17, 195); + this.buttonRemovePlain.Name = "buttonRemovePlain"; + this.buttonRemovePlain.Size = new System.Drawing.Size(175, 35); + this.buttonRemovePlain.TabIndex = 3; + this.buttonRemovePlain.Text = "Удалить самолет"; + this.buttonRemovePlain.UseVisualStyleBackColor = true; + this.buttonRemovePlain.Click += new System.EventHandler(this.ButtonRemovePlain_Click); // // buttonShowStorage // @@ -103,6 +103,7 @@ this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonRight // @@ -114,6 +115,7 @@ this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonLeft // @@ -125,6 +127,7 @@ this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonUp // @@ -136,6 +139,7 @@ this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // @@ -147,15 +151,15 @@ this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // - // buttonAddCar + // buttonAddPlain // - this.buttonAddCar.Location = new System.Drawing.Point(17, 106); - this.buttonAddCar.Name = "buttonAddCar"; - this.buttonAddCar.Size = new System.Drawing.Size(175, 35); - this.buttonAddCar.TabIndex = 1; - this.buttonAddCar.Text = "Добавить автомобиль"; - this.buttonAddCar.UseVisualStyleBackColor = true; - this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click); + this.buttonAddPlain.Location = new System.Drawing.Point(17, 106); + this.buttonAddPlain.Name = "buttonAddPlain"; + this.buttonAddPlain.Size = new System.Drawing.Size(175, 35); + this.buttonAddPlain.TabIndex = 1; + this.buttonAddPlain.Text = "Добавить самолет"; + this.buttonAddPlain.UseVisualStyleBackColor = true; + this.buttonAddPlain.Click += new System.EventHandler(this.ButtonAddPlain_Click); // // comboBoxSelectorMap // @@ -201,13 +205,13 @@ private PictureBox pictureBox; private ComboBox comboBoxSelectorMap; private Button buttonShowOnMap; - private Button buttonAddCar; + private Button buttonAddPlain; private Button buttonDown; private Button buttonRight; private Button buttonLeft; private Button buttonUp; private Button buttonShowStorage; - private Button buttonRemoveCar; + private Button buttonRemovePlain; private MaskedTextBox maskedTextBoxPosition; } } \ No newline at end of file diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index e979d8f..89e646c 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -17,6 +17,7 @@ namespace AirPlaneWithRadar { InitializeComponent(); } + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { AbstractMap map = null; @@ -42,17 +43,20 @@ namespace AirPlaneWithRadar _mapPlainsCollectionGeneric = null; } } - private void ButtonAddCar_Click(object sender, EventArgs e) + private void ButtonAddPlain_Click(object sender, EventArgs e) { + if (_mapPlainsCollectionGeneric == null) { return; } + FormPlain form = new(); if (form.ShowDialog() == DialogResult.OK) { - DrawingObjectPlane car = new(form.SelectedPlain); - if (_mapPlainsCollectionGeneric + car) + DrawingObjectPlane plain = new(form.SelectedPlain); + + if ((_mapPlainsCollectionGeneric + plain)>=0) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); @@ -63,7 +67,7 @@ namespace AirPlaneWithRadar } } } - private void ButtonRemoveCar_Click(object sender, EventArgs e) + private void ButtonRemovePlain_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { @@ -74,7 +78,7 @@ namespace AirPlaneWithRadar return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlainsCollectionGeneric - pos) + if ((_mapPlainsCollectionGeneric - (pos-1)) != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); @@ -106,7 +110,7 @@ namespace AirPlaneWithRadar { return; } - + string name = ((Button)sender)?.Name ?? string.Empty; Direction dir = Direction.None; switch (name) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.resx b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.resx index 1af7de1..f298a7b 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.resx +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.resx @@ -1,64 +1,4 @@ - - - + diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 559a16d..d636c51 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -16,7 +16,7 @@ namespace AirPlaneWithRadar private readonly int _placeSizeWidth = 180; - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 120; private readonly SetPlaneGeneric _setPlains; @@ -31,13 +31,13 @@ namespace AirPlaneWithRadar _pictureHeight = picHeight; _map = map; } - - public static bool operator +(MapWithSetPlainGeneric map, T car) + + public static int operator +(MapWithSetPlainGeneric map, T plain) { - return map._setPlains.Insert(car); + return map._setPlains.Insert(plain); } - public static bool operator -(MapWithSetPlainGeneric map, int position) + public static T operator -(MapWithSetPlainGeneric map, int position) { return map._setPlains.Remove(position); } @@ -56,10 +56,10 @@ namespace AirPlaneWithRadar Shaking(); for (int i = 0; i < _setPlains.Count; i++) { - var car = _setPlains.Get(i); - if (car != null) + var plain = _setPlains.Get(i); + if (plain != null) { - return _map.CreateMap(_pictureWidth, _pictureHeight, car); + return _map.CreateMap(_pictureWidth, _pictureHeight, plain); } } return new(_pictureWidth, _pictureHeight); @@ -83,10 +83,10 @@ namespace AirPlaneWithRadar { for (; j > i; j--) { - var car = _setPlains.Get(j); - if (car != null) + var plain = _setPlains.Get(j); + if (plain != null) { - _setPlains.Insert(car, i); + _setPlains.Insert(plain, i); _setPlains.Remove(j); break; } @@ -101,7 +101,8 @@ namespace AirPlaneWithRadar private void DrawBackground(Graphics g) { - + Brush BrushRazmetka = new SolidBrush(Color.DarkGray); + g.FillRectangle(BrushRazmetka, 0, 0, _pictureWidth, _pictureHeight); Pen pen = new(Color.White, 5); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { @@ -115,12 +116,43 @@ namespace AirPlaneWithRadar } private void DrawPlains(Graphics g) { - - for (int i = 0; i < _setPlains.Count; i++) - { + int CountWidth = _pictureWidth / _placeSizeWidth; - _setPlains.Get(i)?.DrawningObject(g); + int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth/2 - _placeSizeWidth / 4; + int y = (_pictureHeight - _placeSizeHeight)- _placeSizeHeight/2; + + for (int k = 0; k < _setPlains.Count; k++) + { + if (_setPlains.Get(k) != null) + { + if ((k+1) % CountWidth != 0 || k ==0) + { + _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains.Get(k)?.DrawningObject(g); + x -= _placeSizeWidth; + } + else + { + + _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains.Get(k)?.DrawningObject(g); + x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + y -= _placeSizeHeight ; + + } + } + if (_setPlains.Get(k) == null) + { + if ((k + 1) % CountWidth != 0 || k ==0) + x -= _placeSizeWidth; + else + { + x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + y -= _placeSizeHeight; + } + } } + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index b49139f..b030bd8 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -15,22 +15,63 @@ namespace AirPlaneWithRadar { _places = new T[count]; } - public bool Insert(T plain) + public int Insert(T plain) { - - - return true; + int i; + for (i = 0; i < Count; i++) + { + if (_places[i] == null) + { + for (int j = i; j >= 1; j--) + { + _places[j] = _places[j - 1]; + } + _places[0] = plain; + return i; + } + } + + return -1; } public bool Insert(T plain, int position) { - - return true; + if (position > Count || position < 0) + return false; + if (_places[position] == null) + { + _places[position] = plain; + return true; + } + else + { + for (int i = position; i < Count; i++) + { + if (_places[i] == null) + { + for (int j = i; j >= position + 1; j--) + { + _places[j] = _places[j - 1]; + } + _places[position] = plain; + return true; + } + } + } + return false; } - public bool Remove(int position) + public T Remove(int position) { - - return false; + T mid; + if (_places[position] != null) + { + mid = _places[position]; + _places[position] = null; + return mid; + + } + else + return null; } public T Get(int position) {