Compare commits
2 Commits
b967200792
...
681e60fbd6
Author | SHA1 | Date | |
---|---|---|---|
|
681e60fbd6 | ||
dc01587054 |
@ -1,5 +1,4 @@
|
|||||||
using HoistingCrane.Drawning;
|
using HoistingCrane.Drawning;
|
||||||
using System;
|
|
||||||
namespace HoistingCrane.CollectionGenericObjects
|
namespace HoistingCrane.CollectionGenericObjects
|
||||||
{
|
{
|
||||||
public abstract class AbstractCompany
|
public abstract class AbstractCompany
|
||||||
@ -42,13 +41,13 @@ namespace HoistingCrane.CollectionGenericObjects
|
|||||||
arr.SetMaxCount = GetMaxCount;
|
arr.SetMaxCount = GetMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator +(AbstractCompany company, DrawningTrackedVehicle car)
|
public static DrawningTrackedVehicle operator +(AbstractCompany company, DrawningTrackedVehicle car)
|
||||||
{
|
{
|
||||||
return company.arr?.Insert(car) ?? false;
|
return company.arr?.Insert(car) ?? null;
|
||||||
}
|
}
|
||||||
public static bool operator -(AbstractCompany company, int position)
|
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
|
||||||
{
|
{
|
||||||
return company.arr?.Remove(position) ?? false;
|
return company.arr?.Remove(position) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawningTrackedVehicle? GetRandomObject()
|
public DrawningTrackedVehicle? GetRandomObject()
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using HoistingCrane.Drawning;
|
using HoistingCrane.Drawning;
|
||||||
using System;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace HoistingCrane.CollectionGenericObjects
|
namespace HoistingCrane.CollectionGenericObjects
|
||||||
{
|
{
|
||||||
public class Garage : AbstractCompany
|
public class Garage : AbstractCompany
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
namespace HoistingCrane.CollectionGenericObjects
|
||||||
namespace HoistingCrane.CollectionGenericObjects
|
|
||||||
{
|
{
|
||||||
public interface ICollectionGenericObjects<T>
|
public interface ICollectionGenericObjects<T>
|
||||||
where T: class
|
where T: class
|
||||||
@ -17,20 +16,20 @@ namespace HoistingCrane.CollectionGenericObjects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool Insert(T obj);
|
T? Insert(T obj);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление элемента в коллекцию на определенную позицию
|
/// Добавление элемента в коллекцию на определенную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool Insert(T obj, int position);
|
T? Insert(T obj, int position);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление элемента из коллекции по его позиции
|
/// Удаление элемента из коллекции по его позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool Remove(int position);
|
T? Remove(int position);
|
||||||
T? Get(int position);
|
T? Get(int position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
namespace HoistingCrane.CollectionGenericObjects
|
||||||
namespace HoistingCrane.CollectionGenericObjects
|
|
||||||
{
|
{
|
||||||
public class MassivGenericObjects<T> : ICollectionGenericObjects<T> where T : class
|
public class MassivGenericObjects<T> : ICollectionGenericObjects<T> where T : class
|
||||||
{
|
{
|
||||||
@ -31,64 +30,54 @@ namespace HoistingCrane.CollectionGenericObjects
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool 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) {
|
if (arr[i] == null)
|
||||||
arr[i] = obj;
|
{
|
||||||
return true;
|
return Insert(obj, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T obj, int position)
|
public T? Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
// Проверка позиции
|
//todo Проверка позиции
|
||||||
if (position < Count && position >= 0)
|
if (position < 0 || position > Count)
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (arr[position] == null)
|
if (arr[position] == null)
|
||||||
{
|
{
|
||||||
arr[position] = obj;
|
arr[position] = obj;
|
||||||
|
return arr[position];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int flag = -1;
|
if (Insert(obj, position + 1) != null)
|
||||||
for (int i = position + 1; i < arr.Length; i++)
|
|
||||||
{
|
{
|
||||||
if (arr[i] == null)
|
return arr[position + 1];
|
||||||
|
}
|
||||||
|
if (Insert(obj, position - 1) != null)
|
||||||
{
|
{
|
||||||
flag = 1;
|
return arr[position - 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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
public T? Remove(int position)
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(int position)
|
|
||||||
{
|
{
|
||||||
if(position < 0 || position >= arr.Length || arr[position] == null)
|
if(position >= 0 && position < Count)
|
||||||
{
|
{
|
||||||
return false;
|
T? temp = arr[position];
|
||||||
}
|
|
||||||
arr[position] = null;
|
arr[position] = null;
|
||||||
return true;
|
return temp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
using HoistingCrane.CollectionGenericObjects;
|
using HoistingCrane.CollectionGenericObjects;
|
||||||
using HoistingCrane.Drawning;
|
using HoistingCrane.Drawning;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace HoistingCrane
|
namespace HoistingCrane
|
||||||
{
|
{
|
||||||
public partial class FormCarCollection : Form
|
public partial class FormCarCollection : Form
|
||||||
@ -30,7 +20,6 @@ namespace HoistingCrane
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void CreateObject(string type)
|
private void CreateObject(string type)
|
||||||
{
|
{
|
||||||
DrawningTrackedVehicle drawning;
|
DrawningTrackedVehicle drawning;
|
||||||
@ -49,7 +38,7 @@ namespace HoistingCrane
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + drawning)
|
if ((_company + drawning) != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
@ -71,8 +60,6 @@ namespace HoistingCrane
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane));
|
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane));
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +78,7 @@ namespace HoistingCrane
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
if (_company - pos)
|
if ((_company - pos) != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален!");
|
MessageBox.Show("Объект удален!");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
FieldWidth = width;
|
FieldWidth = width;
|
||||||
FieldHeight = height;
|
FieldHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения
|
/// Шаг перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -119,7 +118,6 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected abstract bool IsTargetDestination();
|
protected abstract bool IsTargetDestination();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Попытка перемещения в требуемом направлении
|
/// Попытка перемещения в требуемом направлении
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace HoistingCrane.MovementStrategy
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace HoistingCrane.MovementStrategy
|
||||||
{
|
{
|
||||||
public class MoveToBorder : AbstractStrategy
|
public class MoveToBorder : AbstractStrategy
|
||||||
{
|
{
|
||||||
@ -12,7 +14,6 @@
|
|||||||
|
|
||||||
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void MoveToTarget()
|
protected override void MoveToTarget()
|
||||||
{
|
{
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
Loading…
Reference in New Issue
Block a user