129 lines
3.5 KiB
C#
129 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirFighter
|
|
{
|
|
internal class MapWithSetAircraftsGeneric<T, U>
|
|
where T : class, IDrawingObject
|
|
where U : AbstractMap
|
|
{
|
|
private readonly int _pictureWidth;
|
|
|
|
private readonly int _pictureHeight;
|
|
|
|
private readonly int _placeSizeWidth = 130;
|
|
|
|
private readonly int _placeSizeHeight = 130;
|
|
|
|
private readonly SetAircraftsGeneric<T> _setAircrafts;
|
|
|
|
private readonly U _map;
|
|
|
|
public MapWithSetAircraftsGeneric(int picWidth, int picHeight, U map)
|
|
{
|
|
int width = picWidth / _placeSizeWidth;
|
|
int height = picHeight / _placeSizeHeight;
|
|
_setAircrafts = new SetAircraftsGeneric<T>(width * height);
|
|
_pictureWidth = picWidth;
|
|
_pictureHeight = picHeight;
|
|
_map = map;
|
|
}
|
|
|
|
public static bool operator +(MapWithSetAircraftsGeneric<T, U> map, T aircraft)
|
|
{
|
|
return map._setAircrafts.Insert(aircraft);
|
|
}
|
|
|
|
public static bool operator -(MapWithSetAircraftsGeneric<T, U> map, int position)
|
|
{
|
|
return map._setAircrafts.Remove(position);
|
|
}
|
|
|
|
public Bitmap ShowSet()
|
|
{
|
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
DrawBackground(gr);
|
|
DrawAircrafts(gr);
|
|
return bmp;
|
|
}
|
|
|
|
public Bitmap ShowOnMap()
|
|
{
|
|
Shaking();
|
|
for (int i = 0; i < _setAircrafts.Count; i++)
|
|
{
|
|
var aircraft = _setAircrafts.Get(i);
|
|
if (aircraft != null)
|
|
{
|
|
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
|
|
}
|
|
}
|
|
return new(_pictureWidth, _pictureHeight);
|
|
}
|
|
|
|
public Bitmap MoveObject(Direction direction)
|
|
{
|
|
if (_map != null)
|
|
{
|
|
return _map.MoveObject(direction);
|
|
}
|
|
return new(_pictureWidth, _pictureHeight);
|
|
}
|
|
|
|
|
|
|
|
private void Shaking()
|
|
{
|
|
int j = _setAircrafts.Count - 1;
|
|
for (int i = 0; i < _setAircrafts.Count; i++)
|
|
{
|
|
if (_setAircrafts.Get(i) == null)
|
|
{
|
|
for (; j > i; j--)
|
|
{
|
|
var aircraft = _setAircrafts.Get(i);
|
|
if (aircraft != null)
|
|
{
|
|
_setAircrafts.Insert(aircraft, i);
|
|
_setAircrafts.Remove(j);
|
|
break;
|
|
|
|
}
|
|
}
|
|
if (j <= i)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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++)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void DrawAircrafts(Graphics g)
|
|
{
|
|
for (int i = 0; i < _setAircrafts.Count; i++)
|
|
{
|
|
_setAircrafts.Get(i)?.DrawingObject(g);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|