Этап 3. Форма и замена bool.
This commit is contained in:
parent
bed8d7d922
commit
a678395c8b
@ -69,7 +69,7 @@ namespace Battleship
|
|||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
DrawningObjectBattleship battleship = new(form.SelectedBattleship);
|
DrawningObjectBattleship battleship = new(form.SelectedBattleship);
|
||||||
if (_mapBattleshipCollectionGeneric + battleship)
|
if (_mapBattleshipCollectionGeneric + battleship != null )
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
|
||||||
@ -96,7 +96,7 @@ namespace Battleship
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if (_mapBattleshipCollectionGeneric - pos)
|
if (_mapBattleshipCollectionGeneric - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapBattleshipCollectionGeneric.ShowSet();
|
||||||
|
@ -31,13 +31,11 @@ namespace Battleship
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_map = map;
|
_map = map;
|
||||||
}
|
}
|
||||||
|
public static int operator +(MapWithSetBattleshipGeneric<T, U> map, T battleship)
|
||||||
public static bool operator +(MapWithSetBattleshipGeneric<T, U> map, T warship)
|
|
||||||
{
|
{
|
||||||
return map._setBattleship.Insert(warship);
|
return map._setBattleship.Insert(battleship);
|
||||||
}
|
}
|
||||||
|
public static T operator -(MapWithSetBattleshipGeneric<T, U> map, int position)
|
||||||
public static bool operator -(MapWithSetBattleshipGeneric<T, U> map, int position)
|
|
||||||
{
|
{
|
||||||
return map._setBattleship.Remove(position);
|
return map._setBattleship.Remove(position);
|
||||||
}
|
}
|
||||||
|
@ -22,53 +22,49 @@ namespace Battleship
|
|||||||
_places = new T[count];
|
_places = new T[count];
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T battleship)
|
public int Insert(T battleship)
|
||||||
{
|
{
|
||||||
return Insert(battleship, 0);
|
return Insert(battleship, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T battleship, int position)
|
public int Insert(T battleship, int position)
|
||||||
{
|
{
|
||||||
int EmptyEl = -1;
|
if (position >= _places.Length)
|
||||||
|
|
||||||
if (position >= Count || position < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (_places[position] == null)
|
|
||||||
{
|
{
|
||||||
_places[position] = battleship;
|
return -1;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
else 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)
|
if (_places[i] == null)
|
||||||
{
|
{
|
||||||
EmptyEl = i;
|
indexNull = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (EmptyEl == -1)
|
if (indexNull == -1) return -1;
|
||||||
return false;
|
for (int i = indexNull; i > position; i--)
|
||||||
|
{
|
||||||
for (int i = EmptyEl; i > position; i--)
|
T tmp = _places[i];
|
||||||
_places[i] = _places[i - 1];
|
_places[i] = _places[i - 1];
|
||||||
|
_places[i - 1] = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_places[position] = battleship;
|
_places[position] = battleship;
|
||||||
return true;
|
return position;
|
||||||
}
|
}
|
||||||
|
public T Remove(int position)
|
||||||
public bool Remove(int position)
|
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0 || _places[position] == null)
|
if (position >= _places.Length)
|
||||||
return false;
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T removedObject = _places[position];
|
||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return true;
|
return removedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0)
|
if (position >= Count || position < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user