Этап 3. Форма и замена bool.

This commit is contained in:
Nap 2022-10-30 15:40:58 +04:00
parent bed8d7d922
commit a678395c8b
3 changed files with 29 additions and 35 deletions

View File

@ -69,7 +69,7 @@ namespace Battleship
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectBattleship battleship = new(form.SelectedBattleship);
if (_mapBattleshipCollectionGeneric + battleship)
if (_mapBattleshipCollectionGeneric + battleship != null )
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
@ -96,7 +96,7 @@ namespace Battleship
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapBattleshipCollectionGeneric - pos)
if (_mapBattleshipCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();

View File

@ -31,13 +31,11 @@ namespace Battleship
_pictureHeight = picHeight;
_map = map;
}
public static bool operator +(MapWithSetBattleshipGeneric<T, U> map, T warship)
public static int operator +(MapWithSetBattleshipGeneric<T, U> map, T battleship)
{
return map._setBattleship.Insert(warship);
return map._setBattleship.Insert(battleship);
}
public static bool operator -(MapWithSetBattleshipGeneric<T, U> map, int position)
public static T operator -(MapWithSetBattleshipGeneric<T, U> map, int position)
{
return map._setBattleship.Remove(position);
}

View File

@ -22,53 +22,49 @@ namespace Battleship
_places = new T[count];
}
public bool Insert(T battleship)
public int Insert(T battleship)
{
return Insert(battleship, 0);
}
public bool Insert(T battleship, int position)
public int Insert(T battleship, int position)
{
int EmptyEl = -1;
if (position >= Count || position < 0)
return false;
if (_places[position] == null)
if (position >= _places.Length)
{
_places[position] = battleship;
return true;
return -1;
}
else if (_places[position] != null)
if (_places[position] != null)
{
for (int i = position + 1; i < Count; i++)
int indexNull = -1;
for (int i = position; i < _places.Length; i++)
{
if (_places[i] == null)
{
EmptyEl = i;
indexNull = i;
break;
}
if (EmptyEl == -1)
return false;
for (int i = EmptyEl; i > position; i--)
}
if (indexNull == -1) return -1;
for (int i = indexNull; i > position; i--)
{
T tmp = _places[i];
_places[i] = _places[i - 1];
_places[i - 1] = tmp;
}
}
_places[position] = battleship;
return true;
return position;
}
public bool Remove(int position)
public T Remove(int position)
{
if (position >= Count || position < 0 || _places[position] == null)
return false;
if (position >= _places.Length)
{
return null;
}
T removedObject = _places[position];
_places[position] = null;
return true;
return removedObject;
}
public T Get(int position)
{
if (position >= Count || position < 0)