A. F. Kadyrov Lab work 03 #3
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user