ISE_22.Aparyan.Bulldozer.Base Lab04 #4

Closed
LuizaAparyan wants to merge 5 commits from Laba04 into Laba03
Showing only changes of commit e173941bbc - Show all commits

View File

@ -1,20 +1,19 @@
using ProjectBulldozer.MovementStrategy;
using ProjectBulldozer.Drawning;
using ProjectBulldozer.Drawning;
using ProjectBulldozer.MovementStrategy;
namespace ProjectBulldozer.Generics
{
internal class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
{
//ширина /высота окна
//ширина/высота окна
private readonly int _pictureWidth;
private readonly int _pictureHeight;
//ширина /высота занимаемого места
private readonly int _placeSizeWidth = 170;
//ширина/высота занимаемого места
private readonly int _placeSizeWidth = 150;
private readonly int _placeSizeHeight = 130;
/// Набор объектов
private readonly SetGeneric<T> _collection;
public TractorGenericCollection(int picWidth, int picHeight)
{
// высчитываем размер массива для setgeneric
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@ -23,7 +22,7 @@ namespace ProjectBulldozer.Generics
_collection = new SetGeneric<T>(width * height);
}
/// Перегрузка оператора сложения
public static int operator +(TractorGenericCollection<T, U> collect, T tract)
public static int operator +(TractorGenericCollection<T, U> collect, T? tract)
{
if (tract == null)
{
@ -31,24 +30,20 @@ namespace ProjectBulldozer.Generics
}
return collect._collection.Insert(tract);
}
public static bool operator -(TractorGenericCollection<T, U> collect, int
pos)
/// Перегрузка оператора вычитания
public static T? operator -(TractorGenericCollection<T, U> collect, int pos)
{
T obj = collect._collection.Get(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
return collect.Remove(pos);
collect._collection.Remove(pos);
}
return false;
}
private bool Remove(int pos)
{
throw new NotImplementedException();
return obj;
}
// получение объекта imoveableObj
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
/// Вывод всего набора объектов
public Bitmap ShowTractors()
@ -74,19 +69,25 @@ namespace ProjectBulldozer.Generics
}
private void DrawObjects(Graphics g)
{
int HeightObjCount = _pictureHeight / _placeSizeHeight;
int WidthObjCount = _pictureWidth / _placeSizeWidth;
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++)
{
T t = _collection.Get(i);
if (t != null)
{
{
t.SetPosition(((_collection.Count - i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection.Count - i - 1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
t.DrawTransport(g);
}
}
// Получение объекта
var obj = _collection[i];
// Установка позиции
obj?.SetPosition(
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
);
// Прорисовка объекта
obj?.DrawTransport(g);
}
}
}
}