pibd-12 Tangatarov.I.A. LabWork05 Base #19
@ -1,5 +1,4 @@
|
||||
using HoistingCrane.Drawning;
|
||||
using System;
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
public abstract class AbstractCompany
|
||||
@ -31,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth);
|
||||
return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-3;
|
||||
}
|
||||
}
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> array)
|
||||
@ -48,7 +47,7 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
}
|
||||
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company.arr?.Remove(position) ?? null;
|
||||
return company.arr?.Remove(position);
|
||||
}
|
||||
|
||||
public DrawningTrackedVehicle? GetRandomObject()
|
||||
@ -75,7 +74,6 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,4 @@
|
||||
using HoistingCrane.Drawning;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
public class Garage : AbstractCompany
|
||||
@ -23,7 +20,6 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int countWidth = pictureWidth / _placeSizeWidth;
|
||||
@ -39,7 +35,7 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight);
|
||||
arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, _placeSizeHeight * currentPosHeight + 15);
|
||||
}
|
||||
|
||||
|
||||
if (currentPosWidth > 0)
|
||||
currentPosWidth--;
|
||||
else
|
||||
@ -54,5 +50,6 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T: class
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
@ -24,8 +25,7 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
get { return list.Count; }
|
||||
}
|
||||
|
||||
public int SetMaxCount
|
||||
public int SetMaxCount
|
||||
{
|
||||
set
|
||||
{
|
||||
@ -38,19 +38,14 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count || position < 0) return null;
|
||||
return list[position];
|
||||
}
|
||||
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
return -1;
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
list.Add(obj);
|
||||
return Count;
|
||||
@ -58,21 +53,16 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (position < 0 || position >= Count || Count == _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
list.Insert(position, obj);
|
||||
return position;
|
||||
return position;
|
||||
}
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (position >= 0 && position < list.Count)
|
||||
if(position >= 0 && position < list.Count)
|
||||
{
|
||||
T? temp = list[position];
|
||||
list.RemoveAt(position);
|
||||
|
@ -10,7 +10,7 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
get { return arr.Length; }
|
||||
get { return arr.Length; }
|
||||
}
|
||||
public int SetMaxCount
|
||||
{
|
||||
@ -45,28 +45,33 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
//todo Проверка позиции
|
||||
if (position < 0 || position > Count)
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arr[position] == null)
|
||||
int copyPos = position - 1;
|
||||
|
||||
while (position < Count)
|
||||
{
|
||||
arr[position] = obj;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Insert(obj, position + 1) != -1)
|
||||
{
|
||||
return position;
|
||||
}
|
||||
if (Insert(obj, position - 1) != -1)
|
||||
if (arr[position] == null)
|
||||
{
|
||||
arr[position] = obj;
|
||||
return position;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
while (copyPos > 0)
|
||||
{
|
||||
if (arr[copyPos] == null)
|
||||
{
|
||||
arr[copyPos] = obj;
|
||||
return copyPos;
|
||||
}
|
||||
copyPos--;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -25,17 +25,12 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name) && !Keys.Contains(name))
|
||||
{
|
||||
if(collectionType == CollectionType.Massive)
|
||||
{
|
||||
dict.Add(name, new MassivGenericObjects<T> ());
|
||||
}
|
||||
if(collectionType == CollectionType.List)
|
||||
{
|
||||
dict.Add(name, new ListGenericObjects<T> ());
|
||||
}
|
||||
}
|
||||
if (dict.ContainsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
dict[name] = new MassivGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List)
|
||||
dict[name] = new ListGenericObjects<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
@ -43,8 +38,10 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (dict.ContainsKey(name))
|
||||
if (Keys.Contains(name))
|
||||
{
|
||||
dict.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
@ -55,9 +52,11 @@ namespace HoistingCrane.CollectionGenericObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
if (name == null || !dict.ContainsKey(name)) { return null; }
|
||||
return dict[name];
|
||||
if (dict.ContainsKey(name))
|
||||
return dict[name];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -206,4 +206,4 @@ namespace HoistingCrane
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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