создала новый generic класс
This commit is contained in:
parent
a03be5f062
commit
54db2e3780
@ -70,15 +70,16 @@ namespace Catamaran.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
||||
public static T? operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
@ -86,8 +87,9 @@ namespace Catamaran.Generics
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
@ -125,15 +127,16 @@ namespace Catamaran.Generics
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
|
||||
{
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
T? obj;
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
int diff = 1, currWidth = 0;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
int diff = 1, currWidth = 0, i = 0;
|
||||
foreach (var catamaran in _collection.GetCatamarans())
|
||||
{
|
||||
currWidth++;
|
||||
if (currWidth > width)
|
||||
@ -141,12 +144,13 @@ namespace Catamaran.Generics
|
||||
diff++;
|
||||
currWidth = 1;
|
||||
}
|
||||
obj = _collection.Get(i);
|
||||
if (obj != null)
|
||||
if (catamaran != null)
|
||||
{
|
||||
obj.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
|
||||
catamaran.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
|
||||
(height - diff) * _placeSizeHeight + _placeSizeHeight / 15);
|
||||
obj.DrawTransport(g);
|
||||
catamaran.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
70
base/Catamaran/Catamaran/CatamaransGenericStorage.cs
Normal file
70
base/Catamaran/Catamaran/CatamaransGenericStorage.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.MovementStrategy;
|
||||
namespace Catamaran.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class CatamaransGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, CatamaransGenericCollection<DrawningCatamaran,
|
||||
DrawningObjectCatamaran>> _catamaranStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _catamaranStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public CatamaransGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_catamaranStorages = new Dictionary<string,
|
||||
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,20 +14,25 @@ namespace Catamaran.Generics
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -95,12 +100,45 @@ namespace Catamaran.Generics
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count)
|
||||
if (position < 0 || position > _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка свободных мест в списке
|
||||
// TODO вставка в список по позиции
|
||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.Insert(position, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetCatamarans(int? maxCatamarans = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxCatamarans.HasValue && i == maxCatamarans.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user