финалОчка

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();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningBus? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
try
{
DrawningBus? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (Exception) { }
}
return bitmap;
}

View File

@ -1,10 +1,6 @@
using ProjectAccordionBus.CollectionGenericObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AccordionBus.Drawnings;
using AccordionBus.Exceptions;
namespace AccordionBus.CollectionGenericObjects;
@ -38,13 +34,14 @@ public class BusStation : AbstractCompany
{
int posX = 0;
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)?.SetPosition(posX * _placeSizeWidth+5, posY * _placeSizeHeight+5);
_collection?.Get(i)?.SetPosition(posX * _placeSizeWidth + 5, posY * _placeSizeHeight + 5);
}
catch(Exception) {}
if (posY > 0)
{
posY--;

View File

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

View File

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

View File

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