2024-10-03 01:40:53 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ProjectGasolineTanker.Drawings;
|
|
|
|
|
using ProjectGasolineTanker.MovementStratg;
|
|
|
|
|
|
|
|
|
|
namespace ProjectGasolineTanker.Generic
|
|
|
|
|
{
|
|
|
|
|
internal class TruckGenericCollection<T, U>
|
|
|
|
|
where T : DrawingTruck
|
|
|
|
|
where U : IMoveableObject
|
|
|
|
|
{
|
|
|
|
|
private readonly int _pictureWidth;
|
|
|
|
|
private readonly int _pictureHeight;
|
|
|
|
|
|
|
|
|
|
private readonly int _placeSizeWidth = 200;
|
|
|
|
|
private readonly int _placeSizeHeight = 80;
|
|
|
|
|
|
|
|
|
|
private readonly SetGeneric<T> _collection;
|
|
|
|
|
|
|
|
|
|
|
2024-10-03 01:42:04 +04:00
|
|
|
|
|
2024-10-03 01:40:53 +04:00
|
|
|
|
public TruckGenericCollection(int picWidth, int picHeight)
|
|
|
|
|
{
|
|
|
|
|
int width = picWidth / _placeSizeWidth;
|
|
|
|
|
int height = picHeight / _placeSizeHeight;
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
|
|
|
|
|
_collection = new SetGeneric<T>(width * height);
|
|
|
|
|
}
|
|
|
|
|
public static int operator +(TruckGenericCollection<T, U> collect, T? obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
return collect._collection.Insert(obj);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
public static bool operator -(TruckGenericCollection<T, U> collect, int pos)
|
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
if (collect._collection.GetTruck(pos) == null)
|
2024-10-03 01:40:53 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return collect?._collection.Remove(pos) ?? false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public U? GetU(int pos)
|
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
return (U?)_collection[pos]?.GetMoveableObject;
|
2024-10-03 01:40:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Bitmap ShowTruck()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
DrawBackground(gr);
|
|
|
|
|
DrawObjects(gr);
|
|
|
|
|
return bmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawBackground(Graphics gr)
|
|
|
|
|
{
|
|
|
|
|
Pen pen = new(Color.Black, 3);
|
|
|
|
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
// линия разметки
|
2024-10-03 01:40:53 +04:00
|
|
|
|
gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
|
|
|
|
gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 01:42:04 +04:00
|
|
|
|
|
2024-10-03 01:40:53 +04:00
|
|
|
|
private void DrawObjects(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
2024-10-03 01:42:04 +04:00
|
|
|
|
int y = _pictureHeight / _placeSizeHeight - 1;
|
2024-10-03 01:40:53 +04:00
|
|
|
|
|
2024-10-03 01:42:04 +04:00
|
|
|
|
foreach (var truck in _collection.GetTruck())
|
2024-10-03 01:40:53 +04:00
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
if (truck != null)
|
2024-10-03 01:40:53 +04:00
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
if (x > _pictureWidth / _placeSizeWidth - 1)
|
2024-10-03 01:40:53 +04:00
|
|
|
|
{
|
2024-10-03 01:42:04 +04:00
|
|
|
|
x = 0;
|
|
|
|
|
--y;
|
2024-10-03 01:40:53 +04:00
|
|
|
|
}
|
2024-10-03 01:42:04 +04:00
|
|
|
|
truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
|
|
|
|
truck.DrawTransport(g);
|
|
|
|
|
++x;
|
2024-10-03 01:40:53 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|