Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
783ff07009 | |||
e7f367dc4d | |||
950ea78e74 | |||
075103c116 | |||
76e036db5b | |||
c53f18d132 | |||
74d3f54baf | |||
e4e8b56404 | |||
dfaaa3c746 | |||
8021e8ec78 | |||
b3844b27e5 | |||
54a57600a4 | |||
557028cc39 | |||
726373a2a1 | |||
906637e4b8 | |||
7adc066c5c | |||
937cf9e202 | |||
f210de00c3 | |||
32ff4df6d8 | |||
ede63a0ae5 | |||
2b1fbcbf93 | |||
3835f12fd0 | |||
9472abce93 | |||
dfa874b91f | |||
829029a6dc | |||
0b71bfd2b5 | |||
9b6d4ecda2 | |||
521d4750de | |||
6c82157b44 | |||
3ad2071256 | |||
ed09a0e092 | |||
4bf485c19e | |||
9cadd9bb31 | |||
52950b54cb | |||
1d0a18b4b7 | |||
2fba868169 | |||
53391ab2ec | |||
442ea73375 | |||
b2213886a7 | |||
f4bf49eca1 | |||
0bdfe1f404 | |||
c8cd888bf1 | |||
379eabc701 | |||
fd17593df5 | |||
c11d4126a5 | |||
8cd9bd77c1 | |||
21f5c7ac1b | |||
68ac0088fd | |||
5890fcbba7 | |||
5c75d533a1 | |||
f338060869 | |||
b69d10b872 | |||
03c6fa946c | |||
297eb3a2ab | |||
e6028b4a0e | |||
12ba5a0148 | |||
23663c6c47 | |||
63b5bc994b | |||
5a4093e10f | |||
e8e666afdc | |||
0d60e02b8a | |||
e1ac61109d | |||
393b97f071 | |||
6e1a5eb9c4 | |||
c9489b66f7 | |||
ff4b2f7e71 | |||
6e1fa7e9ec | |||
cf72203a1c |
131
AirBomber/AirBomber/AbstractStrategy.cs
Normal file
131
AirBomber/AirBomber/AbstractStrategy.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Высота поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
/// <summary>
|
||||||
|
/// Установка данных
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
|
height)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition;
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directionType">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,4 +8,30 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
20
AirBomber/AirBomber/AppSettings.json
Normal file
20
AirBomber/AirBomber/AppSettings.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log_.log",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "AirBombers"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
AirBomber/AirBomber/Direction.cs
Normal file
16
AirBomber/AirBomber/Direction.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
62
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
62
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class DrawningAirBomber : DrawningAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bombs">Признак наличия обвеса</param>
|
||||||
|
/// <param name="fuelTanks">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public DrawningAirBomber(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bombs, bool fuelTanks, int width, int height) :
|
||||||
|
base(speed, weight, bodyColor, width, height, 160, 118)
|
||||||
|
{
|
||||||
|
if (EntityAirPlane != null)
|
||||||
|
{
|
||||||
|
EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawPlane(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAirPlane is not EntityAirBomber airBomber)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
|
||||||
|
base.DrawPlane(g);
|
||||||
|
// bombs
|
||||||
|
if(airBomber.Bombs)
|
||||||
|
{
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15);
|
||||||
|
}
|
||||||
|
// fueltanks
|
||||||
|
if (airBomber.FuelTanks)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
277
AirBomber/AirBomber/DrawningAirPlane.cs
Normal file
277
AirBomber/AirBomber/DrawningAirPlane.cs
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class DrawningAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityAirPlane? EntityAirPlane { get; protected set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
public int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
public int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата прорисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected int _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя кооридната прорисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected int _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина прорисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _airPlaneWidth = 150;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _airPlaneHeight = 118;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public DrawningAirPlane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
|
{
|
||||||
|
// TODO: Продумать проверки
|
||||||
|
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
/// <param name="airPlaneWidth">Ширина прорисовки самолета</param>
|
||||||
|
/// <param name="airPlaneHeight">Высота прорисовки самолета</param>
|
||||||
|
protected DrawningAirPlane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height, int airPlaneWidth, int airPlaneHeight)
|
||||||
|
{
|
||||||
|
// TODO: Продумать проверки
|
||||||
|
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_airPlaneWidth = airPlaneWidth;
|
||||||
|
_airPlaneHeight = airPlaneHeight;
|
||||||
|
EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
// TODO: Изменение x, y, если при установке объект выходит за границы
|
||||||
|
if (x < 0 || x + _airPlaneWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x = _pictureWidth - _airPlaneWidth;
|
||||||
|
}
|
||||||
|
if (y < 0 || y + _airPlaneHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = _pictureHeight - _airPlaneHeight;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public virtual void DrawPlane(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush bodyColor = new SolidBrush(EntityAirPlane.BodyColor);
|
||||||
|
Brush wingsColor = new SolidBrush(Color.DeepPink);
|
||||||
|
g.FillPolygon(bodyColor, new Point[] //nose
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 19, _startPosY + 50),
|
||||||
|
new Point(_startPosX + 19, _startPosY + 69),
|
||||||
|
new Point(_startPosX + 1, _startPosY + 59),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //body
|
||||||
|
g.FillPolygon(bodyColor, new Point[] //up left wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 36, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 36, _startPosY + 1),
|
||||||
|
new Point(_startPosX + 45, _startPosY + 1),
|
||||||
|
new Point(_startPosX + 55, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.FillPolygon(bodyColor, new Point[] //down left wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 36, _startPosY + 71),
|
||||||
|
new Point(_startPosX + 36, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 45, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 54, _startPosY + 71),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.FillPolygon(wingsColor, new Point[] //up right wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 42),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 7),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.FillPolygon(wingsColor, new Point[] //down right wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 70),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 77),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 112),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 70),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
g.DrawPolygon(pen, new Point[] //nose
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 20, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 70),
|
||||||
|
new Point(_startPosX, _startPosY + 59),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //body
|
||||||
|
g.DrawPolygon(pen, new Point[] //up left wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 35, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 35, _startPosY),
|
||||||
|
new Point(_startPosX + 45, _startPosY),
|
||||||
|
new Point(_startPosX + 55, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //down left wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 36, _startPosY + 71),
|
||||||
|
new Point(_startPosX + 36, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 45, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 54, _startPosY + 71),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //up right wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 42),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 7),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //down right wing
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 70),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 77),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 112),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 70),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _airPlaneWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _airPlaneHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPosX - EntityAirPlane.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPosY - EntityAirPlane.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DirectionType.Right => _startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MovePlane(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
_startPosX -= (int)EntityAirPlane.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
_startPosY -= (int)EntityAirPlane.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
_startPosX += (int)EntityAirPlane.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
_startPosY += (int)EntityAirPlane.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningAirPlane
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectAirPlane(this);
|
||||||
|
}
|
||||||
|
}
|
35
AirBomber/AirBomber/DrawningObjectAirPlane.cs
Normal file
35
AirBomber/AirBomber/DrawningObjectAirPlane.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class DrawningObjectAirPlane : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningAirPlane? _drawningAirPlane = null;
|
||||||
|
public DrawningObjectAirPlane(DrawningAirPlane drawningAirPlane)
|
||||||
|
{
|
||||||
|
_drawningAirPlane = drawningAirPlane;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null || _drawningAirPlane.EntityAirPlane ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningAirPlane.GetPosX,
|
||||||
|
_drawningAirPlane.GetPosY, _drawningAirPlane.GetWidth, _drawningAirPlane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningAirPlane?.EntityAirPlane?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawningAirPlane?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawningAirPlane?.MovePlane(direction);
|
||||||
|
}
|
||||||
|
}
|
61
AirBomber/AirBomber/DrawningPlanesEquatables.cs
Normal file
61
AirBomber/AirBomber/DrawningPlanesEquatables.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class DrawningPlanesEquatables: IEqualityComparer<DrawningAirPlane?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirPlane.Speed != y.EntityAirPlane.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirPlane.Weight != y.EntityAirPlane.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirPlane.BodyColor != y.EntityAirPlane.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawningAirBomber && y is DrawningAirBomber)
|
||||||
|
{
|
||||||
|
EntityAirBomber xAirBomber = (EntityAirBomber)x.EntityAirPlane;
|
||||||
|
EntityAirBomber yAirBomber = (EntityAirBomber)y.EntityAirPlane;
|
||||||
|
|
||||||
|
if (xAirBomber.Bombs != yAirBomber.Bombs)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (xAirBomber.FuelTanks != yAirBomber.FuelTanks)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (xAirBomber.AdditionalColor != yAirBomber.AdditionalColor)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawningAirPlane obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
27
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
27
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class EntityAirBomber : EntityAirPlane
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool Bombs { get; private set; }
|
||||||
|
public Color BombsColor { get; private set; }
|
||||||
|
public bool FuelTanks { get; private set; }
|
||||||
|
public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Bombs = bombs;
|
||||||
|
FuelTanks = fuelTanks;
|
||||||
|
}
|
||||||
|
public void SetAdditionalColor(Color color)
|
||||||
|
{
|
||||||
|
AdditionalColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
AirBomber/AirBomber/EntityAirPlane.cs
Normal file
45
AirBomber/AirBomber/EntityAirPlane.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class EntityAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения самолета
|
||||||
|
/// </summary>
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор с параметрами
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолета</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityAirPlane(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
public void SetBodyColor(Color color)
|
||||||
|
{
|
||||||
|
BodyColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
AirBomber/AirBomber/ExtentionDrawningAirPlane.cs
Normal file
64
AirBomber/AirBomber/ExtentionDrawningAirPlane.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawningAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawningAirPlane? CreateDrawningAirPlane(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawningAirPlane(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawningAirBomber(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]), width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningAirPlane">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawningAirPlane drawningAirPlane, char separatorForObject)
|
||||||
|
{
|
||||||
|
var plane = drawningAirPlane.EntityAirPlane;
|
||||||
|
if (plane == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||||
|
if (plane is not EntityAirBomber airBomber)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
AirBomber/AirBomber/Form1.Designer.cs
generated
39
AirBomber/AirBomber/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
190
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
Normal file
190
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormAirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonCreateAirBomber = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
pictureBoxAirBomber = new PictureBox();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonCreateAirPlane = new Button();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
|
buttonSelectPlane = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCreateAirBomber
|
||||||
|
//
|
||||||
|
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateAirBomber.Location = new Point(29, 447);
|
||||||
|
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
||||||
|
buttonCreateAirBomber.Size = new Size(191, 66);
|
||||||
|
buttonCreateAirBomber.TabIndex = 0;
|
||||||
|
buttonCreateAirBomber.Text = "Создать бомбардировщик";
|
||||||
|
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateAirBomber.Click += buttonCreateAirBomber_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(842, 483);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 1;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(806, 483);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 2;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(878, 483);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 3;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(842, 447);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 4;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxAirBomber
|
||||||
|
//
|
||||||
|
pictureBoxAirBomber.BackColor = SystemColors.Control;
|
||||||
|
pictureBoxAirBomber.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxAirBomber.Location = new Point(0, 0);
|
||||||
|
pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
||||||
|
pictureBoxAirBomber.Size = new Size(986, 540);
|
||||||
|
pictureBoxAirBomber.TabIndex = 5;
|
||||||
|
pictureBoxAirBomber.TabStop = false;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
|
comboBoxStrategy.Location = new Point(755, 26);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(219, 33);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCreateAirPlane
|
||||||
|
//
|
||||||
|
buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateAirPlane.Location = new Point(249, 447);
|
||||||
|
buttonCreateAirPlane.Name = "buttonCreateAirPlane";
|
||||||
|
buttonCreateAirPlane.Size = new Size(191, 65);
|
||||||
|
buttonCreateAirPlane.TabIndex = 7;
|
||||||
|
buttonCreateAirPlane.Text = "Создать самолёт";
|
||||||
|
buttonCreateAirPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateAirPlane.Click += buttonCreateAirPlane_Click;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStrategyStep.Location = new Point(862, 77);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(112, 49);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "Шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectPlane
|
||||||
|
//
|
||||||
|
buttonSelectPlane.Location = new Point(862, 178);
|
||||||
|
buttonSelectPlane.Name = "buttonSelectPlane";
|
||||||
|
buttonSelectPlane.Size = new Size(110, 91);
|
||||||
|
buttonSelectPlane.TabIndex = 9;
|
||||||
|
buttonSelectPlane.Text = "Выбрать самолет";
|
||||||
|
buttonSelectPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectPlane.Click += buttonSelectPlane_Click;
|
||||||
|
//
|
||||||
|
// FormAirBomber
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(986, 540);
|
||||||
|
Controls.Add(buttonSelectPlane);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(buttonCreateAirPlane);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonCreateAirBomber);
|
||||||
|
Controls.Add(pictureBoxAirBomber);
|
||||||
|
Name = "FormAirBomber";
|
||||||
|
Text = "Бомбардировщик";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCreateAirBomber;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonUp;
|
||||||
|
private PictureBox pictureBoxAirBomber;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCreateAirPlane;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
|
private Button buttonSelectPlane;
|
||||||
|
}
|
||||||
|
}
|
142
AirBomber/AirBomber/FormAirBomber.cs
Normal file
142
AirBomber/AirBomber/FormAirBomber.cs
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public partial class FormAirBomber : Form
|
||||||
|
{
|
||||||
|
private DrawningAirPlane? _drawningAirPlane;
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Выбранный самолет
|
||||||
|
/// </summary>
|
||||||
|
public DrawningAirPlane? SelectedPlane { get; private set; }
|
||||||
|
|
||||||
|
public FormAirBomber()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
SelectedPlane = null;
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningAirPlane.DrawPlane(gr);
|
||||||
|
pictureBoxAirBomber.Image = bmp;
|
||||||
|
}
|
||||||
|
private void buttonCreateAirBomber_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
//TODO выбор основного цвета DONE
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
//TODO выбор дополнительного цвета DONE
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
|
||||||
|
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonCreateAirPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
|
||||||
|
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawningAirPlane.MovePlane(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawningAirPlane.MovePlane(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawningAirPlane.MovePlane(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawningAirPlane.MovePlane(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(_drawningAirPlane.GetMoveableObject,
|
||||||
|
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSelectPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedPlane = _drawningAirPlane;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AirBomber/AirBomber/FormAirBomber.resx
Normal file
60
AirBomber/AirBomber/FormAirBomber.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
275
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
Normal file
275
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormPlaneCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
buttonAddPlane = new Button();
|
||||||
|
buttonRemovePlane = new Button();
|
||||||
|
buttonRefreshCollection = new Button();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
groupBoxStorages = new GroupBox();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
buttonDelObject = new Button();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
groupBoxStorages.SuspendLayout();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.BackColor = SystemColors.Control;
|
||||||
|
pictureBoxCollection.Dock = DockStyle.Left;
|
||||||
|
pictureBoxCollection.Location = new Point(0, 33);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(708, 713);
|
||||||
|
pictureBoxCollection.TabIndex = 0;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonAddPlane
|
||||||
|
//
|
||||||
|
buttonAddPlane.Location = new Point(49, 525);
|
||||||
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
|
buttonAddPlane.Size = new Size(209, 44);
|
||||||
|
buttonAddPlane.TabIndex = 0;
|
||||||
|
buttonAddPlane.Text = "Добавить самолет";
|
||||||
|
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddPlane.Click += buttonAddPlane_Click;
|
||||||
|
//
|
||||||
|
// buttonRemovePlane
|
||||||
|
//
|
||||||
|
buttonRemovePlane.Location = new Point(76, 612);
|
||||||
|
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||||
|
buttonRemovePlane.Size = new Size(160, 60);
|
||||||
|
buttonRemovePlane.TabIndex = 1;
|
||||||
|
buttonRemovePlane.Text = "Удалить самолет";
|
||||||
|
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemovePlane.Click += buttonRemovePlane_Click;
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
buttonRefreshCollection.Location = new Point(49, 678);
|
||||||
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
buttonRefreshCollection.Size = new Size(209, 56);
|
||||||
|
buttonRefreshCollection.TabIndex = 2;
|
||||||
|
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(76, 575);
|
||||||
|
maskedTextBoxNumber.Mask = "00";
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(160, 31);
|
||||||
|
maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByType);
|
||||||
|
groupBoxTools.Controls.Add(groupBoxStorages);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||||
|
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||||
|
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBoxTools.Location = new Point(714, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(305, 746);
|
||||||
|
groupBoxTools.TabIndex = 4;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(49, 469);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(209, 48);
|
||||||
|
buttonSortByColor.TabIndex = 6;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(49, 415);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(209, 48);
|
||||||
|
buttonSortByType.TabIndex = 5;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// groupBoxStorages
|
||||||
|
//
|
||||||
|
groupBoxStorages.Controls.Add(textBoxStorageName);
|
||||||
|
groupBoxStorages.Controls.Add(buttonDelObject);
|
||||||
|
groupBoxStorages.Controls.Add(buttonAddObject);
|
||||||
|
groupBoxStorages.Controls.Add(listBoxStorages);
|
||||||
|
groupBoxStorages.Location = new Point(5, 30);
|
||||||
|
groupBoxStorages.Name = "groupBoxStorages";
|
||||||
|
groupBoxStorages.Size = new Size(294, 368);
|
||||||
|
groupBoxStorages.TabIndex = 4;
|
||||||
|
groupBoxStorages.TabStop = false;
|
||||||
|
groupBoxStorages.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(6, 54);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(281, 31);
|
||||||
|
textBoxStorageName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
buttonDelObject.Location = new Point(44, 305);
|
||||||
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
|
buttonDelObject.Size = new Size(209, 34);
|
||||||
|
buttonDelObject.TabIndex = 2;
|
||||||
|
buttonDelObject.Text = "Удалить набор";
|
||||||
|
buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelObject.Click += buttonDelObject_Click;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(44, 106);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(209, 34);
|
||||||
|
buttonAddObject.TabIndex = 1;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += buttonAddObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 25;
|
||||||
|
listBoxStorages.Location = new Point(6, 160);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(281, 129);
|
||||||
|
listBoxStorages.TabIndex = 0;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.ImageScalingSize = new Size(24, 24);
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(1030, 33);
|
||||||
|
menuStrip.TabIndex = 5;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// ToolStripMenuItem
|
||||||
|
//
|
||||||
|
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||||
|
ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||||
|
ToolStripMenuItem.Size = new Size(69, 29);
|
||||||
|
ToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(212, 34);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранение";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
LoadToolStripMenuItem.Size = new Size(212, 34);
|
||||||
|
LoadToolStripMenuItem.Text = "Загрузка";
|
||||||
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// FormPlaneCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1030, 746);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
|
Name = "FormPlaneCollection";
|
||||||
|
Text = "Набор самолетов";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
groupBoxStorages.ResumeLayout(false);
|
||||||
|
groupBoxStorages.PerformLayout();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private Button buttonAddPlane;
|
||||||
|
private Button buttonRemovePlane;
|
||||||
|
private Button buttonRefreshCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private GroupBox groupBoxStorages;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private Button buttonDelObject;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
}
|
||||||
|
}
|
270
AirBomber/AirBomber/FormPlaneCollection.cs
Normal file
270
AirBomber/AirBomber/FormPlaneCollection.cs
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public partial class FormPlaneCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly PlanesGenericStorage _storage;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
public FormPlaneCollection(ILogger<FormPlaneCollection> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var formPlaneConfig = new FormPlaneConfig();
|
||||||
|
// TODO DONE
|
||||||
|
formPlaneConfig.AddEvent(AddPlane);
|
||||||
|
formPlaneConfig.Show();
|
||||||
|
}
|
||||||
|
private void AddPlane(DrawningAirPlane plane)
|
||||||
|
{
|
||||||
|
plane._pictureWidth = pictureBoxCollection.Width;
|
||||||
|
plane._pictureHeight = pictureBoxCollection.Height;
|
||||||
|
|
||||||
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = obj + plane;
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
_logger.LogInformation("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning($"Объект не добавлен в набор {listBoxStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRemovePlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
_logger.LogInformation("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
_logger.LogWarning("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PlaneNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Неверный ввод");
|
||||||
|
_logger.LogWarning("Неверный ввод");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Не все данные заполнены");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||||
|
}
|
||||||
|
private void buttonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string Name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить набор {Name}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(Name);
|
||||||
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Удален набор: {Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation("Сохранение прошло успешно");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Не сохранилось: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Загрузка"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// TODO продумать логику DONE
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошла успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation("Загрузка прошла успешно");
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Не загрузилось: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType());
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по цвету
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor());
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по сравнителю
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
private void ComparePlanes(IComparer<DrawningAirPlane?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
AirBomber/AirBomber/FormPlaneCollection.resx
Normal file
72
AirBomber/AirBomber/FormPlaneCollection.resx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>163, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>357, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>71</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
366
AirBomber/AirBomber/FormPlaneConfig.Designer.cs
generated
Normal file
366
AirBomber/AirBomber/FormPlaneConfig.Designer.cs
generated
Normal file
@ -0,0 +1,366 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormPlaneConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBoxParameters = new GroupBox();
|
||||||
|
labelModifiedObject = new Label();
|
||||||
|
labelSimpleObject = new Label();
|
||||||
|
groupBoxColors = new GroupBox();
|
||||||
|
panelPurple = new Panel();
|
||||||
|
panelBlack = new Panel();
|
||||||
|
panelGray = new Panel();
|
||||||
|
panelWhite = new Panel();
|
||||||
|
panelYellow = new Panel();
|
||||||
|
panelBlue = new Panel();
|
||||||
|
panelGreen = new Panel();
|
||||||
|
panelRed = new Panel();
|
||||||
|
checkBoxFuelTanks = new CheckBox();
|
||||||
|
checkBoxBombs = new CheckBox();
|
||||||
|
numericUpDownWeight = new NumericUpDown();
|
||||||
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
|
labelWeight = new Label();
|
||||||
|
labelSpeed = new Label();
|
||||||
|
pictureBoxObject = new PictureBox();
|
||||||
|
panelObject = new Panel();
|
||||||
|
labelAddColor = new Label();
|
||||||
|
labelColor = new Label();
|
||||||
|
buttonOk = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
groupBoxParameters.SuspendLayout();
|
||||||
|
groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||||
|
panelObject.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxParameters
|
||||||
|
//
|
||||||
|
groupBoxParameters.Controls.Add(labelModifiedObject);
|
||||||
|
groupBoxParameters.Controls.Add(labelSimpleObject);
|
||||||
|
groupBoxParameters.Controls.Add(groupBoxColors);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxFuelTanks);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxBombs);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownWeight);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownSpeed);
|
||||||
|
groupBoxParameters.Controls.Add(labelWeight);
|
||||||
|
groupBoxParameters.Controls.Add(labelSpeed);
|
||||||
|
groupBoxParameters.Location = new Point(12, 12);
|
||||||
|
groupBoxParameters.Name = "groupBoxParameters";
|
||||||
|
groupBoxParameters.Size = new Size(733, 340);
|
||||||
|
groupBoxParameters.TabIndex = 0;
|
||||||
|
groupBoxParameters.TabStop = false;
|
||||||
|
groupBoxParameters.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelModifiedObject.Location = new Point(563, 259);
|
||||||
|
labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
labelModifiedObject.Size = new Size(150, 48);
|
||||||
|
labelModifiedObject.TabIndex = 8;
|
||||||
|
labelModifiedObject.Text = "Продвинутый";
|
||||||
|
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelModifiedObject.MouseDown += labelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleObject.Location = new Point(389, 259);
|
||||||
|
labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
labelSimpleObject.Size = new Size(150, 48);
|
||||||
|
labelSimpleObject.TabIndex = 7;
|
||||||
|
labelSimpleObject.Text = "Простой";
|
||||||
|
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleObject.MouseDown += labelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
groupBoxColors.Controls.Add(panelPurple);
|
||||||
|
groupBoxColors.Controls.Add(panelBlack);
|
||||||
|
groupBoxColors.Controls.Add(panelGray);
|
||||||
|
groupBoxColors.Controls.Add(panelWhite);
|
||||||
|
groupBoxColors.Controls.Add(panelYellow);
|
||||||
|
groupBoxColors.Controls.Add(panelBlue);
|
||||||
|
groupBoxColors.Controls.Add(panelGreen);
|
||||||
|
groupBoxColors.Controls.Add(panelRed);
|
||||||
|
groupBoxColors.Location = new Point(389, 20);
|
||||||
|
groupBoxColors.Name = "groupBoxColors";
|
||||||
|
groupBoxColors.Size = new Size(324, 194);
|
||||||
|
groupBoxColors.TabIndex = 6;
|
||||||
|
groupBoxColors.TabStop = false;
|
||||||
|
groupBoxColors.Text = "Цвета";
|
||||||
|
groupBoxColors.DragDrop += PanelObject_DragDrop;
|
||||||
|
groupBoxColors.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
panelPurple.BackColor = Color.Purple;
|
||||||
|
panelPurple.Location = new Point(243, 113);
|
||||||
|
panelPurple.Name = "panelPurple";
|
||||||
|
panelPurple.Size = new Size(54, 54);
|
||||||
|
panelPurple.TabIndex = 1;
|
||||||
|
panelPurple.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
panelBlack.BackColor = Color.Black;
|
||||||
|
panelBlack.Location = new Point(169, 113);
|
||||||
|
panelBlack.Name = "panelBlack";
|
||||||
|
panelBlack.Size = new Size(54, 54);
|
||||||
|
panelBlack.TabIndex = 1;
|
||||||
|
panelBlack.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
panelGray.BackColor = Color.Gray;
|
||||||
|
panelGray.Location = new Point(96, 113);
|
||||||
|
panelGray.Name = "panelGray";
|
||||||
|
panelGray.Size = new Size(54, 54);
|
||||||
|
panelGray.TabIndex = 1;
|
||||||
|
panelGray.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
panelWhite.BackColor = Color.White;
|
||||||
|
panelWhite.Location = new Point(22, 113);
|
||||||
|
panelWhite.Name = "panelWhite";
|
||||||
|
panelWhite.Size = new Size(54, 54);
|
||||||
|
panelWhite.TabIndex = 1;
|
||||||
|
panelWhite.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
panelYellow.BackColor = Color.Yellow;
|
||||||
|
panelYellow.Location = new Point(243, 43);
|
||||||
|
panelYellow.Name = "panelYellow";
|
||||||
|
panelYellow.Size = new Size(54, 54);
|
||||||
|
panelYellow.TabIndex = 1;
|
||||||
|
panelYellow.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
panelBlue.BackColor = Color.Blue;
|
||||||
|
panelBlue.Location = new Point(169, 43);
|
||||||
|
panelBlue.Name = "panelBlue";
|
||||||
|
panelBlue.Size = new Size(54, 54);
|
||||||
|
panelBlue.TabIndex = 1;
|
||||||
|
panelBlue.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
panelGreen.BackColor = Color.Green;
|
||||||
|
panelGreen.Location = new Point(96, 43);
|
||||||
|
panelGreen.Name = "panelGreen";
|
||||||
|
panelGreen.Size = new Size(54, 54);
|
||||||
|
panelGreen.TabIndex = 1;
|
||||||
|
panelGreen.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
panelRed.BackColor = Color.Red;
|
||||||
|
panelRed.Location = new Point(22, 43);
|
||||||
|
panelRed.Name = "panelRed";
|
||||||
|
panelRed.Size = new Size(54, 54);
|
||||||
|
panelRed.TabIndex = 0;
|
||||||
|
panelRed.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// checkBoxFuelTanks
|
||||||
|
//
|
||||||
|
checkBoxFuelTanks.AutoSize = true;
|
||||||
|
checkBoxFuelTanks.Location = new Point(30, 225);
|
||||||
|
checkBoxFuelTanks.Name = "checkBoxFuelTanks";
|
||||||
|
checkBoxFuelTanks.Size = new Size(327, 29);
|
||||||
|
checkBoxFuelTanks.TabIndex = 5;
|
||||||
|
checkBoxFuelTanks.Text = "Признак наличия топливных баков";
|
||||||
|
checkBoxFuelTanks.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxBombs
|
||||||
|
//
|
||||||
|
checkBoxBombs.AutoSize = true;
|
||||||
|
checkBoxBombs.Location = new Point(30, 158);
|
||||||
|
checkBoxBombs.Name = "checkBoxBombs";
|
||||||
|
checkBoxBombs.Size = new Size(229, 29);
|
||||||
|
checkBoxBombs.TabIndex = 4;
|
||||||
|
checkBoxBombs.Text = "Признак наличия бомб";
|
||||||
|
checkBoxBombs.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
numericUpDownWeight.Location = new Point(146, 94);
|
||||||
|
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
numericUpDownWeight.Size = new Size(180, 31);
|
||||||
|
numericUpDownWeight.TabIndex = 3;
|
||||||
|
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
numericUpDownSpeed.Location = new Point(146, 52);
|
||||||
|
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
numericUpDownSpeed.Size = new Size(180, 31);
|
||||||
|
numericUpDownSpeed.TabIndex = 2;
|
||||||
|
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
labelWeight.AutoSize = true;
|
||||||
|
labelWeight.Location = new Point(30, 100);
|
||||||
|
labelWeight.Name = "labelWeight";
|
||||||
|
labelWeight.Size = new Size(39, 25);
|
||||||
|
labelWeight.TabIndex = 1;
|
||||||
|
labelWeight.Text = "Вес";
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
labelSpeed.AutoSize = true;
|
||||||
|
labelSpeed.Location = new Point(30, 54);
|
||||||
|
labelSpeed.Name = "labelSpeed";
|
||||||
|
labelSpeed.Size = new Size(89, 25);
|
||||||
|
labelSpeed.TabIndex = 0;
|
||||||
|
labelSpeed.Text = "Скорость";
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
pictureBoxObject.Location = new Point(32, 61);
|
||||||
|
pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
pictureBoxObject.Size = new Size(358, 175);
|
||||||
|
pictureBoxObject.TabIndex = 1;
|
||||||
|
pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
panelObject.AllowDrop = true;
|
||||||
|
panelObject.Controls.Add(labelAddColor);
|
||||||
|
panelObject.Controls.Add(labelColor);
|
||||||
|
panelObject.Controls.Add(pictureBoxObject);
|
||||||
|
panelObject.Location = new Point(776, 23);
|
||||||
|
panelObject.Name = "panelObject";
|
||||||
|
panelObject.Size = new Size(418, 253);
|
||||||
|
panelObject.TabIndex = 2;
|
||||||
|
panelObject.DragDrop += PanelObject_DragDrop;
|
||||||
|
panelObject.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// labelAddColor
|
||||||
|
//
|
||||||
|
labelAddColor.AllowDrop = true;
|
||||||
|
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAddColor.Location = new Point(225, 9);
|
||||||
|
labelAddColor.Name = "labelAddColor";
|
||||||
|
labelAddColor.Size = new Size(165, 49);
|
||||||
|
labelAddColor.TabIndex = 3;
|
||||||
|
labelAddColor.Text = "Доп. цвет";
|
||||||
|
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAddColor.DragDrop += labelColor_dragDrop;
|
||||||
|
labelAddColor.DragEnter += labelColor_dragEnter;
|
||||||
|
//
|
||||||
|
// labelColor
|
||||||
|
//
|
||||||
|
labelColor.AllowDrop = true;
|
||||||
|
labelColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelColor.Location = new Point(32, 9);
|
||||||
|
labelColor.Name = "labelColor";
|
||||||
|
labelColor.Size = new Size(165, 49);
|
||||||
|
labelColor.TabIndex = 2;
|
||||||
|
labelColor.Text = "Цвет";
|
||||||
|
labelColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelColor.DragDrop += labelColor_dragDrop;
|
||||||
|
labelColor.DragEnter += labelColor_dragEnter;
|
||||||
|
//
|
||||||
|
// buttonOk
|
||||||
|
//
|
||||||
|
buttonOk.Location = new Point(783, 291);
|
||||||
|
buttonOk.Name = "buttonOk";
|
||||||
|
buttonOk.Size = new Size(190, 51);
|
||||||
|
buttonOk.TabIndex = 3;
|
||||||
|
buttonOk.Text = "Добавить";
|
||||||
|
buttonOk.UseVisualStyleBackColor = true;
|
||||||
|
buttonOk.Click += buttonOk_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(992, 291);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(190, 51);
|
||||||
|
buttonCancel.TabIndex = 4;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormPlaneConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1222, 364);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonOk);
|
||||||
|
Controls.Add(panelObject);
|
||||||
|
Controls.Add(groupBoxParameters);
|
||||||
|
Name = "FormPlaneConfig";
|
||||||
|
Text = "Создание объекта";
|
||||||
|
groupBoxParameters.ResumeLayout(false);
|
||||||
|
groupBoxParameters.PerformLayout();
|
||||||
|
groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||||
|
panelObject.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxParameters;
|
||||||
|
private CheckBox checkBoxFuelTanks;
|
||||||
|
private CheckBox checkBoxBombs;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelWeight;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelRed;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Panel panelObject;
|
||||||
|
private Label labelAddColor;
|
||||||
|
private Label labelColor;
|
||||||
|
private Button buttonOk;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
152
AirBomber/AirBomber/FormPlaneConfig.cs
Normal file
152
AirBomber/AirBomber/FormPlaneConfig.cs
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public partial class FormPlaneConfig : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Переменная-выбранная машина
|
||||||
|
/// </summary>
|
||||||
|
DrawningAirPlane? _plane = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Делегат для передачи объекта-автомобиля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane"></param>
|
||||||
|
private event Action<DrawningAirPlane>? EventAddPlane;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormPlaneConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += panelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += panelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += panelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += panelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += panelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += panelColor_MouseDown;
|
||||||
|
// TODO buttonCancel.Click with lambda DONE
|
||||||
|
buttonCancel.Click += (s, e) => Close();
|
||||||
|
}
|
||||||
|
private void DrawPlane()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_plane?.SetPosition(5, 5);
|
||||||
|
_plane?.DrawPlane(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление события
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ev">Привязанный метод</param>
|
||||||
|
public void AddEvent(Action<DrawningAirPlane> ev)
|
||||||
|
{
|
||||||
|
if (EventAddPlane == null)
|
||||||
|
{
|
||||||
|
EventAddPlane = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddPlane += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Передаем информацию при нажатии на Label
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Действия при приеме перетаскиваемой информации
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_plane = new DrawningAirPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_plane = new DrawningAirBomber((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBombs.Checked, checkBoxFuelTanks.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawPlane();
|
||||||
|
}
|
||||||
|
// TODO Реализовать логику смены цветов DONE
|
||||||
|
public void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
private void labelColor_dragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void labelColor_dragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_plane == null)
|
||||||
|
return;
|
||||||
|
switch (((Label)sender).Name)
|
||||||
|
{
|
||||||
|
case "labelColor":
|
||||||
|
_plane?.EntityAirPlane?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
case "labelAddColor":
|
||||||
|
if (!(_plane is DrawningAirBomber))
|
||||||
|
return;
|
||||||
|
(_plane.EntityAirPlane as EntityAirBomber)?.SetAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawPlane();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonOk_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddPlane?.Invoke(_plane);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AirBomber/AirBomber/FormPlaneConfig.resx
Normal file
60
AirBomber/AirBomber/FormPlaneConfig.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
31
AirBomber/AirBomber/IMoveableObject.cs
Normal file
31
AirBomber/AirBomber/IMoveableObject.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты X объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, можно ли переместиться по нужному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления пермещения объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
||||||
|
}
|
26
AirBomber/AirBomber/MoveToBorder.cs
Normal file
26
AirBomber/AirBomber/MoveToBorder.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return false;
|
||||||
|
|
||||||
|
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return;
|
||||||
|
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
||||||
|
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
AirBomber/AirBomber/MoveToCenter.cs
Normal file
57
AirBomber/AirBomber/MoveToCenter.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
54
AirBomber/AirBomber/ObjectParameters.cs
Normal file
54
AirBomber/AirBomber/ObjectParameters.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
AirBomber/AirBomber/PlaneCollectionInfo.cs
Normal file
33
AirBomber/AirBomber/PlaneCollectionInfo.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class PlaneCollectionInfo: IEquatable<PlaneCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public PlaneCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(PlaneCollectionInfo other)
|
||||||
|
{
|
||||||
|
if (Name != other?.Name)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
AirBomber/AirBomber/PlaneCompareByColor.cs
Normal file
56
AirBomber/AirBomber/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class PlaneCompareByColor: IComparer<DrawningAirPlane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
var bodyColorCompare = x.EntityAirPlane.BodyColor.Name.CompareTo(y.EntityAirPlane.BodyColor.Name);
|
||||||
|
|
||||||
|
if (bodyColorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodyColorCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityAirPlane is EntityAirBomber xEntitySailCatamaran && y.EntityAirPlane is EntityAirBomber yEntitySailCatamaran)
|
||||||
|
{
|
||||||
|
var BodyColorCompare = xEntitySailCatamaran.BodyColor.Name.CompareTo(yEntitySailCatamaran.BodyColor.Name);
|
||||||
|
if (BodyColorCompare != 0)
|
||||||
|
{
|
||||||
|
return BodyColorCompare;
|
||||||
|
}
|
||||||
|
var AdditionalColorCompare = xEntitySailCatamaran.AdditionalColor.Name.CompareTo(yEntitySailCatamaran.AdditionalColor.Name);
|
||||||
|
if (AdditionalColorCompare != 0)
|
||||||
|
{
|
||||||
|
return AdditionalColorCompare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
AirBomber/AirBomber/PlaneCompareByType.cs
Normal file
39
AirBomber/AirBomber/PlaneCompareByType.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class PlaneCompareByType: IComparer<DrawningAirPlane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
AirBomber/AirBomber/PlaneNotFoundException.cs
Normal file
20
AirBomber/AirBomber/PlaneNotFoundException.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class PlaneNotFoundException: ApplicationException
|
||||||
|
{
|
||||||
|
public PlaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public PlaneNotFoundException() : base() { }
|
||||||
|
public PlaneNotFoundException(string message) : base(message) { }
|
||||||
|
public PlaneNotFoundException(string message, Exception exception) : base(message, exception)
|
||||||
|
{ }
|
||||||
|
protected PlaneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
146
AirBomber/AirBomber/PlanesGenericCollection.cs
Normal file
146
AirBomber/AirBomber/PlanesGenericCollection.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class PlanesGenericCollection<T, U>
|
||||||
|
where T : DrawningAirPlane
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 170;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 120;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(PlanesGenericCollection<T, U> collect, T obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj, new DrawningPlanesEquatables());
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static T? operator -(PlanesGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowPlanes()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
//линия рамзетки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int widthObjCount = _pictureWidth / _placeSizeWidth;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
T? type = _collection[i];
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
int row = i / widthObjCount;
|
||||||
|
int col = widthObjCount - 1 - (i % widthObjCount);
|
||||||
|
|
||||||
|
type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
|
||||||
|
type?.DrawPlane(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||||
|
}
|
||||||
|
}
|
198
AirBomber/AirBomber/PlanesGenericStorage.cs
Normal file
198
AirBomber/AirBomber/PlanesGenericStorage.cs
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
using AirBomber.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class PlanesGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>> _planeStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<PlaneCollectionInfo> Keys => _planeStorages.Keys.ToList();
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_planeStorages = new Dictionary<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления DONE
|
||||||
|
if(!_planeStorages.ContainsKey(new PlaneCollectionInfo(name, string.Empty)))
|
||||||
|
{
|
||||||
|
_planeStorages.Add(new PlaneCollectionInfo(name, string.Empty),
|
||||||
|
new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления DONE
|
||||||
|
if (!_planeStorages.ContainsKey(new PlaneCollectionInfo(name, string.Empty)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_planeStorages.Remove(new PlaneCollectionInfo(name, string.Empty));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора DONE
|
||||||
|
if (_planeStorages.ContainsKey(new PlaneCollectionInfo(ind, string.Empty)))
|
||||||
|
{
|
||||||
|
return _planeStorages[new PlaneCollectionInfo(ind, string.Empty)];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по самолетам в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>record in _planeStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawningAirPlane? elem in record.Value.GetPlanes)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Невалидная операция, нет данных для сохранения");
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamWriter sw = new(filename);
|
||||||
|
sw.Write($"PlaneStorage{Environment.NewLine}{data}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по самолетам в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
}
|
||||||
|
using (StreamReader sr = new(filename))
|
||||||
|
{
|
||||||
|
string str = sr.ReadLine();
|
||||||
|
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
if (!str.StartsWith("PlaneStorage"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new InvalidDataException("Неверный формат данных");
|
||||||
|
}
|
||||||
|
|
||||||
|
_planeStorages.Clear();
|
||||||
|
string strs = "";
|
||||||
|
|
||||||
|
while ((strs = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (strs == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawningAirPlane? plane = elem?.CreateDrawningAirPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
if ((collection + plane) == -1)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = collection + plane;
|
||||||
|
}
|
||||||
|
catch (PlaneNotFoundException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_planeStorages.Add(new PlaneCollectionInfo(record[0], string.Empty), collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,9 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using AirBomber;
|
||||||
|
|
||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +17,29 @@ namespace AirBomber
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormPlaneCollection>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormPlaneCollection>().AddLogging(option =>
|
||||||
|
{
|
||||||
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appSettings.json", optional: false, reloadOnChange: true).Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||||
|
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
103
AirBomber/AirBomber/Properties/Resources.Designer.cs
generated
Normal file
103
AirBomber/AirBomber/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace AirBomber.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AirBomber.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowDown {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowLeft {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowRight {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowUp {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -117,4 +117,17 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
BIN
AirBomber/AirBomber/Resources/arrowDown.png
Normal file
BIN
AirBomber/AirBomber/Resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
AirBomber/AirBomber/Resources/arrowLeft.png
Normal file
BIN
AirBomber/AirBomber/Resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
AirBomber/AirBomber/Resources/arrowRight.png
Normal file
BIN
AirBomber/AirBomber/Resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
AirBomber/AirBomber/Resources/arrowUp.png
Normal file
BIN
AirBomber/AirBomber/Resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
136
AirBomber/AirBomber/SetGeneric.cs
Normal file
136
AirBomber/AirBomber/SetGeneric.cs
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Count;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">Добавляемый самолет</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T plane, IEqualityComparer<T?>? equal = null)
|
||||||
|
{
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
foreach (var secondLoco in _places)
|
||||||
|
{
|
||||||
|
if (equal.Equals(plane, secondLoco))
|
||||||
|
{
|
||||||
|
throw new Exception("Такой объект уже есть в коллекции");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Insert(plane, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">Добавляемый самолет</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
|
||||||
|
{
|
||||||
|
if (_places.Count >= _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
if (_places.Contains(plane, equal))
|
||||||
|
throw new ArgumentException(("Такой объект уже есть в коллекции"));
|
||||||
|
}
|
||||||
|
_places.Insert(position, plane);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
throw new PlaneNotFoundException("Невалидная операция");
|
||||||
|
if (_places[position] == null)
|
||||||
|
throw new PlaneNotFoundException(position);
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO проверка позиции DONE
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
AirBomber/AirBomber/Status.cs
Normal file
15
AirBomber/AirBomber/Status.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
19
AirBomber/AirBomber/StorageOverflowException.cs
Normal file
19
AirBomber/AirBomber/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class StorageOverflowException: ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { }
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
|
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user