lab3 done

This commit is contained in:
Danil Markov 2022-11-04 14:41:28 +04:00
parent 56aa1980ca
commit 9cd7a29f6a
4 changed files with 14 additions and 16 deletions

View File

@ -15,7 +15,6 @@ namespace ContainerShip
private MapWithSetShipGeneric<DrawingObjectShip, AbstractMap> _mapShipCollectionGeneric;
public FormMapWithSetShip()
{
InitializeComponent();
@ -58,7 +57,7 @@ namespace ContainerShip
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectShip ship = new(form.SelectedShip);
if (_mapShipCollectionGeneric + ship)
if (_mapShipCollectionGeneric + ship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
@ -82,7 +81,7 @@ namespace ContainerShip
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapShipCollectionGeneric - pos)
if (_mapShipCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();

View File

@ -70,7 +70,6 @@ namespace ContainerShip
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),

View File

@ -33,12 +33,12 @@ namespace ContainerShip
_map = map;
}
public static bool operator +(MapWithSetShipGeneric<T, U> map, T car)
public static int operator +(MapWithSetShipGeneric<T, U> map, T car)
{
return map._setShip.Insert(car);
}
public static bool operator -(MapWithSetShipGeneric<T, U> map, int
public static T operator -(MapWithSetShipGeneric<T, U> map, int
position)
{
return map._setShip.Remove(position);

View File

@ -19,16 +19,16 @@ namespace ContainerShip
_places = new T[count];
}
public bool Insert(T ship)
public int Insert(T ship)
{
return Insert(ship, 0);
}
public bool Insert(T ship, int position)
public int Insert(T ship, int position)
{
if (position < 0 || position > _places.Length)
{
return false;
return -1;
}
int emptyCellIndex = -1;
if (_places[position] != null)
@ -52,30 +52,30 @@ namespace ContainerShip
else
{
_places[position] = ship;
return true;
return position;
}
if (emptyCellIndex == -1)
{
return false;
return -1;
}
else
{
_places[position] = ship;
return true;
return position;
}
}
public bool Remove(int position)
public T Remove(int position)
{
if (position >= Count || position < 0)
{
return false;
return null;
}
T removedObject = _places[position];
_places[position] = null;
return true;
return removedObject;
}
public T Get(int position)