Zhimolostnova A.V. Lab work 3 #3

Merged
eegov merged 5 commits from LabRab_3 into LabRab_2 2022-10-07 09:44:34 +04:00
4 changed files with 23 additions and 17 deletions
Showing only changes of commit 26b48afac4 - Show all commits

View File

@ -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
//

View File

@ -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();

View File

@ -27,12 +27,12 @@ namespace Warship
_map = map;
}
public static bool operator +(MapWithSetWarshipsGeneric<T,U> map, T warship)
public static int operator +(MapWithSetWarshipsGeneric<T,U> map, T warship)
{
return map._setWarship.Insert(warship);
}
public static bool operator -(MapWithSetWarshipsGeneric<T,U> map, int position)
public static T operator -(MapWithSetWarshipsGeneric<T,U> 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);
}
}

View File

@ -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;
Review

Почему 1?

Почему 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)