PIbd-23 Firsov Kirill LabWork 03 #8

Closed
Firsov_Kirill wants to merge 6 commits from Laba3 into Laba2
3 changed files with 17 additions and 23 deletions
Showing only changes of commit b3f332db43 - Show all commits

View File

@ -36,7 +36,7 @@ namespace ProjectTractor
FormTractor form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_tractors + form.SelectedTractor)
if (_tractors + form.SelectedTractor != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _tractors.ShowTractors();

View File

@ -30,17 +30,12 @@ namespace ProjectTractor.Generics
/// </summary>
/// <param name="tractor">Добавляемый трактор</param>
/// <returns></returns>
public bool Insert(T tractor)
public int Insert(T tractor)
{
if (_places[0] == null)
{
_places[0] = tractor;
}
else
{
return Insert(tractor, 0);
}
return true;
if (_places[Count - 1] != null)
return -1;
return Insert(tractor, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -48,23 +43,23 @@ namespace ProjectTractor.Generics
/// <param name="tractor">Добавляемый трактор</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T tractor, int position)
public int Insert(T tractor, int position)
{
if (!(position >= 0 && position < Count))
return false;
return -1;
if (_places[position] != null)
{
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return false;
return -1;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = tractor;
return true;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции

View File

@ -28,7 +28,7 @@ namespace ProjectTractor.Generics
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeWidth = 200;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
@ -56,14 +56,12 @@ namespace ProjectTractor.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(TractorsGenericCollection<T, U> collect, T?
obj)
public static int operator +(TractorsGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
}
return collect?._collection.Insert(obj) ?? false;
return -1;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -85,6 +83,7 @@ namespace ProjectTractor.Generics
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
///
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
@ -133,7 +132,7 @@ namespace ProjectTractor.Generics
if (tractor != null)
{
int countRows = _pictureWidth / _placeSizeWidth;
tractor.SetPosition(_pictureWidth - _placeSizeWidth*2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 150);
tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % countRows * _placeSizeWidth), _pictureHeight - i / countRows * _placeSizeHeight - 150);
tractor.DrawTransport(g);
}
}