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

View File

@ -70,7 +70,6 @@ namespace ContainerShip
private void ButtonCreateModif_Click(object sender, EventArgs e) private void ButtonCreateModif_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), _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)), 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; _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); return map._setShip.Insert(car);
} }
public static bool operator -(MapWithSetShipGeneric<T, U> map, int public static T operator -(MapWithSetShipGeneric<T, U> map, int
position) position)
{ {
return map._setShip.Remove(position); return map._setShip.Remove(position);

View File

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