Изменение типов возвращаемых значений операций добавления/удаления и отрисовка хранилища

This commit is contained in:
ityurner02@mail.ru 2022-10-03 19:20:02 +04:00
parent a761e843c9
commit 2e53a104b7
3 changed files with 33 additions and 19 deletions

View File

@ -67,7 +67,7 @@ namespace AntiAircraftGun
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun); DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun);
if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun) if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun >= 0)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet(); pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
@ -94,7 +94,7 @@ namespace AntiAircraftGun
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapAntiAircraftGunsCollectionGeneric - pos) if (_mapAntiAircraftGunsCollectionGeneric - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet(); pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();

View File

@ -60,7 +60,7 @@ namespace AntiAircraftGun
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="antiAircraftGuns"></param> /// <param name="antiAircraftGuns"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator +(MapWithSetAntiAircraftGunsGeneric<T, U> map, T antiAircraftGuns) public static int operator +(MapWithSetAntiAircraftGunsGeneric<T, U> map, T antiAircraftGuns)
{ {
return map._setAntiAircraftGuns.Insert(antiAircraftGuns); return map._setAntiAircraftGuns.Insert(antiAircraftGuns);
} }
@ -70,7 +70,7 @@ namespace AntiAircraftGun
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator -(MapWithSetAntiAircraftGunsGeneric<T, U> map, int position) public static T operator -(MapWithSetAntiAircraftGunsGeneric<T, U> map, int position)
{ {
return map._setAntiAircraftGuns.Remove(position); return map._setAntiAircraftGuns.Remove(position);
} }
@ -149,7 +149,6 @@ namespace AntiAircraftGun
/// <param name="g"></param> /// <param name="g"></param>
private void DrawBackground(Graphics g) private void DrawBackground(Graphics g)
{ {
Pen pen = new(Color.Black, 3);
Brush brushGreen = new SolidBrush(Color.Green); Brush brushGreen = new SolidBrush(Color.Green);
Brush brushLightGray = new SolidBrush(Color.LightGray); Brush brushLightGray = new SolidBrush(Color.LightGray);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
@ -167,10 +166,18 @@ namespace AntiAircraftGun
/// <param name="g"></param> /// <param name="g"></param>
private void DrawAntiAircraftGuns(Graphics g) private void DrawAntiAircraftGuns(Graphics g)
{ {
int xPositionInStorage = _placeSizeWidth / 10;
int yPositionInStorage = _placeSizeHeight / 10;
for (int i = 0; i < _setAntiAircraftGuns.Count; i++) for (int i = 0; i < _setAntiAircraftGuns.Count; i++)
{ {
// TODO установка позиции _setAntiAircraftGuns.Get(i)?.SetObject(xPositionInStorage, yPositionInStorage, _pictureWidth, _pictureHeight);
_setAntiAircraftGuns.Get(i)?.DrawingObjectAntiAircraftGun(g); _setAntiAircraftGuns.Get(i)?.DrawingObjectAntiAircraftGun(g);
xPositionInStorage += _placeSizeWidth;
if (xPositionInStorage > _pictureWidth - _placeSizeWidth)
{
xPositionInStorage = _placeSizeWidth / 10;
yPositionInStorage += _placeSizeHeight;
}
} }
} }
} }

View File

@ -34,9 +34,8 @@ namespace AntiAircraftGun
/// </summary> /// </summary>
/// <param name="antiAircraftGun">Добавляемый автомобиль</param> /// <param name="antiAircraftGun">Добавляемый автомобиль</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T antiAircraftGun) public int Insert(T antiAircraftGun)
{ {
// TODO вставка в начало набора
if (_places[Count - 1] == null) if (_places[Count - 1] == null)
{ {
for(int i = Count - 1; i > 0; i--) for(int i = Count - 1; i > 0; i--)
@ -44,9 +43,9 @@ namespace AntiAircraftGun
_places[i] = _places[i - 1]; _places[i] = _places[i - 1];
} }
_places[0] = antiAircraftGun; _places[0] = antiAircraftGun;
return true; return 0;
} }
return false; return -1;
} }
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
@ -54,13 +53,13 @@ namespace AntiAircraftGun
/// <param name="antiAircraftGun">Добавляемое орудие</param> /// <param name="antiAircraftGun">Добавляемое орудие</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T antiAircraftGun, int position) public int Insert(T antiAircraftGun, int position)
{ {
if (position < 0 || position >= Count) return false; if (position < 0 || position >= Count) return -1;
if (_places[position] == null) if (_places[position] == null)
{ {
_places[position] = antiAircraftGun; _places[position] = antiAircraftGun;
return true; return position;
} }
else else
{ {
@ -71,9 +70,9 @@ namespace AntiAircraftGun
_places[i] = _places[i - 1]; _places[i] = _places[i - 1];
} }
_places[position] = antiAircraftGun; _places[position] = antiAircraftGun;
return true; return position;
} }
return false; return -1;
} }
} }
/// <summary> /// <summary>
@ -81,15 +80,23 @@ namespace AntiAircraftGun
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public bool Remove(int position) public T Remove(int position)
{ {
if (position < 0 || position >= Count) return false; if (position < 0 || position >= Count) return null;
if (_places[position] != null) if (_places[position] != null)
{ {
T removed = _places[position];
_places[position] = null; _places[position] = null;
return true; if (position < Count - 1)
{
for (int k = position; k < Count - 1; k++)
{
_places[k] = _places[k + 1];
}
}
return removed;
} }
return false; return null;
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции