2023-12-29 22:03:17 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using WarmlyLocomotive.Generics;
|
|
|
|
|
using WarmlyLocomotive.DrawningObjects;
|
|
|
|
|
using WarmlyLocomotive.Entities;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
using WarmlyLocomotive.MovementStrategy;
|
2023-12-29 22:03:17 +04:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
|
using WarmlyLocomotive;
|
|
|
|
|
|
2023-11-10 20:16:55 +04:00
|
|
|
|
namespace WarmlyLocomotive.Generics
|
|
|
|
|
{
|
2023-12-29 22:03:17 +04:00
|
|
|
|
internal class WarmlyLocomotiveGenericCollection<T, U>
|
|
|
|
|
|
2023-11-10 20:16:55 +04:00
|
|
|
|
where T : DrawningWarmlyLocomotive
|
|
|
|
|
where U : IMoveableObject
|
|
|
|
|
{
|
|
|
|
|
private readonly int _pictureWidth;
|
|
|
|
|
private readonly int _pictureHeight;
|
|
|
|
|
private readonly int _placeSizeWidth = 270;
|
|
|
|
|
private readonly int _placeSizeHeight = 100;
|
|
|
|
|
private readonly SetGeneric<T> _collection;
|
2023-12-29 22:03:17 +04:00
|
|
|
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
|
|
|
|
public WarmlyLocomotiveGenericCollection(int picWidth, int picHeight)
|
2023-11-10 20:16:55 +04:00
|
|
|
|
{
|
|
|
|
|
int width = picWidth / _placeSizeWidth;
|
|
|
|
|
int height = picHeight / _placeSizeHeight;
|
|
|
|
|
_pictureWidth = picWidth;
|
|
|
|
|
_pictureHeight = picHeight;
|
|
|
|
|
_collection = new SetGeneric<T>(width * height);
|
|
|
|
|
}
|
2023-12-29 22:03:17 +04:00
|
|
|
|
public static bool operator +(WarmlyLocomotiveGenericCollection<T, U> collect, T? obj)
|
2023-11-10 20:16:55 +04:00
|
|
|
|
{
|
2023-12-29 22:03:17 +04:00
|
|
|
|
if (obj == null || collect == null)
|
2023-11-11 21:26:13 +04:00
|
|
|
|
return false;
|
2023-12-29 22:03:17 +04:00
|
|
|
|
collect._collection.Insert(obj, new DrawingWarmlyLocomotiveEqutables());
|
|
|
|
|
return true;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
}
|
2023-12-29 22:03:17 +04:00
|
|
|
|
public static T? operator -(WarmlyLocomotiveGenericCollection<T, U> collect, int pos)
|
2023-11-10 20:16:55 +04:00
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
T? obj = collect._collection[pos];
|
2023-12-29 22:03:17 +04:00
|
|
|
|
collect._collection.Remove(pos);
|
|
|
|
|
return obj;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
}
|
|
|
|
|
public U? GetU(int pos)
|
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
return (U?)_collection[pos]?.GetMoveableObject;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
public Bitmap ShowWarmlyLocomotives()
|
2023-11-10 20:16:55 +04:00
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
DrawBackground(gr);
|
|
|
|
|
DrawObjects(gr);
|
|
|
|
|
return bmp;
|
|
|
|
|
}
|
|
|
|
|
private void DrawBackground(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
Pen pen = new(Color.Black, 3);
|
|
|
|
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
|
|
|
|
1; ++j)
|
2023-12-29 22:03:17 +04:00
|
|
|
|
{//линия разметки места
|
2023-11-10 20:16:55 +04:00
|
|
|
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
|
|
|
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
|
|
|
|
_placeSizeHeight);
|
|
|
|
|
}
|
|
|
|
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
|
|
|
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void DrawObjects(Graphics g)
|
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
int i = 0;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
|
2023-12-29 21:05:52 +04:00
|
|
|
|
foreach (var warmlylocomotive in _collection.GetWarmlyLocomotive())
|
2023-11-10 20:16:55 +04:00
|
|
|
|
{
|
|
|
|
|
if (warmlylocomotive != null)
|
|
|
|
|
{
|
|
|
|
|
warmlylocomotive.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
|
|
|
|
|
warmlylocomotive.DrawTransport(g);
|
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
i++;
|
2023-11-10 20:16:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-29 22:03:17 +04:00
|
|
|
|
public IEnumerable<T?> GetWarmlyLocomotive => _collection.GetWarmlyLocomotive();
|
2023-11-10 20:16:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|