From 131e58dc885b059c8917c50bec7b2000905b935e Mon Sep 17 00:00:00 2001
From: Esenia12 <148366616+Esenia12@users.noreply.github.com>
Date: Mon, 4 Mar 2024 11:12:56 +0400
Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?=
=?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D0=B0=20=E2=84=963?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 8 +++---
.../ICollectionGenericObjects.cs | 6 ++---
.../MassiveGenericObjects.cs | 25 ++++++++++---------
.../Drawnings/DrawningDumpTrack.cs | 3 ---
.../Entities/EntityDumpTrack.cs | 2 +-
.../FormTrackCollection.Designer.cs | 2 +-
.../ProjectDumpTruck/FormTrackCollection.cs | 6 ++---
7 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
index 563ac42..ec4a642 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
@@ -53,9 +53,9 @@ public abstract class AbstractCompany
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningTrack car)
+ public static int operator +(AbstractCompany company, DrawningTrack car)
{
- return company._collection?.Insert(car) ?? false;
+ return company._collection.Insert(car);
}
///
@@ -64,9 +64,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningTrack operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection.Remove(position);
}
///
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
index eda278c..9a30125 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -24,7 +24,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -32,14 +32,14 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
index cfb1b26..495535c 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -44,7 +44,7 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
// TODO вставка в свободное место набора
int index = 0;
@@ -53,25 +53,25 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
if (_collection[index] == null)
{
_collection[index] = obj;
- return true;
+ return index;
}
index++;
}
- return false;
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
- if (position >= _collection.Length || position < 0) return false;
+ if (position >= _collection.Length || position < 0) return -1;
if (_collection[position] == null)
{
_collection[position] = obj;
- return true;
+ return position;
}
int index = position + 1;
while (index < _collection.Length)
@@ -79,7 +79,7 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
if (_collection[index] == null)
{
_collection[index] = obj;
- return true;
+ return index;
}
index++;
}
@@ -89,20 +89,21 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
if (_collection[index] == null)
{
_collection[index] = obj;
- return true;
+ return index;
}
index--;
}
- return false;
+ return -1;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
- if (position >= _collection.Length || position < 0) return false;
+ if (position >= _collection.Length || position < 0) return null;
+ T removeObj = _collection[position];
_collection[position] = null;
- return true;
+ return removeObj;
}
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
index b86d1ce..801139e 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
@@ -53,9 +53,6 @@ public class DrawningDumpTrack : DrawningTrack
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value, 3, 40);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value, 3, 40);
}
-
-
- base.DrawTransport(g);
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
index 60cc6ff..945c61f 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
@@ -38,7 +38,7 @@ public class EntityDumpTrack : EntityTrack
/// Признак наличия кузова
/// Признак наличия тента
- public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, Color.Black)
+ public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, bodyColor)
{
AdditionalColor = additionalColor;
Additional2Color = additional2Color;
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
index 8deaa1a..4d419fb 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
@@ -148,7 +148,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(961, 493);
+ ClientSize = new Size(961, 100);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormTrackCollection";
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
index c67031b..d4b36cd 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
@@ -70,14 +70,14 @@ public partial class FormTrackCollection : Form
drawningTrack = new DrawningTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningDumpTrack):
- drawningTrack = new DrawningDumpTrack(random.Next(100, 300), random.Next(1000, 3000), Color.Black, GetColor(random), GetColor(random),
+ drawningTrack = new DrawningDumpTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(2, 2)), Convert.ToBoolean(random.Next(1, 2)));
break;
default:
return;
}
- if (_company + drawningTrack)
+ if (_company + drawningTrack != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -125,7 +125,7 @@ public partial class FormTrackCollection : Form
}
int pos = Convert.ToInt32(maskedTextBox.Text);
- if (_company - pos)
+ if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();