From 26b48afac4c0365d851ce1ad9c032cd8d9a4f6f8 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Tue, 4 Oct 2022 15:53:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=203=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetWarships.Designer.cs | 4 ++++ Warship/Warship/FormMapWithSetWarships.cs | 4 ++-- Warship/Warship/MapWithSetWarshipsGeneric.cs | 13 +++++++------ Warship/Warship/SetWarshipsGeneric.cs | 19 ++++++++++--------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Warship/Warship/FormMapWithSetWarships.Designer.cs b/Warship/Warship/FormMapWithSetWarships.Designer.cs index 4c2c1c1..760c7de 100644 --- a/Warship/Warship/FormMapWithSetWarships.Designer.cs +++ b/Warship/Warship/FormMapWithSetWarships.Designer.cs @@ -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 // diff --git a/Warship/Warship/FormMapWithSetWarships.cs b/Warship/Warship/FormMapWithSetWarships.cs index 477b2aa..b71de7e 100644 --- a/Warship/Warship/FormMapWithSetWarships.cs +++ b/Warship/Warship/FormMapWithSetWarships.cs @@ -53,7 +53,7 @@ namespace Warship if (form.ShowDialog() == DialogResult.OK) { DrawingObjectWarship warship = new(form.SelectedWarship); - if (_mapWarshipsCollectionGeneric + warship) + if (_mapWarshipsCollectionGeneric + warship>=0) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet(); @@ -76,7 +76,7 @@ namespace Warship return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapWarshipsCollectionGeneric - pos) + if (_mapWarshipsCollectionGeneric - pos !=null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet(); diff --git a/Warship/Warship/MapWithSetWarshipsGeneric.cs b/Warship/Warship/MapWithSetWarshipsGeneric.cs index 64fa238..deec30f 100644 --- a/Warship/Warship/MapWithSetWarshipsGeneric.cs +++ b/Warship/Warship/MapWithSetWarshipsGeneric.cs @@ -27,12 +27,12 @@ namespace Warship _map = map; } - public static bool operator +(MapWithSetWarshipsGeneric map, T warship) + public static int operator +(MapWithSetWarshipsGeneric map, T warship) { return map._setWarship.Insert(warship); } - public static bool operator -(MapWithSetWarshipsGeneric map, int position) + public static T operator -(MapWithSetWarshipsGeneric map, int position) { return map._setWarship.Remove(position); } @@ -101,9 +101,10 @@ namespace Warship { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { - gr.DrawLine(pen, i * _placeSizeWidth+10, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2); - gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9)+10, j * _placeSizeHeight + 2+20); - gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20); + gr.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2); + gr.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + _placeSizeHeight/2+2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight/2+2); + gr.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2); + gr.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight); } } } @@ -117,7 +118,7 @@ namespace Warship { if (_setWarship.Get(i) != null) { - _setWarship.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + _setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight); _setWarship.Get(i)?.DrawingObject(gr); } } diff --git a/Warship/Warship/SetWarshipsGeneric.cs b/Warship/Warship/SetWarshipsGeneric.cs index c5c25b4..ac9c126 100644 --- a/Warship/Warship/SetWarshipsGeneric.cs +++ b/Warship/Warship/SetWarshipsGeneric.cs @@ -18,22 +18,22 @@ namespace Warship _places = new T[count]; } - public bool Insert(T warship) + public int Insert(T warship) { return Insert(warship,0); } - public bool Insert(T warship, int position) + public int Insert(T warship, int position) { int EmptyEl=-1; if (position>=Count || position < 0) - return false; + return -1; if (_places[position] == null) { _places[position] = warship; - return true; + return 1; } else if (_places[position] != null) @@ -46,23 +46,24 @@ namespace Warship } if (EmptyEl == -1) - return false; + return -1; for (int i = EmptyEl; i > position; i--) _places[i] = _places[i - 1]; } _places[position] = warship; - return true; + return 1; } - public bool Remove(int position) + public T Remove(int position) { if (position >= Count || position < 0 || _places[position]==null) - return false; + return null; + T deleted =_places[position]; _places[position] = null; - return true; + return deleted; } public T Get(int position)