126 lines
4.2 KiB
C#
126 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirBomber
|
|
{
|
|
internal class MapWithSetAirBomberGeneric<T, U>
|
|
where T : class, IDrawningObject
|
|
where U : AbstractMap
|
|
{
|
|
private readonly int _pictureWidth;
|
|
private readonly int _pictureHeight;
|
|
private readonly int _placeSizeWidth = 210;
|
|
private readonly int _placeSizeHeight = 120;
|
|
private readonly SetAirBomberGeneric<T> _setAirBomber;
|
|
private readonly U _map;
|
|
|
|
public MapWithSetAirBomberGeneric(int picWidth, int picHeight, U map)
|
|
{
|
|
int width = picWidth / _placeSizeWidth;
|
|
int height = picHeight / _placeSizeHeight;
|
|
_setAirBomber = new SetAirBomberGeneric<T>(width * height);
|
|
_pictureWidth = picWidth;
|
|
_pictureHeight = picHeight;
|
|
_map = map;
|
|
}
|
|
|
|
public static int operator +(MapWithSetAirBomberGeneric<T, U> map, T airBomber)
|
|
{
|
|
return map._setAirBomber.Insert(airBomber);
|
|
}
|
|
|
|
public static T operator -(MapWithSetAirBomberGeneric<T, U> map, int position)
|
|
{
|
|
return map._setAirBomber.Remove(position);
|
|
}
|
|
|
|
public Bitmap ShowSet()
|
|
{
|
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
DrawBackground(gr);
|
|
DrawAirBomber(gr);
|
|
return bmp;
|
|
}
|
|
|
|
public Bitmap ShowOnMap()
|
|
{
|
|
Shaking();
|
|
for (int i = 0; i < _setAirBomber.Count; i++)
|
|
{
|
|
var airBomber = _setAirBomber.Get(i);
|
|
if (airBomber != null)
|
|
{
|
|
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
|
|
}
|
|
}
|
|
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 = _setAirBomber.Count - 1;
|
|
for (int i = 0; i < _setAirBomber.Count; i++)
|
|
{
|
|
if (_setAirBomber.Get(i) == null)
|
|
{
|
|
for (; j > i; j--)
|
|
{
|
|
var airBomber = _setAirBomber.Get(j);
|
|
if (airBomber != null)
|
|
{
|
|
_setAirBomber.Insert(airBomber, i);
|
|
_setAirBomber.Remove(j);
|
|
break;
|
|
}
|
|
}
|
|
if (j <= i)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void DrawBackground(Graphics g)
|
|
{
|
|
Pen pen = new(Color.DarkGreen, 3);
|
|
SolidBrush brush = new(Color.DarkGreen);
|
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
|
|
{
|
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j)
|
|
{
|
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
|
g.DrawPie(pen, new Rectangle(i * _placeSizeWidth - 25, j * _placeSizeHeight, 50, 120), -90, 180);
|
|
g.FillPie(brush, new Rectangle((i + 1) * _placeSizeWidth - _placeSizeHeight - 10, j * _placeSizeHeight, 50, 120), -90, 180);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DrawAirBomber(Graphics g)
|
|
{
|
|
for (int i = 0; i < _setAirBomber.Count; ++i)
|
|
{
|
|
if (_setAirBomber.Get(i) != null)
|
|
{
|
|
_setAirBomber.Get(i).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
|
_setAirBomber.Get(i).DrawningObject(g);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|