From b3f332db43f397fe876d24e36ef50f75d6ffcc17 Mon Sep 17 00:00:00 2001
From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com>
Date: Fri, 10 Nov 2023 11:03:52 +0400
Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BB=20=D1=82=D1=80=D0=B5?=
=?UTF-8?q?=D1=82=D1=8C=D1=8E=20=D0=BB=D0=B0=D0=B1=D1=83,=20=D0=B4=D0=BE?=
=?UTF-8?q?=D0=BF=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=83?=
=?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormTractorCollection.cs | 2 +-
.../RPP_FirstLaba_Tractor/SetGeneric.cs | 23 ++++++++-----------
.../TractorsGenericCollection.cs | 15 ++++++------
3 files changed, 17 insertions(+), 23 deletions(-)
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);
}
}