diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index b2708e0..4c32193 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -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(); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index 2ad9043..c0d112a 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -30,17 +30,12 @@ namespace ProjectTractor.Generics /// /// Добавляемый трактор /// - 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); } /// /// Добавление объекта в набор на конкретную позицию @@ -48,23 +43,23 @@ namespace ProjectTractor.Generics /// Добавляемый трактор /// Позиция /// - 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; } /// /// Удаление объекта из набора с конкретной позиции diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index da5fb77..8a333eb 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -28,7 +28,7 @@ namespace ProjectTractor.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeWidth = 200; /// /// Размер занимаемого объектом места (высота) /// @@ -56,14 +56,12 @@ namespace ProjectTractor.Generics /// /// /// - public static bool operator +(TractorsGenericCollection collect, T? - obj) + public static int operator +(TractorsGenericCollection collect, T? obj) { if (obj == null) - { - return false; - } - return collect?._collection.Insert(obj) ?? false; + return -1; + + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -85,6 +83,7 @@ namespace ProjectTractor.Generics /// /// /// + /// 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); } }