Morozov V.S. LabWork03 #4
124
AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs
Normal file
124
AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class MapWithSetPlainGeneric
|
||||
<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
|
||||
private readonly SetPlaneGeneric<T> _setPlains;
|
||||
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetPlainGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setPlains = new SetPlaneGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static bool operator +(MapWithSetPlainGeneric<T, U> map, T plain)
|
||||
{
|
||||
return map._setPlains.Insert(plain);
|
||||
}
|
||||
|
||||
public static bool operator -(MapWithSetPlainGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setPlains.Remove(position);
|
||||
}
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawPlains(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setPlains.Count; i++)
|
||||
{
|
||||
var plain = _setPlains.Get(i);
|
||||
if (plain != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plain);
|
||||
}
|
||||
}
|
||||
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 = _setPlains.Count - 1;
|
||||
for (int i = 0; i < _setPlains.Count; i++)
|
||||
{
|
||||
if (_setPlains.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var plain = _setPlains.Get(j);
|
||||
if (plain != null)
|
||||
{
|
||||
_setPlains.Insert(plain, i);
|
||||
_setPlains.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Brush BrushRazmetka = new SolidBrush(Color.DarkGray);
|
||||
|
||||
Pen pen = new(Color.White, 5);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
|
||||
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 DrawPlains(Graphics g)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
38
AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs
Normal file
38
AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class SetPlaneGeneric<T>
|
||||
where T : class
|
||||
|
||||
{
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetPlaneGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
public bool Insert(T plain)
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
public bool Insert(T plain, int position)
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public T Get(int position)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Правильнее было вызвать Insert(T obj, 0);