финалОчка

This commit is contained in:
repka228 2024-06-12 20:44:28 +04:00
parent d15a731a0b
commit a794117141
6 changed files with 60 additions and 56 deletions

View File

@ -1,6 +0,0 @@
using AccordionBus.Drawnings;
namespace AccordionBus;
public delegate void BusDelegate(DrawningBus bus);

View File

@ -91,8 +91,12 @@ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{ {
DrawningBus? obj = _collection?.Get(i); try
obj?.DrawTransport(graphics); {
DrawningBus? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (Exception) { }
} }
return bitmap; return bitmap;
} }

View File

@ -1,10 +1,6 @@
using ProjectAccordionBus.CollectionGenericObjects; using ProjectAccordionBus.CollectionGenericObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AccordionBus.Drawnings; using AccordionBus.Drawnings;
using AccordionBus.Exceptions;
namespace AccordionBus.CollectionGenericObjects; namespace AccordionBus.CollectionGenericObjects;
@ -38,13 +34,14 @@ public class BusStation : AbstractCompany
{ {
int posX = 0; int posX = 0;
int posY = _pictureHeight / _placeSizeHeight-1; int posY = _pictureHeight / _placeSizeHeight-1;
for (int i = 0; i < _collection?.Count; i++) for (int i = 0; i < (_collection?.Count ?? 0); i++)
{ {
if (_collection.Get(i) != null) try
{ {
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(posX * _placeSizeWidth+5, posY * _placeSizeHeight+5); _collection?.Get(i)?.SetPosition(posX * _placeSizeWidth + 5, posY * _placeSizeHeight + 5);
} }
catch(Exception) {}
if (posY > 0) if (posY > 0)
{ {
posY--; posY--;

View File

@ -10,13 +10,13 @@ namespace AccordionBus.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _collection; private T?[] _collection;
public int Count => _collection.Length; public int Count => _collection.Length;
public int MaxCount public int MaxCount
{ {
get get
{ {
return _collection.Length; return _collection.Length;
@ -36,26 +36,29 @@ where T : class
} }
} }
} }
public CollectionType GetCollectionType => CollectionType.Massive; public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects() public MassiveGenericObjects()
{ {
_collection = Array.Empty<T?>(); _collection = Array.Empty<T?>();
} }
public T? Get(int position) // получение с позиции
public T Get(int position)
{ {
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position); if (position < 0 || position >= _collection.Length)
if (_collection[position] == null) throw new ObjectNotFoundException(position); {
throw new PositionOutOfCollectionException();
}
if (_collection[position] == null)
{
throw new ObjectNotFoundException(position);
}
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) // вставка объекта на свободное место
public int Insert(T obj)
{ {
for (int i = 0; i < Count; i++) for (int i = 0; i < _collection.Length; i++)
{ {
if (_collection[i] == null) if (_collection[i] == null)
{ {
@ -65,52 +68,60 @@ where T : class
} }
throw new CollectionOverflowException(Count); throw new CollectionOverflowException(Count);
} }
public int Insert(T obj, int position) // вставка объекта на место
public int Insert(T obj, int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= _collection.Length)
{ {
throw new PositionOutOfCollectionException(position); throw new PositionOutOfCollectionException(position);
} }
if (_collection[position] == null) if (_collection[position] == null)
{ {
_collection[position] = obj; _collection[position] = obj;
return position; return position;
} }
else
for (int i = position + 1; i < Count; i++)
{ {
if (_collection[i] == null) for (int i = position; i < _collection.Length; ++i) //ищем свободное место справа
{ {
_collection[i] = obj; if (_collection[i] == null)
return i; {
_collection[i] = obj;
return i;
}
}
for (int i = 0; i < position; ++i) // иначе слева
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
} }
} }
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
throw new CollectionOverflowException(Count); throw new CollectionOverflowException(Count);
} }
public T? Remove(int position) // удаление объекта, зануляя его
public T? Remove(int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= _collection.Length)
{
throw new PositionOutOfCollectionException(position); throw new PositionOutOfCollectionException(position);
}
if (_collection[position] == null) throw new ObjectNotFoundException(position);
T? obj = _collection[position]; T? obj = _collection[position];
_collection[position] = null; if (_collection[position] == null)
{
throw new ObjectNotFoundException(position);
}
if (_collection[position] != null)
{
_collection[position] = null;
}
return obj; return obj;
} }
public IEnumerable<T?> GetItems() public IEnumerable<T?> GetItems()
{ {
for(int i=0;i<_collection.Length;i++) for (int i = 0; i < _collection.Length; ++i)
{ {
yield return _collection[i]; yield return _collection[i];
} }

View File

@ -215,5 +215,4 @@ public class StorageCollection<T> where T : DrawningBus
_ => null, _ => null,
}; };
} }
} }

View File

@ -252,5 +252,4 @@ public partial class FormBusCollection : Form
} }
} }
} }
} }
}