From 681e60fbd6355a94acf216c2be031016117dff19 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Mon, 1 Apr 2024 18:26:17 +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=BA=D0=B0=20#3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 6 +-
.../ICollectionGenericObjects.cs | 4 +-
.../MassivGenericObjects.cs | 69 ++++++++-----------
.../HoistingCrane/FormCarCollection.cs | 7 +-
.../MovementStrategy/AbstractStrategy.cs | 2 -
.../MovementStrategy/MoveToBorder.cs | 5 +-
6 files changed, 39 insertions(+), 54 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index b7dbbee..45ca30e 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -41,13 +41,13 @@ namespace HoistingCrane.CollectionGenericObjects
arr.SetMaxCount = GetMaxCount;
}
- public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
+ public static DrawningTrackedVehicle operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
- return company.arr?.Insert(car) ?? 0;
+ return company.arr?.Insert(car) ?? null;
}
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{
- return company.arr?.Remove(position);
+ return company.arr?.Remove(position) ?? null;
}
public DrawningTrackedVehicle? GetRandomObject()
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 5182f15..ce4dbb0 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -16,14 +16,14 @@
///
///
///
- int Insert(T obj);
+ T? Insert(T obj);
///
/// Добавление элемента в коллекцию на определенную позицию
///
///
///
///
- bool Insert(T obj, int position);
+ T? Insert(T obj, int position);
///
/// Удаление элемента из коллекции по его позиции
///
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index ac0d22a..0fcf4a2 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -30,65 +30,54 @@
return null;
}
- public int Insert(T obj)
+ public T? Insert(T obj)
{
- for(int i = 0; i < Count; i++)
+ for (int i = 0; i < Count; i++)
{
- if (arr[i] == null) {
- Insert(obj,i);
- return 1;
- }
+ if (arr[i] == null)
+ {
+ return Insert(obj, 0);
+ }
}
- return 0;
+ return null;
}
- public bool Insert(T obj, int position)
+ public T? Insert(T obj, int position)
{
- // Проверка позиции
- if (position < Count && position >= 0)
+ //todo Проверка позиции
+ if (position < 0 || position > Count)
{
- if (arr[position] == null)
+ return null;
+ }
+
+ if (arr[position] == null)
+ {
+ arr[position] = obj;
+ return arr[position];
+ }
+ else
+ {
+ if (Insert(obj, position + 1) != null)
{
- arr[position] = obj;
+ return arr[position + 1];
}
- else
+ if (Insert(obj, position - 1) != null)
{
- int flag = -1;
- for (int i = position + 1; i < arr.Length; i++)
- {
- if (arr[i] == null)
- {
- flag = 1;
- arr[i] = obj;
- break;
- }
- }
- if (flag == -1 && position != 0)
- {
- for (int i = position - 1; i >= 0; i--)
- {
- if (arr[i] == null)
- {
- arr[i] = obj;
- break;
- }
- }
- }
+ return arr[position - 1];
}
}
-
- return false;
- }
+ return null;
+ }
public T? Remove(int position)
{
if(position >= 0 && position < Count)
{
+ T? temp = arr[position];
arr[position] = null;
- return arr[position];
+ return temp;
}
- return arr[position];
+ return null;
}
-
}
}
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 6c6c042..fb77e28 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -20,7 +20,6 @@ namespace HoistingCrane
}
}
-
private void CreateObject(string type)
{
DrawningTrackedVehicle drawning;
@@ -39,7 +38,7 @@ namespace HoistingCrane
default:
return;
}
- if ((_company + drawning) == 1)
+ if ((_company + drawning) != null)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -61,8 +60,6 @@ namespace HoistingCrane
return color;
}
-
-
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane));
@@ -81,7 +78,7 @@ namespace HoistingCrane
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
- if ((_company - pos) == null)
+ if ((_company - pos) != null)
{
MessageBox.Show("Объект удален!");
pictureBox.Image = _company.Show();
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs
index 43e18e9..f8f3173 100644
--- a/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs
@@ -47,7 +47,6 @@
FieldWidth = width;
FieldHeight = height;
}
-
///
/// Шаг перемещения
///
@@ -119,7 +118,6 @@
///
///
protected abstract bool IsTargetDestination();
-
///
/// Попытка перемещения в требуемом направлении
///
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs
index 99cb56b..3d19b4d 100644
--- a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs
@@ -1,4 +1,6 @@
-namespace HoistingCrane.MovementStrategy
+using System.Configuration;
+
+namespace HoistingCrane.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
@@ -12,7 +14,6 @@
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
}
-
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;