Лабораторная работка #3
This commit is contained in:
parent
dc01587054
commit
681e60fbd6
@ -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()
|
||||
|
@ -16,14 +16,14 @@
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
int Insert(T obj);
|
||||
T? Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление элемента в коллекцию на определенную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
bool Insert(T obj, int position);
|
||||
T? Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// Удаление элемента из коллекции по его позиции
|
||||
/// </summary>
|
||||
|
@ -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)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (arr[position] == null)
|
||||
{
|
||||
arr[position] = obj;
|
||||
return arr[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
int flag = -1;
|
||||
for (int i = position + 1; i < arr.Length; i++)
|
||||
if (Insert(obj, position + 1) != null)
|
||||
{
|
||||
if (arr[i] == null)
|
||||
return arr[position + 1];
|
||||
}
|
||||
if (Insert(obj, position - 1) != null)
|
||||
{
|
||||
flag = 1;
|
||||
arr[i] = obj;
|
||||
break;
|
||||
return arr[position - 1];
|
||||
}
|
||||
}
|
||||
if (flag == -1 && position != 0)
|
||||
{
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (arr[i] == null)
|
||||
{
|
||||
arr[i] = obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -47,7 +47,6 @@
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
@ -119,7 +118,6 @@
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestination();
|
||||
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user