Переделал методы из требования №5
This commit is contained in:
parent
a22085ac83
commit
578ac2e424
@ -67,7 +67,7 @@ public abstract class AbstractCompany
|
||||
{
|
||||
if(company._collection == null)
|
||||
{
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
return company._collection.Insert(train);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ 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>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
|
@ -49,21 +49,21 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
@ -71,10 +71,10 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
|
@ -41,9 +41,9 @@ public class TrainSharingService : AbstractCompany
|
||||
{
|
||||
int counter = 0;
|
||||
int valPlaceY = _pictureHeight / _placeSizeHeight;
|
||||
for (int y = (valPlaceY - 1) * _placeSizeHeight; y >= 0; y -= _placeSizeHeight)
|
||||
for (int y = ((valPlaceY - 1) * _placeSizeHeight) + 30; y >= 0; y -= _placeSizeHeight)
|
||||
{
|
||||
for (int x = 5; x + _placeSizeWidth < _pictureWidth; x += _placeSizeWidth)
|
||||
for (int x = 10; x + _placeSizeWidth < _pictureWidth; x += _placeSizeWidth)
|
||||
{
|
||||
_collection?.Get(counter)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(counter)?.SetPosition(x, y);
|
||||
|
@ -86,7 +86,7 @@ public partial class FormTrainCollection : Form
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (_company + drawingTrain != 0)
|
||||
if (_company + drawingTrain != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
Loading…
Reference in New Issue
Block a user