законченная 3ья лабораторная
This commit is contained in:
parent
15399b84b1
commit
c4eacd38e5
@ -64,9 +64,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="bus">Добавляемый объект </param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawingBus bus)
|
||||
public static int? operator +(AbstractCompany company, DrawingBus bus)
|
||||
{
|
||||
return company._collection?.Insert(bus) ?? false;
|
||||
return company._collection?.Insert(bus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -75,9 +75,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
public static DrawingBus? operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
public DrawingBus? GetRandomObject()
|
||||
|
@ -21,9 +21,9 @@ public class BusStation : AbstractCompany
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
|
||||
int gap = 15;
|
||||
int y = 10;
|
||||
int y = gap;
|
||||
int size_of_array = 2;
|
||||
|
||||
|
||||
while (y + _placeSizeHeight < _pictureHeight - gap)
|
||||
{
|
||||
int x = _pictureWidth - gap;
|
||||
@ -35,13 +35,13 @@ public class BusStation : AbstractCompany
|
||||
g.DrawLine(pen, x, y + _placeSizeHeight, x - _placeSizeWidth, y + _placeSizeHeight);
|
||||
|
||||
Array.Resize(ref _arrayOfCoordinates, size_of_array);
|
||||
_arrayOfCoordinates[size_of_array - 2] = x;
|
||||
_arrayOfCoordinates[size_of_array - 1] = y;
|
||||
_arrayOfCoordinates[size_of_array - 2] = x - 120;
|
||||
_arrayOfCoordinates[size_of_array - 1] = y + gap;
|
||||
|
||||
x -= (_placeSizeWidth + 70);
|
||||
x -= (_placeSizeWidth + (_placeSizeWidth/2));
|
||||
size_of_array += 2;
|
||||
}
|
||||
y += _placeSizeHeight;
|
||||
size_of_array += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj);
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление элемента на конкретную позицию
|
||||
@ -36,14 +36,14 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло успешно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
|
@ -39,7 +39,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)//возможно придётся доделать
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
@ -49,50 +49,53 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (Insert(obj, 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Insert(obj, 0);
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
//проверка позиции
|
||||
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
int copy_of_position = position - 1;
|
||||
|
||||
while (position < Count)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
else
|
||||
while (copy_of_position > 0)
|
||||
{
|
||||
if (Insert(obj, position + 1))
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Insert(obj, position - 1))
|
||||
{
|
||||
return true;
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
position--;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
T? removed_object = _collection[position];
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
return removed_object;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public partial class FormBusCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawingBus)
|
||||
if ((_company + drawingBus) != -1)
|
||||
{
|
||||
MessageBox.Show("Object added");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -98,7 +98,7 @@ public partial class FormBusCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos)
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object removed");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user