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