Проверенная 3 лаба

This commit is contained in:
d.agil 2022-11-02 09:49:17 +04:00
parent a3df0cf285
commit 5181a68461
3 changed files with 11 additions and 10 deletions

View File

@ -29,7 +29,7 @@ namespace AirBomber
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectBomber airBomber = new(form.SelectedAirBomber); DrawningObjectBomber airBomber = new(form.SelectedAirBomber);
if (_mapAirBomberCollectionGeneric + airBomber == 1) if (_mapAirBomberCollectionGeneric + airBomber > -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet();
@ -52,7 +52,7 @@ namespace AirBomber
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapAirBomberCollectionGeneric - pos == 1) if (_mapAirBomberCollectionGeneric - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet();

View File

@ -32,7 +32,7 @@ namespace AirBomber
return map._setAirBomber.Insert(airBomber); return map._setAirBomber.Insert(airBomber);
} }
public static int operator -(MapWithSetAirBomberGeneric<T, U> map, int position) public static T operator -(MapWithSetAirBomberGeneric<T, U> map, int position)
{ {
return map._setAirBomber.Remove(position); return map._setAirBomber.Remove(position);
} }

View File

@ -27,13 +27,13 @@ namespace AirBomber
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return 0; return -1;
} }
int emptyPos = -1; int emptyPos = -1;
if (_places[position] == null) if (_places[position] == null)
{ {
_places[position] = airBomber; _places[position] = airBomber;
return 1; return position;
} }
else else
{ {
@ -56,22 +56,23 @@ namespace AirBomber
if (emptyPos != -1) if (emptyPos != -1)
{ {
_places[position] = airBomber; _places[position] = airBomber;
return 1; return position;
} }
else else
{ {
return 0; return -1;
} }
} }
public int Remove(int position) public T Remove(int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return 0; return null;
} }
T elem = _places[position];
_places[position] = null; _places[position] = null;
return 1; return elem;
} }
public T Get(int position) public T Get(int position)