Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 84e4affbde | |||
| e971b264e6 | |||
| 93274b9a00 | |||
| ef1bec9f3c | |||
| 6ead7f2b69 | |||
| 5e46d4770d | |||
| 1dc111bb61 | |||
| c61f10fa34 | |||
| ed6631e1ea | |||
| 763e829619 | |||
| 08ef0b42bd | |||
| 6ee94b8ce5 | |||
| 712a7c6802 | |||
| e521690132 | |||
| 73b879b9c6 | |||
| 1c816e6597 | |||
| 6676432892 | |||
| f746d687c9 |
@@ -2,12 +2,21 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32901.215
|
VisualStudioVersion = 17.3.32901.215
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AirBomber", "AirBomber.csproj", "{4E086563-17EB-404C-9522-520DE8724E73}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AirBomber", "AirBomber.csproj", "{4E086563-17EB-404C-9522-520DE8724E73}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
128
AirBomber/CollectionGenericObjects/AbstractCompany.cs
Normal file
128
AirBomber/CollectionGenericObjects/AbstractCompany.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber.Drawnings;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Абстракция компании, хранящий коллекцию самолетов
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 210;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 150;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция лодок
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObjects<DrawningAirPlane>? _collection = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||||
|
/// </summary>
|
||||||
|
private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth">Ширина окна</param>
|
||||||
|
/// <param name="picHeight">Высота окна</param>
|
||||||
|
/// <param name="collection">Коллекция лодок</param>
|
||||||
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirPlane> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.MaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="boat">Добавляемый объект</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(AbstractCompany company, DrawningAirPlane airPlane)
|
||||||
|
{
|
||||||
|
return company._collection?.Insert(airPlane, new DrawningAirPlaneEqutables()) ?? -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора удаления для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawningAirPlane operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection?.Remove(position) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение случайного объекта из коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DrawningAirPlane? GetRandomObject()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всей коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap? Show()
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
DrawBackground(graphics);
|
||||||
|
|
||||||
|
SetObjectsPosition();
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DrawningAirPlane? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод заднего фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
protected abstract void DrawBackground(Graphics g);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстановка объектов
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
|
||||||
|
public void Sort(IComparer<DrawningAirPlane?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
|
}
|
||||||
79
AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs
Normal file
79
AirBomber/CollectionGenericObjects/AirPlaneSharingService.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber.Drawnings;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class AirPlaneSharingService : AbstractCompany
|
||||||
|
{
|
||||||
|
private List<Tuple<int, int>> locCoord = new List<Tuple<int, int>>();
|
||||||
|
private int numRows, numCols;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public AirPlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirPlane> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Color backgroundColor = Color.Gray;
|
||||||
|
using (Brush brush = new SolidBrush(backgroundColor))
|
||||||
|
{
|
||||||
|
g.FillRectangle(brush, new Rectangle(0, 0, _pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
Pen pen = new Pen(Color.Brown, 3);
|
||||||
|
int offsetX = 10, offsetY = -12;
|
||||||
|
int x = _pictureWidth - _placeSizeWidth, y = offsetY;
|
||||||
|
numRows = 0;
|
||||||
|
|
||||||
|
int adjustedHeight = _pictureHeight - (_placeSizeHeight + 5 + offsetY);
|
||||||
|
while (y + _placeSizeHeight <= adjustedHeight)
|
||||||
|
{
|
||||||
|
int numCols = 0;
|
||||||
|
int initialX = x;
|
||||||
|
while (x >= 0)
|
||||||
|
{
|
||||||
|
numCols++;
|
||||||
|
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
|
||||||
|
g.DrawLine(pen, x, y, x, y + _placeSizeHeight + 4);
|
||||||
|
locCoord.Add(new Tuple<int, int>(x, y));
|
||||||
|
x -= _placeSizeWidth + 2;
|
||||||
|
}
|
||||||
|
numRows++;
|
||||||
|
x = initialX;
|
||||||
|
y += _placeSizeHeight + 5 + offsetY;
|
||||||
|
}
|
||||||
|
numCols = numCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
if (locCoord == null || _collection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int row = numRows - 1, col = numCols;
|
||||||
|
for (int i = 0; i < _collection?.Count; i++, col--)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(i)?.SetPosition(locCoord[row * numCols - col].Item1 + 5, locCoord[row * numCols - col].Item2 + 9);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
if (col == 1)
|
||||||
|
{
|
||||||
|
col = numCols + 1;
|
||||||
|
row--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
AirBomber/CollectionGenericObjects/CollectionInfo.cs
Normal file
45
AirBomber/CollectionGenericObjects/CollectionInfo.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using AirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public CollectionType CollectionType { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
private static readonly string _separator = "-";
|
||||||
|
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
CollectionType = collectionType;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public static CollectionInfo? GetCollectionInfo(string data)
|
||||||
|
{
|
||||||
|
string[] strs = data.Split(_separator,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (strs.Length < 1 || strs.Length > 3)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new CollectionInfo(strs[0],
|
||||||
|
(CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ?
|
||||||
|
strs[2] : string.Empty);
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name + _separator + CollectionType + _separator + Description;
|
||||||
|
}
|
||||||
|
public bool Equals(CollectionInfo? other)
|
||||||
|
{
|
||||||
|
return Name == other?.Name;
|
||||||
|
}
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
return Equals(obj as CollectionInfo);
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
AirBomber/CollectionGenericObjects/CollectionType.cs
Normal file
25
AirBomber/CollectionGenericObjects/CollectionType.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неопределено
|
||||||
|
/// </summary>
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Массив
|
||||||
|
/// </summary>
|
||||||
|
Massive = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список
|
||||||
|
/// </summary>
|
||||||
|
List = 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using AirBomber.CollectionGenericObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBomber.Drawnings;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в коллекции
|
||||||
|
/// </summary>
|
||||||
|
int Count { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка максимального количества элементов
|
||||||
|
/// </summary>
|
||||||
|
int MaxCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
|
T Remove(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение типа коллекции
|
||||||
|
/// </summary>
|
||||||
|
CollectionType GetCollectionType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поэлементный вывод элементов коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerable<T?> GetItems();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
|
}
|
||||||
102
AirBomber/CollectionGenericObjects/ListGenericObjects.cs
Normal file
102
AirBomber/CollectionGenericObjects/ListGenericObjects.cs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
using AirBomber.Drawnings;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр </typeparam>
|
||||||
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T?> _collection;
|
||||||
|
private int _maxCount;
|
||||||
|
public int Count => _collection.Count;
|
||||||
|
|
||||||
|
public int MaxCount
|
||||||
|
{
|
||||||
|
get => _maxCount;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
_maxCount = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.List;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public ListGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||||
|
_collection.Add(obj);
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
throw new PositionOutOfCollectionException(position);
|
||||||
|
|
||||||
|
if (Count == _maxCount)
|
||||||
|
throw new CollectionOverflowException(Count);
|
||||||
|
_collection.Insert(position, obj);
|
||||||
|
return position;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
T obj = _collection[position];
|
||||||
|
_collection.RemoveAt(position);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
|
}
|
||||||
144
AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs
Normal file
144
AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
using AirBomber.Drawnings;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private T?[] _collection;
|
||||||
|
|
||||||
|
public int Count => _collection.Length;
|
||||||
|
|
||||||
|
public int MaxCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _collection.Length;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
if (_collection.Length > 0)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _collection, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_collection = new T?[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public MassiveGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = Array.Empty<T?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, IEqualityComparer<T?> comparer = null)
|
||||||
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
foreach (T? item in _collection)
|
||||||
|
{
|
||||||
|
if ((comparer as IEqualityComparer<DrawningAirPlane>).Equals(obj as DrawningAirPlane, item as DrawningAirPlane))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new CollectionOverflowException(Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
|
{
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
foreach (T? item in _collection)
|
||||||
|
{
|
||||||
|
if ((comparer as IEqualityComparer<DrawningAirPlane>).Equals(obj as DrawningAirPlane, item as DrawningAirPlane))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
throw new PositionOutOfCollectionException(position);
|
||||||
|
}
|
||||||
|
if (_collection[position] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = position - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new CollectionOverflowException(Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
throw new PositionOutOfCollectionException(position);
|
||||||
|
}
|
||||||
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
|
T obj = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
Array.Sort(_collection, comparer);
|
||||||
|
}
|
||||||
|
}
|
||||||
224
AirBomber/CollectionGenericObjects/StorageCollection.cs
Normal file
224
AirBomber/CollectionGenericObjects/StorageCollection.cs
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
using AirBomber.Drawnings;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class StorageCollection<T>
|
||||||
|
where T : DrawningAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с коллекциями
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий коллекций
|
||||||
|
/// </summary>
|
||||||
|
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ключевое слово, с которого должен начинаться файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _collectionKey = "CollectionsStorage";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorForKeyValue = "|";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorItems = ";";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public StorageCollection()
|
||||||
|
{
|
||||||
|
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление коллекции в хранилище
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
|
{
|
||||||
|
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (collectionType)
|
||||||
|
{
|
||||||
|
case CollectionType.Massive:
|
||||||
|
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||||
|
break;
|
||||||
|
case CollectionType.List:
|
||||||
|
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
public void DelCollection(string name)
|
||||||
|
{
|
||||||
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
{
|
||||||
|
_storages.Remove(collectionInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
return _storages[collectionInfo];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public void SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (_storages.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("В хранилище отсутствуют коллекции для сохранения");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new();
|
||||||
|
|
||||||
|
using (StreamWriter sw = new StreamWriter(filename))
|
||||||
|
{
|
||||||
|
sw.WriteLine(_collectionKey.ToString());
|
||||||
|
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> kvpair in _storages)
|
||||||
|
{
|
||||||
|
// не сохраняем пустые коллекции
|
||||||
|
if (kvpair.Value.Count == 0)
|
||||||
|
continue;
|
||||||
|
sb.Append(kvpair.Key);
|
||||||
|
sb.Append(_separatorForKeyValue);
|
||||||
|
sb.Append(kvpair.Value.MaxCount);
|
||||||
|
sb.Append(_separatorForKeyValue);
|
||||||
|
foreach (T? item in kvpair.Value.GetItems())
|
||||||
|
{
|
||||||
|
string data = item?.GetDataForSave() ?? string.Empty;
|
||||||
|
if (string.IsNullOrEmpty(data))
|
||||||
|
continue;
|
||||||
|
sb.Append(data);
|
||||||
|
sb.Append(_separatorItems);
|
||||||
|
}
|
||||||
|
sw.WriteLine(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public void LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new Exception("Файл не существует");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader sr = new StreamReader(filename))
|
||||||
|
{
|
||||||
|
string? str;
|
||||||
|
str = sr.ReadLine();
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
throw new Exception("В файле нет данных");
|
||||||
|
if (!str.StartsWith(_collectionKey))
|
||||||
|
throw new Exception("В файле неверные данные");
|
||||||
|
_storages.Clear();
|
||||||
|
string strs = "";
|
||||||
|
while ((strs = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 3)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||||
|
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||||
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||||
|
throw new Exception("Не удалось создать коллекцию");
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Не удалось создать коллекцию");
|
||||||
|
}
|
||||||
|
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||||
|
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
if (elem?.CreateDrawningAirPlane() is T boat)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (collection.Insert(boat) == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CollectionOverflowException ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Коллекция переполнена", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_storages.Add(collectionInfo, collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание коллекции по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collectionType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||||
|
{
|
||||||
|
return collectionType switch
|
||||||
|
{
|
||||||
|
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
||||||
|
CollectionType.List => new ListGenericObjects<T>(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
namespace AirBomber;
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неизвестная направление
|
||||||
|
/// </summary>
|
||||||
|
Unknow = -1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,7 +24,7 @@ public enum DirectionType
|
|||||||
/// Влево
|
/// Влево
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вправо
|
/// Вправо
|
||||||
/// </summary>
|
/// </summary>
|
||||||
106
AirBomber/Drawnings/DrawningAirBomber.cs
Normal file
106
AirBomber/Drawnings/DrawningAirBomber.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using AirBomber.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за отрисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
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>
|
||||||
|
public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks) : base(140, 128)
|
||||||
|
{
|
||||||
|
EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор через сущность
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityAirPlane"></param>
|
||||||
|
public DrawningAirBomber(EntityAirPlane entityAirPlane) : base()
|
||||||
|
{
|
||||||
|
EntityAirPlane = entityAirPlane;
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAirPlane == null || EntityAirPlane is not EntityAirBomber airbomber || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка границ поля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width"><Ширина/param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new
|
||||||
|
SolidBrush(airbomber.AdditionalColor);
|
||||||
|
|
||||||
|
if (airbomber.FuelTanks)
|
||||||
|
{
|
||||||
|
//Дополнительные топливные баки
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29);
|
||||||
|
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Brush brGreen = new SolidBrush(Color.Green);
|
||||||
|
Brush brRed = new SolidBrush(Color.Red);
|
||||||
|
Brush BodyBrush = new SolidBrush(airbomber.BodyColor);
|
||||||
|
|
||||||
|
|
||||||
|
//Бомбы
|
||||||
|
if (airbomber.Bombs)
|
||||||
|
{
|
||||||
|
Point[] Bomb1Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 125), new Point(_startPosX.Value + 84, _startPosY.Value + 128), new Point(_startPosX.Value + 84, _startPosY.Value + 120), new Point(_startPosX.Value + 79, _startPosY.Value + 122) };
|
||||||
|
g.FillPolygon(brGreen, Bomb1Point);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 125, _startPosX.Value + 84, _startPosY.Value + 128);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 128, _startPosX.Value + 84, _startPosY.Value + 120);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 120, _startPosX.Value + 79, _startPosY.Value + 122);
|
||||||
|
g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5);
|
||||||
|
Point[] BombNose1Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 119), new Point(_startPosX.Value + 60, _startPosY.Value + 123), new Point(_startPosX.Value + 65, _startPosY.Value + 128) };
|
||||||
|
g.FillPolygon(brRed, BombNose1Point);
|
||||||
|
|
||||||
|
Point[] Bomb2Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 3), new Point(_startPosX.Value + 84, _startPosY.Value), new Point(_startPosX.Value + 84, _startPosY.Value + 8), new Point(_startPosX.Value + 79, _startPosY.Value + 6) };
|
||||||
|
g.FillPolygon(brGreen, Bomb2Point);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 3, _startPosX.Value + 84, _startPosY.Value);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value, _startPosX.Value + 84, _startPosY.Value + 8);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 8, _startPosX.Value + 79, _startPosY.Value + 6);
|
||||||
|
g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5);
|
||||||
|
Point[] BombNose2Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 9), new Point(_startPosX.Value + 60, _startPosY.Value + 5), new Point(_startPosX.Value + 65, _startPosY.Value) };
|
||||||
|
g.FillPolygon(brRed, BombNose2Point);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +1,111 @@
|
|||||||
using System;
|
using AirBomber.Entities;
|
||||||
|
using AirBomber.Drawnings;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AirBomber;
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
public class DrawningAirPlane
|
||||||
/// Класс, отвечающий за отрисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningAirBomber
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
public EntityAirPlane? EntityAirPlane { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth;
|
private int? _pictureWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight;
|
private int? _pictureHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки бомбардировщика
|
/// Левая координата отрисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? _startPosX;
|
public int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя координата отрисовки бомбардировщика
|
/// Верхняя координата отрисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
public int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки бомбардировщика
|
/// Ширина отрисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningAirBomberWidth = 140;
|
private readonly int _drawningAirPlaneWidth = 140;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки бомбардировщика
|
/// Высота отрисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningAirBomberHeight = 128;
|
private readonly int _drawningAirPlaneHeight = 128;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Координата X объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
public int? GetPosX => _startPosX;
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <summary>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// Координата Y объекта
|
||||||
/// <param name="bombs">Признак наличия бомб</param>
|
/// </summary>
|
||||||
/// <param name="fuelTanks">Признак наличия дополнительный топливных баков</param>
|
public int? GetPosY => _startPosY;
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks)
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _drawningAirPlaneWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _drawningAirPlaneHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
protected DrawningAirPlane()
|
||||||
{
|
{
|
||||||
EntityAirBomber = new EntityAirBomber();
|
|
||||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
|
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public DrawningAirPlane(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningAirBomberWidth">Ширина прорисовки самолета</param>
|
||||||
|
/// <param name="drawningAirBomberWidth">Высота прорисовки самолета</param>
|
||||||
|
public DrawningAirPlane(int drawningAirBomberWidth, int drawningAirBomberHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningAirPlaneHeight = drawningAirBomberHeight;
|
||||||
|
_drawningAirPlaneWidth = drawningAirBomberWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор через сущность
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityAirPlane"></param>
|
||||||
|
public DrawningAirPlane(EntityAirPlane entityAirPlane) : base()
|
||||||
|
{
|
||||||
|
EntityAirPlane = entityAirPlane;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
@@ -68,19 +115,19 @@ public class DrawningAirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
if (_drawningAirBomberHeight > height || _drawningAirBomberWidth > width)
|
if (_drawningAirPlaneHeight > height || _drawningAirPlaneWidth > width)
|
||||||
return false;
|
return false;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
|
|
||||||
if (_startPosX.HasValue || _startPosY.HasValue)
|
if (_startPosX.HasValue || _startPosY.HasValue)
|
||||||
{
|
{
|
||||||
if (_startPosX + _drawningAirBomberWidth > _pictureWidth)
|
if (_startPosX + _drawningAirPlaneWidth > _pictureWidth)
|
||||||
_startPosX = _pictureWidth - _drawningAirBomberWidth;
|
_startPosX = _pictureWidth - _drawningAirPlaneWidth;
|
||||||
else if (_startPosX < 0)
|
else if (_startPosX < 0)
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
if (_startPosY + _drawningAirBomberHeight > _pictureHeight)
|
if (_startPosY + _drawningAirPlaneHeight > _pictureHeight)
|
||||||
_startPosY = _pictureHeight - _drawningAirBomberHeight;
|
_startPosY = _pictureHeight - _drawningAirPlaneHeight;
|
||||||
else if (_startPosY < 0)
|
else if (_startPosY < 0)
|
||||||
_startPosY = 0;
|
_startPosY = 0;
|
||||||
}
|
}
|
||||||
@@ -98,19 +145,19 @@ public class DrawningAirBomber
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (x + _drawningAirBomberWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirBomberWidth;
|
if (x + _drawningAirPlaneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirPlaneWidth;
|
||||||
else if (x < 0) _startPosX = 0;
|
else if (x < 0) _startPosX = 0;
|
||||||
else _startPosX = x;
|
else _startPosX = x;
|
||||||
|
|
||||||
if (y + _drawningAirBomberHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirBomberHeight;
|
if (y + _drawningAirPlaneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirPlaneHeight;
|
||||||
else if (y < 0) _startPosY = 0;
|
else if (y < 0) _startPosY = 0;
|
||||||
else _startPosY = y;
|
else _startPosY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool MoveAirBomber(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -119,30 +166,30 @@ public class DrawningAirBomber
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityAirBomber.Step > 0)
|
if (_startPosX.Value - EntityAirPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityAirBomber.Step;
|
_startPosX -= (int)EntityAirPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityAirBomber.Step > 0)
|
if (_startPosY.Value - EntityAirPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityAirBomber.Step;
|
_startPosY -= (int)EntityAirPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вправо
|
//вправо
|
||||||
case DirectionType.Right :
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityAirBomber.Step + _drawningAirBomberWidth < _pictureWidth)
|
if (_startPosX.Value + EntityAirPlane.Step + _drawningAirPlaneWidth < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityAirBomber.Step;
|
_startPosX += (int)EntityAirPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY + EntityAirBomber.Step + _drawningAirBomberHeight < _pictureHeight)
|
if (_startPosY + EntityAirPlane.Step + _drawningAirPlaneHeight < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityAirBomber.Step;
|
_startPosY += (int)EntityAirPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@@ -156,56 +203,14 @@ public class DrawningAirBomber
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawAirBomber(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new
|
Brush BodyBrush = new SolidBrush(EntityAirPlane.BodyColor);
|
||||||
SolidBrush(EntityAirBomber.AdditionalColor);
|
|
||||||
|
|
||||||
if (EntityAirBomber.FuelTanks)
|
|
||||||
{
|
|
||||||
//Дополнительные топливные баки
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29);
|
|
||||||
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Brush brGreen = new SolidBrush(Color.Green);
|
|
||||||
Brush brRed = new SolidBrush(Color.Red);
|
|
||||||
Brush BodyBrush = new SolidBrush(EntityAirBomber.BodyColor);
|
|
||||||
|
|
||||||
|
|
||||||
//Бомбы
|
|
||||||
if (EntityAirBomber.Bombs)
|
|
||||||
{
|
|
||||||
Point[] Bomb1Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 125), new Point(_startPosX.Value + 84, _startPosY.Value + 128), new Point(_startPosX.Value + 84, _startPosY.Value + 120), new Point(_startPosX.Value + 79, _startPosY.Value + 122) };
|
|
||||||
g.FillPolygon(brGreen, Bomb1Point);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 125, _startPosX.Value + 84, _startPosY.Value + 128);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 128, _startPosX.Value + 84, _startPosY.Value + 120);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 120, _startPosX.Value + 79, _startPosY.Value + 122);
|
|
||||||
g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5);
|
|
||||||
Point[] BombNose1Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 119), new Point(_startPosX.Value + 60, _startPosY.Value + 123), new Point(_startPosX.Value + 65, _startPosY.Value + 128) };
|
|
||||||
g.FillPolygon(brRed, BombNose1Point);
|
|
||||||
|
|
||||||
Point[] Bomb2Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 3), new Point(_startPosX.Value + 84, _startPosY.Value), new Point(_startPosX.Value + 84, _startPosY.Value + 8), new Point(_startPosX.Value + 79, _startPosY.Value + 6) };
|
|
||||||
g.FillPolygon(brGreen, Bomb2Point);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 3, _startPosX.Value + 84, _startPosY.Value);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value, _startPosX.Value + 84, _startPosY.Value + 8);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 8, _startPosX.Value + 79, _startPosY.Value + 6);
|
|
||||||
g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5);
|
|
||||||
Point[] BombNose2Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 9), new Point(_startPosX.Value + 60, _startPosY.Value + 5), new Point(_startPosX.Value + 65, _startPosY.Value) };
|
|
||||||
g.FillPolygon(brRed, BombNose2Point);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Корпус
|
//Корпус
|
||||||
Brush brGray = new SolidBrush(Color.Gray);
|
Brush brGray = new SolidBrush(Color.Gray);
|
||||||
@@ -250,4 +255,3 @@ public class DrawningAirBomber
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
28
AirBomber/Drawnings/DrawningAirPlaneCompareByColor.cs
Normal file
28
AirBomber/Drawnings/DrawningAirPlaneCompareByColor.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
|
public class DrawningBoatCompareByColor : IComparer<DrawningAirPlane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var bodycolorCompare = x.EntityAirPlane.BodyColor.Name.CompareTo(y.EntityAirPlane.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodycolorCompare;
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
AirBomber/Drawnings/DrawningAirPlaneCompareByType.cs
Normal file
29
AirBomber/Drawnings/DrawningAirPlaneCompareByType.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
|
public class DrawningAirPlaneCompareByType : IComparer<DrawningAirPlane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
62
AirBomber/Drawnings/DrawningAirPlaneEqutables.cs
Normal file
62
AirBomber/Drawnings/DrawningAirPlaneEqutables.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using AirBomber.Entities;
|
||||||
|
|
||||||
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
|
public class DrawningAirPlaneEqutables : IEqualityComparer<DrawningAirPlane>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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 _x = (EntityAirBomber)x.EntityAirPlane;
|
||||||
|
EntityAirBomber _y = (EntityAirBomber)x.EntityAirPlane;
|
||||||
|
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.Bombs != _y.Bombs)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.FuelTanks != _y.FuelTanks)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawningAirPlane obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
56
AirBomber/Drawnings/ExtentionDrawningAirPlane.cs
Normal file
56
AirBomber/Drawnings/ExtentionDrawningAirPlane.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.Entities;
|
||||||
|
|
||||||
|
namespace AirBomber.Drawnings;
|
||||||
|
|
||||||
|
public static class ExtentionDrawningAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly string _separatorForObject = ":";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawningAirPlane? CreateDrawningAirPlane(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
EntityAirPlane? airPlane = EntityAirBomber.CreateEntityAirBomber(strs);
|
||||||
|
if (airPlane != null)
|
||||||
|
{
|
||||||
|
return new DrawningAirBomber(airPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
airPlane = EntityAirPlane.CreateEntityAirPlane(strs);
|
||||||
|
if (airPlane != null)
|
||||||
|
{
|
||||||
|
return new DrawningAirPlane(airPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningAirPlane">Сохраняемый объект</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawningAirPlane drawningAirPlane)
|
||||||
|
{
|
||||||
|
string[]? array = drawningAirPlane?.EntityAirPlane?.GetStringRepresentation();
|
||||||
|
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(_separatorForObject, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
AirBomber/Entities/EntityAirBomber.cs
Normal file
55
AirBomber/Entities/EntityAirBomber.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Entities;
|
||||||
|
|
||||||
|
public class EntityAirBomber : EntityAirPlane
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
public void SetAdditionalColor(Color color) => AdditionalColor = color;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия бомб
|
||||||
|
/// </summary>
|
||||||
|
public bool Bombs { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия дополнительных топливных баков
|
||||||
|
/// </summary>
|
||||||
|
public bool FuelTanks { get; private set; }
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
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 override string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityAirBomber), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Bombs.ToString(), FuelTanks.ToString() };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityAirBomber? CreateEntityAirBomber(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 7 || strs[0] != nameof(EntityAirBomber))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EntityAirBomber(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]),
|
||||||
|
Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||||
|
}
|
||||||
|
}
|
||||||
69
AirBomber/Entities/EntityAirPlane.cs
Normal file
69
AirBomber/Entities/EntityAirPlane.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Самолет"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityAirPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
|
public void SetBodyColor(Color color) => BodyColor = color;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public double Step => 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение строк со значениями свойств объекта класса-сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityAirPlane), Speed.ToString(), Weight.ToString(), BodyColor.Name };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из массива строк
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static EntityAirPlane? CreateEntityAirPlane(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 4 || strs[0] != nameof(EntityAirPlane))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EntityAirPlane(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public class EntityAirBomber
|
|
||||||
{
|
|
||||||
/// <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 Color AdditionalColor { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличия бомб
|
|
||||||
/// </summary>
|
|
||||||
public bool Bombs { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличия дополнительных топливных баков
|
|
||||||
/// </summary>
|
|
||||||
public bool FuelTanks { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Bombs = bombs;
|
|
||||||
FuelTanks = fuelTanks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
AirBomber/Exceptions/CollectionOverflowException.cs
Normal file
17
AirBomber/Exceptions/CollectionOverflowException.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку переполнения коллекции
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
internal class CollectionOverflowException : ApplicationException
|
||||||
|
{
|
||||||
|
public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
|
||||||
|
public CollectionOverflowException() : base() { }
|
||||||
|
public CollectionOverflowException(string message) : base(message) { }
|
||||||
|
public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
|
||||||
21
AirBomber/Exceptions/ObjectIsEqualException.cs
Normal file
21
AirBomber/Exceptions/ObjectIsEqualException.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку переполнения коллекции
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class ObjectIsEqualException : ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectIsEqualException(int count) : base("В коллекции содержится равный элемент: " + count) { }
|
||||||
|
public ObjectIsEqualException() : base() { }
|
||||||
|
public ObjectIsEqualException(string message) : base(message) { }
|
||||||
|
public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
16
AirBomber/Exceptions/ObjectNotFoundException.cs
Normal file
16
AirBomber/Exceptions/ObjectNotFoundException.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку, что по указанной позиции нет элемента
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
internal class ObjectNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { }
|
||||||
|
public ObjectNotFoundException() : base() { }
|
||||||
|
public ObjectNotFoundException(string message) : base(message) { }
|
||||||
|
public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
16
AirBomber/Exceptions/PositionOutOfCollectionException.cs
Normal file
16
AirBomber/Exceptions/PositionOutOfCollectionException.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AirBomber.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку выхода за границы коллекции
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
internal class PositionOutOfCollectionException : ApplicationException
|
||||||
|
{
|
||||||
|
public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции.Позиция " + i) { }
|
||||||
|
public PositionOutOfCollectionException() : base() { }
|
||||||
|
public PositionOutOfCollectionException(string message) : base(message) { }
|
||||||
|
public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
175
AirBomber/FormAirBomber.Designer.cs
generated
175
AirBomber/FormAirBomber.Designer.cs
generated
@@ -28,109 +28,128 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.buttonCreate = new System.Windows.Forms.Button();
|
ButtonRight = new Button();
|
||||||
this.ButtonRight = new System.Windows.Forms.Button();
|
ButtonUp = new Button();
|
||||||
this.ButtonUp = new System.Windows.Forms.Button();
|
ButtonLeft = new Button();
|
||||||
this.ButtonLeft = new System.Windows.Forms.Button();
|
ButtonDown = new Button();
|
||||||
this.ButtonDown = new System.Windows.Forms.Button();
|
pictureBoxAirBomber = new PictureBox();
|
||||||
this.pictureBoxAirBomber = new System.Windows.Forms.PictureBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit();
|
buttonStrategyStep = new Button();
|
||||||
this.SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
//
|
SuspendLayout();
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
|
||||||
this.buttonCreate.Location = new System.Drawing.Point(12, 575);
|
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(128, 33);
|
|
||||||
this.buttonCreate.TabIndex = 0;
|
|
||||||
this.buttonCreate.Text = "Создать";
|
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
|
||||||
//
|
//
|
||||||
// ButtonRight
|
// ButtonRight
|
||||||
//
|
//
|
||||||
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
this.ButtonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
|
ButtonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||||
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
this.ButtonRight.Location = new System.Drawing.Point(905, 560);
|
ButtonRight.Location = new Point(792, 420);
|
||||||
this.ButtonRight.Name = "ButtonRight";
|
ButtonRight.Margin = new Padding(3, 2, 3, 2);
|
||||||
this.ButtonRight.Size = new System.Drawing.Size(50, 48);
|
ButtonRight.Name = "ButtonRight";
|
||||||
this.ButtonRight.TabIndex = 1;
|
ButtonRight.Size = new Size(44, 36);
|
||||||
this.ButtonRight.UseVisualStyleBackColor = true;
|
ButtonRight.TabIndex = 1;
|
||||||
this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
ButtonRight.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// ButtonUp
|
// ButtonUp
|
||||||
//
|
//
|
||||||
this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
this.ButtonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
|
ButtonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||||
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
ButtonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
this.ButtonUp.Location = new System.Drawing.Point(849, 506);
|
ButtonUp.Location = new Point(743, 380);
|
||||||
this.ButtonUp.Name = "ButtonUp";
|
ButtonUp.Margin = new Padding(3, 2, 3, 2);
|
||||||
this.ButtonUp.Size = new System.Drawing.Size(50, 48);
|
ButtonUp.Name = "ButtonUp";
|
||||||
this.ButtonUp.TabIndex = 2;
|
ButtonUp.Size = new Size(44, 36);
|
||||||
this.ButtonUp.UseVisualStyleBackColor = true;
|
ButtonUp.TabIndex = 2;
|
||||||
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
ButtonUp.UseVisualStyleBackColor = true;
|
||||||
|
ButtonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// ButtonLeft
|
// ButtonLeft
|
||||||
//
|
//
|
||||||
this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
this.ButtonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
|
ButtonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||||
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
this.ButtonLeft.Location = new System.Drawing.Point(793, 560);
|
ButtonLeft.Location = new Point(694, 420);
|
||||||
this.ButtonLeft.Name = "ButtonLeft";
|
ButtonLeft.Margin = new Padding(3, 2, 3, 2);
|
||||||
this.ButtonLeft.Size = new System.Drawing.Size(50, 48);
|
ButtonLeft.Name = "ButtonLeft";
|
||||||
this.ButtonLeft.TabIndex = 3;
|
ButtonLeft.Size = new Size(44, 36);
|
||||||
this.ButtonLeft.UseVisualStyleBackColor = true;
|
ButtonLeft.TabIndex = 3;
|
||||||
this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
ButtonLeft.UseVisualStyleBackColor = true;
|
||||||
|
ButtonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// ButtonDown
|
// ButtonDown
|
||||||
//
|
//
|
||||||
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
this.ButtonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
|
ButtonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||||
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
ButtonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
this.ButtonDown.Location = new System.Drawing.Point(849, 560);
|
ButtonDown.Location = new Point(743, 420);
|
||||||
this.ButtonDown.Name = "ButtonDown";
|
ButtonDown.Margin = new Padding(3, 2, 3, 2);
|
||||||
this.ButtonDown.Size = new System.Drawing.Size(50, 48);
|
ButtonDown.Name = "ButtonDown";
|
||||||
this.ButtonDown.TabIndex = 4;
|
ButtonDown.Size = new Size(44, 36);
|
||||||
this.ButtonDown.UseVisualStyleBackColor = true;
|
ButtonDown.TabIndex = 4;
|
||||||
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
ButtonDown.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDown.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// pictureBoxAirBomber
|
// pictureBoxAirBomber
|
||||||
//
|
//
|
||||||
this.pictureBoxAirBomber.Dock = System.Windows.Forms.DockStyle.Fill;
|
pictureBoxAirBomber.Dock = DockStyle.Fill;
|
||||||
this.pictureBoxAirBomber.Location = new System.Drawing.Point(0, 0);
|
pictureBoxAirBomber.Location = new Point(0, 0);
|
||||||
this.pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
pictureBoxAirBomber.Margin = new Padding(3, 2, 3, 2);
|
||||||
this.pictureBoxAirBomber.Size = new System.Drawing.Size(967, 621);
|
pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
||||||
this.pictureBoxAirBomber.TabIndex = 5;
|
pictureBoxAirBomber.Size = new Size(846, 466);
|
||||||
this.pictureBoxAirBomber.TabStop = false;
|
pictureBoxAirBomber.TabIndex = 5;
|
||||||
this.pictureBoxAirBomber.Resize += new System.EventHandler(this.PictureBoxResize);
|
pictureBoxAirBomber.TabStop = false;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
|
||||||
|
comboBoxStrategy.Location = new Point(704, 9);
|
||||||
|
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(133, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStrategyStep.Location = new Point(704, 56);
|
||||||
|
buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(82, 22);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "Шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||||
//
|
//
|
||||||
// FormAirBomber
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(967, 621);
|
ClientSize = new Size(846, 466);
|
||||||
this.Controls.Add(this.ButtonDown);
|
Controls.Add(buttonStrategyStep);
|
||||||
this.Controls.Add(this.ButtonLeft);
|
Controls.Add(comboBoxStrategy);
|
||||||
this.Controls.Add(this.ButtonUp);
|
Controls.Add(ButtonDown);
|
||||||
this.Controls.Add(this.ButtonRight);
|
Controls.Add(ButtonLeft);
|
||||||
this.Controls.Add(this.buttonCreate);
|
Controls.Add(ButtonUp);
|
||||||
this.Controls.Add(this.pictureBoxAirBomber);
|
Controls.Add(ButtonRight);
|
||||||
this.Name = "FormAirBomber";
|
Controls.Add(pictureBoxAirBomber);
|
||||||
this.Text = "AirBomber";
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).EndInit();
|
Name = "FormAirBomber";
|
||||||
this.ResumeLayout(false);
|
Text = "AirBomber";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Button buttonCreate;
|
|
||||||
private Button ButtonRight;
|
private Button ButtonRight;
|
||||||
private Button ButtonUp;
|
private Button ButtonUp;
|
||||||
private Button ButtonLeft;
|
private Button ButtonLeft;
|
||||||
private Button ButtonDown;
|
private Button ButtonDown;
|
||||||
private PictureBox pictureBoxAirBomber;
|
private PictureBox pictureBoxAirBomber;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,72 +1,122 @@
|
|||||||
namespace AirBomber
|
using AirBomber.Drawnings;
|
||||||
|
using AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
namespace AirBomber;
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormAirBomber : Form
|
||||||
{
|
{
|
||||||
public partial class FormAirBomber : Form
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
private DrawningAirPlane? _drawningAirPlane;
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
public DrawningAirPlane SetAirPlane
|
||||||
{
|
{
|
||||||
private DrawningAirBomber _drawingAirBomber;
|
set
|
||||||
public FormAirBomber()
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
_drawningAirPlane = value;
|
||||||
}
|
_drawningAirPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
private void Draw()
|
|
||||||
{
|
|
||||||
Bitmap bpm = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bpm);
|
|
||||||
_drawingAirBomber.DrawAirBomber(gr);
|
|
||||||
pictureBoxAirBomber.Image = bpm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
_drawingAirBomber = new DrawningAirBomber();
|
|
||||||
_drawingAirBomber.Init(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
_drawingAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
|
||||||
_drawingAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawingAirBomber == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
||||||
bool result = false;
|
|
||||||
switch (name)
|
|
||||||
{
|
|
||||||
case "ButtonUp":
|
|
||||||
result = _drawingAirBomber.MoveAirBomber(DirectionType.Up);
|
|
||||||
break;
|
|
||||||
case "ButtonDown":
|
|
||||||
result = _drawingAirBomber.MoveAirBomber(DirectionType.Down);
|
|
||||||
break;
|
|
||||||
case "ButtonLeft":
|
|
||||||
result = _drawingAirBomber.MoveAirBomber(DirectionType.Left);
|
|
||||||
break;
|
|
||||||
case "ButtonRight":
|
|
||||||
result = _drawingAirBomber.MoveAirBomber(DirectionType.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PictureBoxResize(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_drawingAirBomber?.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public FormAirBomber()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pictureBoxAirBomber.Width == 0 || pictureBoxAirBomber.Height == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bpm = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bpm);
|
||||||
|
_drawningAirPlane?.DrawTransport(gr);
|
||||||
|
pictureBoxAirBomber.Image = bpm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
bool result = false;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "ButtonUp":
|
||||||
|
result = _drawningAirPlane.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "ButtonDown":
|
||||||
|
result = _drawningAirPlane.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "ButtonLeft":
|
||||||
|
result = _drawningAirPlane.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "ButtonRight":
|
||||||
|
result = _drawningAirPlane.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
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(new MoveableAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,64 @@
|
|||||||
<root>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<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:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
|||||||
378
AirBomber/FormAirPlaneCollection.Designer.cs
generated
Normal file
378
AirBomber/FormAirPlaneCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,378 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormAirPlaneCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
panelCompanyTools = new Panel();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonAddAirPlane = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonDelAirPlane = new Button();
|
||||||
|
buttonGoToCheck = new Button();
|
||||||
|
buttonCreateCompany = new Button();
|
||||||
|
panelStorage = new Panel();
|
||||||
|
buttonCollectionDel = new Button();
|
||||||
|
listBoxCollection = new ListBox();
|
||||||
|
buttonCollectionAdd = new Button();
|
||||||
|
radioButtonList = new RadioButton();
|
||||||
|
radioButtonMassive = new RadioButton();
|
||||||
|
textBoxCollectionName = new TextBox();
|
||||||
|
labelCollectionName = new Label();
|
||||||
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
panelCompanyTools.SuspendLayout();
|
||||||
|
panelStorage.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||||
|
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||||
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(752, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(208, 659);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструманты";
|
||||||
|
//
|
||||||
|
// panelCompanyTools
|
||||||
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
|
panelCompanyTools.Controls.Add(buttonAddAirPlane);
|
||||||
|
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||||
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
|
panelCompanyTools.Controls.Add(buttonDelAirPlane);
|
||||||
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
|
panelCompanyTools.Location = new Point(12, 315);
|
||||||
|
panelCompanyTools.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
|
panelCompanyTools.Size = new Size(184, 339);
|
||||||
|
panelCompanyTools.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(6, 295);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(175, 37);
|
||||||
|
buttonSortByColor.TabIndex = 9;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(6, 255);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(175, 38);
|
||||||
|
buttonSortByType.TabIndex = 8;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// buttonAddAirPlane
|
||||||
|
//
|
||||||
|
buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddAirPlane.Location = new Point(6, 3);
|
||||||
|
buttonAddAirPlane.Name = "buttonAddAirPlane";
|
||||||
|
buttonAddAirPlane.Size = new Size(175, 41);
|
||||||
|
buttonAddAirPlane.TabIndex = 1;
|
||||||
|
buttonAddAirPlane.Text = "Добавление самолета";
|
||||||
|
buttonAddAirPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddAirPlane.Click += buttonAddAirPlane_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(6, 98);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(176, 23);
|
||||||
|
maskedTextBox.TabIndex = 3;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(6, 212);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(175, 37);
|
||||||
|
buttonRefresh.TabIndex = 6;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonDelAirPlane
|
||||||
|
//
|
||||||
|
buttonDelAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonDelAirPlane.Location = new Point(6, 124);
|
||||||
|
buttonDelAirPlane.Name = "buttonDelAirPlane";
|
||||||
|
buttonDelAirPlane.Size = new Size(175, 38);
|
||||||
|
buttonDelAirPlane.TabIndex = 4;
|
||||||
|
buttonDelAirPlane.Text = "Удалить Самолет";
|
||||||
|
buttonDelAirPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelAirPlane.Click += ButtonRemoveAirPlane_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Location = new Point(6, 168);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(175, 38);
|
||||||
|
buttonGoToCheck.TabIndex = 5;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateCompany
|
||||||
|
//
|
||||||
|
buttonCreateCompany.Location = new Point(14, 274);
|
||||||
|
buttonCreateCompany.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
|
buttonCreateCompany.Size = new Size(181, 37);
|
||||||
|
buttonCreateCompany.TabIndex = 7;
|
||||||
|
buttonCreateCompany.Text = "Создать компанию";
|
||||||
|
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateCompany.Click += buttonCreateCompany_Click;
|
||||||
|
//
|
||||||
|
// panelStorage
|
||||||
|
//
|
||||||
|
panelStorage.Controls.Add(buttonCollectionDel);
|
||||||
|
panelStorage.Controls.Add(listBoxCollection);
|
||||||
|
panelStorage.Controls.Add(buttonCollectionAdd);
|
||||||
|
panelStorage.Controls.Add(radioButtonList);
|
||||||
|
panelStorage.Controls.Add(radioButtonMassive);
|
||||||
|
panelStorage.Controls.Add(textBoxCollectionName);
|
||||||
|
panelStorage.Controls.Add(labelCollectionName);
|
||||||
|
panelStorage.Dock = DockStyle.Top;
|
||||||
|
panelStorage.Location = new Point(3, 19);
|
||||||
|
panelStorage.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
panelStorage.Name = "panelStorage";
|
||||||
|
panelStorage.Size = new Size(202, 228);
|
||||||
|
panelStorage.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonCollectionDel
|
||||||
|
//
|
||||||
|
buttonCollectionDel.Location = new Point(11, 203);
|
||||||
|
buttonCollectionDel.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||||
|
buttonCollectionDel.Size = new Size(184, 22);
|
||||||
|
buttonCollectionDel.TabIndex = 6;
|
||||||
|
buttonCollectionDel.Text = "Удалить коллецию";
|
||||||
|
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionDel.Click += buttonCollectionDel_Click;
|
||||||
|
//
|
||||||
|
// listBoxCollection
|
||||||
|
//
|
||||||
|
listBoxCollection.FormattingEnabled = true;
|
||||||
|
listBoxCollection.ItemHeight = 15;
|
||||||
|
listBoxCollection.Location = new Point(3, 121);
|
||||||
|
listBoxCollection.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
listBoxCollection.Name = "listBoxCollection";
|
||||||
|
listBoxCollection.Size = new Size(193, 79);
|
||||||
|
listBoxCollection.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonCollectionAdd
|
||||||
|
//
|
||||||
|
buttonCollectionAdd.Location = new Point(11, 94);
|
||||||
|
buttonCollectionAdd.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||||
|
buttonCollectionAdd.Size = new Size(189, 22);
|
||||||
|
buttonCollectionAdd.TabIndex = 4;
|
||||||
|
buttonCollectionAdd.Text = "Добавить коллецию";
|
||||||
|
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
|
||||||
|
//
|
||||||
|
// radioButtonList
|
||||||
|
//
|
||||||
|
radioButtonList.AutoSize = true;
|
||||||
|
radioButtonList.Location = new Point(84, 72);
|
||||||
|
radioButtonList.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
radioButtonList.Name = "radioButtonList";
|
||||||
|
radioButtonList.Size = new Size(66, 19);
|
||||||
|
radioButtonList.TabIndex = 3;
|
||||||
|
radioButtonList.TabStop = true;
|
||||||
|
radioButtonList.Text = "Список";
|
||||||
|
radioButtonList.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// radioButtonMassive
|
||||||
|
//
|
||||||
|
radioButtonMassive.AutoSize = true;
|
||||||
|
radioButtonMassive.Location = new Point(11, 72);
|
||||||
|
radioButtonMassive.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
radioButtonMassive.Name = "radioButtonMassive";
|
||||||
|
radioButtonMassive.Size = new Size(67, 19);
|
||||||
|
radioButtonMassive.TabIndex = 2;
|
||||||
|
radioButtonMassive.TabStop = true;
|
||||||
|
radioButtonMassive.Text = "Массив";
|
||||||
|
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// textBoxCollectionName
|
||||||
|
//
|
||||||
|
textBoxCollectionName.Location = new Point(3, 40);
|
||||||
|
textBoxCollectionName.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||||
|
textBoxCollectionName.Size = new Size(198, 23);
|
||||||
|
textBoxCollectionName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCollectionName
|
||||||
|
//
|
||||||
|
labelCollectionName.AutoSize = true;
|
||||||
|
labelCollectionName.Location = new Point(11, 9);
|
||||||
|
labelCollectionName.Name = "labelCollectionName";
|
||||||
|
labelCollectionName.Size = new Size(119, 15);
|
||||||
|
labelCollectionName.TabIndex = 0;
|
||||||
|
labelCollectionName.Text = "Название коллеции:";
|
||||||
|
//
|
||||||
|
// comboBoxSelectorCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
|
comboBoxSelectorCompany.Location = new Point(14, 248);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(184, 23);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(752, 659);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(752, 24);
|
||||||
|
menuStrip.TabIndex = 3;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||||
|
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||||
|
файлToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// saveToolStripMenuItem
|
||||||
|
//
|
||||||
|
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
|
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||||
|
saveToolStripMenuItem.Size = new Size(181, 22);
|
||||||
|
saveToolStripMenuItem.Text = "Сохранение";
|
||||||
|
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// loadToolStripMenuItem
|
||||||
|
//
|
||||||
|
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
|
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||||
|
loadToolStripMenuItem.Size = new Size(181, 22);
|
||||||
|
loadToolStripMenuItem.Text = "Загрузка";
|
||||||
|
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// FormAirPlaneCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(960, 659);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormAirPlaneCollection";
|
||||||
|
Text = "FormAirPlaneCollection";
|
||||||
|
Load += FormAirPlaneCollection_Load;
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
panelCompanyTools.ResumeLayout(false);
|
||||||
|
panelCompanyTools.PerformLayout();
|
||||||
|
panelStorage.ResumeLayout(false);
|
||||||
|
panelStorage.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private Button buttonAddAirPlane;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
private Button buttonDelAirPlane;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Panel panelStorage;
|
||||||
|
private TextBox textBoxCollectionName;
|
||||||
|
private Label labelCollectionName;
|
||||||
|
private RadioButton radioButtonList;
|
||||||
|
private RadioButton radioButtonMassive;
|
||||||
|
private Button buttonCollectionAdd;
|
||||||
|
private Button buttonCollectionDel;
|
||||||
|
private ListBox listBoxCollection;
|
||||||
|
private Button buttonCreateCompany;
|
||||||
|
private Panel panelCompanyTools;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
}
|
||||||
|
}
|
||||||
366
AirBomber/FormAirPlaneCollection.cs
Normal file
366
AirBomber/FormAirPlaneCollection.cs
Normal file
@@ -0,0 +1,366 @@
|
|||||||
|
using AirBomber.CollectionGenericObjects;
|
||||||
|
using AirBomber.Drawnings;
|
||||||
|
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.Extensions.Logging;
|
||||||
|
using AirBomber.Exceptions;
|
||||||
|
|
||||||
|
namespace AirBomber;
|
||||||
|
|
||||||
|
public partial class FormAirPlaneCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
private readonly StorageCollection<DrawningAirPlane> _storageCollection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Компания
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormAirPlaneCollection(ILogger<FormAirPlaneCollection> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storageCollection = new();
|
||||||
|
_logger = logger;
|
||||||
|
_logger.LogInformation("Форма загрузилась");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор компании
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
panelCompanyTools.Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddAirPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormAirPlaneConfig form = new();
|
||||||
|
//TODO передать метод
|
||||||
|
form.Show();
|
||||||
|
form.AddEvent(SetAirPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление самолета в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="airplane"></param>
|
||||||
|
private void SetAirPlane(DrawningAirPlane airplane)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_company == null || airplane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_company + airplane != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
_logger.LogInformation("Добавлен объект: " + airplane.GetDataForSave());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ObjectNotFoundException) { }
|
||||||
|
catch (CollectionOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("В коллекции превышено допустимое количество элементов");
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
catch (ObjectIsEqualException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Такой объект уже существует в коллекции");
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveAirPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Входные данные отсутствуют");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
_logger.LogInformation("Объект удален");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не найден объект по позиции " + pos);
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Передача объекта в другую форму
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawningAirPlane? airPlane = null;
|
||||||
|
int counter = 100;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (airPlane == null)
|
||||||
|
{
|
||||||
|
airPlane = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (airPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormAirBomber form = new FormAirBomber();
|
||||||
|
form.SetAirPlane = airPlane;
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перерисовка коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormAirPlaneCollection_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCollectionAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данный заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CollectionType collectionType = CollectionType.None;
|
||||||
|
if (radioButtonMassive.Checked)
|
||||||
|
{
|
||||||
|
collectionType = CollectionType.Massive;
|
||||||
|
}
|
||||||
|
else if (radioButtonList.Checked)
|
||||||
|
{
|
||||||
|
collectionType = CollectionType.List;
|
||||||
|
}
|
||||||
|
|
||||||
|
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||||
|
RefreshListBoxItems();
|
||||||
|
_logger.LogInformation("Добавлена коллекция:", textBoxCollectionName.Text);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshListBoxItems()
|
||||||
|
{
|
||||||
|
listBoxCollection.Items.Clear();
|
||||||
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||||
|
{
|
||||||
|
string? colName = _storageCollection.Keys?[i].Name;
|
||||||
|
if (!string.IsNullOrEmpty(colName))
|
||||||
|
{
|
||||||
|
listBoxCollection.Items.Add(colName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItems == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||||
|
RefreshListBoxItems();
|
||||||
|
_logger.LogInformation("Удалена коллекция: ", listBoxCollection.SelectedItem.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Создание компании
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICollectionGenericObjects<DrawningAirPlane>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не проинициализирована");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new AirPlaneSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
panelCompanyTools.Enabled = true;
|
||||||
|
RefreshListBoxItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка кнопки загрузки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storageCollection.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
RefreshListBoxItems();
|
||||||
|
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareAirPlane(new DrawningAirPlaneCompareByType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareAirPlane(new DrawningBoatCompareByColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CompareAirPlane(IComparer<DrawningAirPlane?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
129
AirBomber/FormAirPlaneCollection.resx
Normal file
129
AirBomber/FormAirPlaneCollection.resx
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<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="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>126, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>261, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
||||||
358
AirBomber/FormAirPlaneConfig.Designer.cs
generated
Normal file
358
AirBomber/FormAirPlaneConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormAirPlaneConfig
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBoxConfig = new GroupBox();
|
||||||
|
groupBoxColors = new GroupBox();
|
||||||
|
panelPurple = new Panel();
|
||||||
|
panelYellow = new Panel();
|
||||||
|
panelBlack = new Panel();
|
||||||
|
panelGray = new Panel();
|
||||||
|
panelBlue = new Panel();
|
||||||
|
panelWhite = new Panel();
|
||||||
|
panelGreen = new Panel();
|
||||||
|
panelRed = new Panel();
|
||||||
|
checkBoxFuelTanks = new CheckBox();
|
||||||
|
checkBoxBombs = new CheckBox();
|
||||||
|
numericUpDownWeight = new NumericUpDown();
|
||||||
|
labelWeight = new Label();
|
||||||
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
|
labelSpeed = new Label();
|
||||||
|
labelModifiedObject = new Label();
|
||||||
|
labelSimpleObject = new Label();
|
||||||
|
pictureBoxObject = new PictureBox();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
panelObject = new Panel();
|
||||||
|
labelBodyColor = new Label();
|
||||||
|
labelAdditionalColor = new Label();
|
||||||
|
groupBoxConfig.SuspendLayout();
|
||||||
|
groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||||
|
panelObject.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
groupBoxConfig.Controls.Add(groupBoxColors);
|
||||||
|
groupBoxConfig.Controls.Add(checkBoxFuelTanks);
|
||||||
|
groupBoxConfig.Controls.Add(checkBoxBombs);
|
||||||
|
groupBoxConfig.Controls.Add(numericUpDownWeight);
|
||||||
|
groupBoxConfig.Controls.Add(labelWeight);
|
||||||
|
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||||
|
groupBoxConfig.Controls.Add(labelSpeed);
|
||||||
|
groupBoxConfig.Controls.Add(labelModifiedObject);
|
||||||
|
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||||
|
groupBoxConfig.Dock = DockStyle.Left;
|
||||||
|
groupBoxConfig.Location = new Point(0, 0);
|
||||||
|
groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
groupBoxConfig.Size = new Size(550, 260);
|
||||||
|
groupBoxConfig.TabIndex = 0;
|
||||||
|
groupBoxConfig.TabStop = false;
|
||||||
|
groupBoxConfig.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
groupBoxColors.Controls.Add(panelPurple);
|
||||||
|
groupBoxColors.Controls.Add(panelYellow);
|
||||||
|
groupBoxColors.Controls.Add(panelBlack);
|
||||||
|
groupBoxColors.Controls.Add(panelGray);
|
||||||
|
groupBoxColors.Controls.Add(panelBlue);
|
||||||
|
groupBoxColors.Controls.Add(panelWhite);
|
||||||
|
groupBoxColors.Controls.Add(panelGreen);
|
||||||
|
groupBoxColors.Controls.Add(panelRed);
|
||||||
|
groupBoxColors.Location = new Point(315, 12);
|
||||||
|
groupBoxColors.Name = "groupBoxColors";
|
||||||
|
groupBoxColors.Size = new Size(227, 112);
|
||||||
|
groupBoxColors.TabIndex = 11;
|
||||||
|
groupBoxColors.TabStop = false;
|
||||||
|
groupBoxColors.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
panelPurple.BackColor = Color.Purple;
|
||||||
|
panelPurple.Location = new Point(176, 66);
|
||||||
|
panelPurple.Name = "panelPurple";
|
||||||
|
panelPurple.Size = new Size(34, 34);
|
||||||
|
panelPurple.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
panelYellow.BackColor = Color.Yellow;
|
||||||
|
panelYellow.Location = new Point(176, 22);
|
||||||
|
panelYellow.Name = "panelYellow";
|
||||||
|
panelYellow.Size = new Size(34, 34);
|
||||||
|
panelYellow.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
panelBlack.BackColor = Color.Black;
|
||||||
|
panelBlack.Location = new Point(120, 66);
|
||||||
|
panelBlack.Name = "panelBlack";
|
||||||
|
panelBlack.Size = new Size(34, 34);
|
||||||
|
panelBlack.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
panelGray.BackColor = Color.Gray;
|
||||||
|
panelGray.Location = new Point(67, 66);
|
||||||
|
panelGray.Name = "panelGray";
|
||||||
|
panelGray.Size = new Size(34, 34);
|
||||||
|
panelGray.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
panelBlue.BackColor = Color.Blue;
|
||||||
|
panelBlue.Location = new Point(120, 22);
|
||||||
|
panelBlue.Name = "panelBlue";
|
||||||
|
panelBlue.Size = new Size(34, 34);
|
||||||
|
panelBlue.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
panelWhite.BackColor = Color.White;
|
||||||
|
panelWhite.Location = new Point(15, 66);
|
||||||
|
panelWhite.Name = "panelWhite";
|
||||||
|
panelWhite.Size = new Size(34, 34);
|
||||||
|
panelWhite.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
panelGreen.BackColor = Color.Green;
|
||||||
|
panelGreen.Location = new Point(67, 22);
|
||||||
|
panelGreen.Name = "panelGreen";
|
||||||
|
panelGreen.Size = new Size(34, 34);
|
||||||
|
panelGreen.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
panelRed.BackColor = Color.Red;
|
||||||
|
panelRed.Location = new Point(15, 22);
|
||||||
|
panelRed.Name = "panelRed";
|
||||||
|
panelRed.Size = new Size(34, 34);
|
||||||
|
panelRed.TabIndex = 0;
|
||||||
|
panelRed.MouseDown += Panel_MouseDown;
|
||||||
|
//
|
||||||
|
// checkBoxFuelTanks
|
||||||
|
//
|
||||||
|
checkBoxFuelTanks.AutoSize = true;
|
||||||
|
checkBoxFuelTanks.Location = new Point(12, 178);
|
||||||
|
checkBoxFuelTanks.Name = "checkBoxFuelTanks";
|
||||||
|
checkBoxFuelTanks.Size = new Size(248, 19);
|
||||||
|
checkBoxFuelTanks.TabIndex = 7;
|
||||||
|
checkBoxFuelTanks.Text = "Признак наличия доп. топливных баков";
|
||||||
|
checkBoxFuelTanks.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxBombs
|
||||||
|
//
|
||||||
|
checkBoxBombs.AutoSize = true;
|
||||||
|
checkBoxBombs.Location = new Point(12, 132);
|
||||||
|
checkBoxBombs.Name = "checkBoxBombs";
|
||||||
|
checkBoxBombs.Size = new Size(156, 19);
|
||||||
|
checkBoxBombs.TabIndex = 6;
|
||||||
|
checkBoxBombs.Text = "Признак наличия бомб";
|
||||||
|
checkBoxBombs.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
numericUpDownWeight.Location = new Point(80, 82);
|
||||||
|
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(88, 23);
|
||||||
|
numericUpDownWeight.TabIndex = 5;
|
||||||
|
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
labelWeight.AutoSize = true;
|
||||||
|
labelWeight.Location = new Point(12, 84);
|
||||||
|
labelWeight.Name = "labelWeight";
|
||||||
|
labelWeight.Size = new Size(29, 15);
|
||||||
|
labelWeight.TabIndex = 4;
|
||||||
|
labelWeight.Text = "Вес:";
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
numericUpDownSpeed.Location = new Point(80, 38);
|
||||||
|
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(88, 23);
|
||||||
|
numericUpDownSpeed.TabIndex = 3;
|
||||||
|
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
labelSpeed.AutoSize = true;
|
||||||
|
labelSpeed.Location = new Point(12, 40);
|
||||||
|
labelSpeed.Name = "labelSpeed";
|
||||||
|
labelSpeed.Size = new Size(62, 15);
|
||||||
|
labelSpeed.TabIndex = 2;
|
||||||
|
labelSpeed.Text = "Скорость:";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelModifiedObject.Location = new Point(408, 166);
|
||||||
|
labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
labelModifiedObject.Size = new Size(103, 40);
|
||||||
|
labelModifiedObject.TabIndex = 1;
|
||||||
|
labelModifiedObject.Text = "Продвинутый";
|
||||||
|
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelModifiedObject.MouseDown += labelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleObject.Location = new Point(289, 166);
|
||||||
|
labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
labelSimpleObject.Size = new Size(103, 40);
|
||||||
|
labelSimpleObject.TabIndex = 0;
|
||||||
|
labelSimpleObject.Text = "Простой";
|
||||||
|
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleObject.MouseDown += labelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
pictureBoxObject.Location = new Point(13, 45);
|
||||||
|
pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
pictureBoxObject.Size = new Size(170, 136);
|
||||||
|
pictureBoxObject.TabIndex = 1;
|
||||||
|
pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(588, 190);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(88, 40);
|
||||||
|
buttonAdd.TabIndex = 2;
|
||||||
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += ButtonAdd_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(688, 190);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(89, 40);
|
||||||
|
buttonCancel.TabIndex = 3;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
panelObject.AllowDrop = true;
|
||||||
|
panelObject.Controls.Add(labelBodyColor);
|
||||||
|
panelObject.Controls.Add(labelAdditionalColor);
|
||||||
|
panelObject.Controls.Add(pictureBoxObject);
|
||||||
|
panelObject.Location = new Point(594, 0);
|
||||||
|
panelObject.Name = "panelObject";
|
||||||
|
panelObject.Size = new Size(194, 184);
|
||||||
|
panelObject.TabIndex = 4;
|
||||||
|
panelObject.DragDrop += PanelObject_DragDrop;
|
||||||
|
panelObject.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// labelBodyColor
|
||||||
|
//
|
||||||
|
labelBodyColor.AllowDrop = true;
|
||||||
|
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelBodyColor.Location = new Point(13, 9);
|
||||||
|
labelBodyColor.Name = "labelBodyColor";
|
||||||
|
labelBodyColor.Size = new Size(75, 33);
|
||||||
|
labelBodyColor.TabIndex = 2;
|
||||||
|
labelBodyColor.Text = "Цвет";
|
||||||
|
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelBodyColor.DragDrop += labelBodyColor_DragDrop;
|
||||||
|
labelBodyColor.DragEnter += labelBodyColor_DragEnter;
|
||||||
|
//
|
||||||
|
// labelAdditionalColor
|
||||||
|
//
|
||||||
|
labelAdditionalColor.AllowDrop = true;
|
||||||
|
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAdditionalColor.Location = new Point(108, 9);
|
||||||
|
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||||
|
labelAdditionalColor.Size = new Size(75, 33);
|
||||||
|
labelAdditionalColor.TabIndex = 3;
|
||||||
|
labelAdditionalColor.Text = "Доп. Цвет";
|
||||||
|
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
|
||||||
|
labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
|
||||||
|
//
|
||||||
|
// FormAirPlaneConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(795, 260);
|
||||||
|
Controls.Add(panelObject);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(groupBoxConfig);
|
||||||
|
Name = "FormAirPlaneConfig";
|
||||||
|
Text = "Создание объекта";
|
||||||
|
groupBoxConfig.ResumeLayout(false);
|
||||||
|
groupBoxConfig.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 groupBoxConfig;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private CheckBox checkBoxBombs;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private Label labelWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private CheckBox checkBoxFuelTanks;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Panel panelObject;
|
||||||
|
private Label labelAdditionalColor;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Label labelBodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
175
AirBomber/FormAirPlaneConfig.cs
Normal file
175
AirBomber/FormAirPlaneConfig.cs
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
using AirBomber.Drawnings;
|
||||||
|
using AirBomber.Entities;
|
||||||
|
|
||||||
|
namespace AirBomber;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форма конфигурации объекта
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormAirPlaneConfig : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Объект - прорисовка самолета
|
||||||
|
/// </summary>
|
||||||
|
private DrawningAirPlane? _airplane = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// События для передачи объекта
|
||||||
|
/// </summary>
|
||||||
|
private event Action<DrawningAirPlane> AirPlaneDelegate;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormAirPlaneConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
panelRed.MouseDown += Panel_MouseDown;
|
||||||
|
panelGreen.MouseDown += Panel_MouseDown;
|
||||||
|
panelBlue.MouseDown += Panel_MouseDown;
|
||||||
|
panelYellow.MouseDown += Panel_MouseDown;
|
||||||
|
panelWhite.MouseDown += Panel_MouseDown;
|
||||||
|
panelGray.MouseDown += Panel_MouseDown;
|
||||||
|
panelBlack.MouseDown += Panel_MouseDown;
|
||||||
|
panelPurple.MouseDown += Panel_MouseDown;
|
||||||
|
|
||||||
|
buttonCancel.Click += (sender, e) => Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Привязка внешнего метода к событию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="airplaneDelegate"></param>
|
||||||
|
public void AddEvent(Action<DrawningAirPlane> airplaneDelegate)
|
||||||
|
{
|
||||||
|
AirPlaneDelegate += airplaneDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
private void DrawObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_airplane?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
_airplane?.SetPosition(5, 5);
|
||||||
|
_airplane?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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 ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : 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":
|
||||||
|
_airplane = new DrawningAirPlane((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_airplane = new DrawningAirBomber((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
||||||
|
Color.Black, checkBoxBombs.Checked, checkBoxFuelTanks.Checked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
labelBodyColor.BackColor = Color.Empty;
|
||||||
|
labelAdditionalColor.BackColor = Color.Empty;
|
||||||
|
DrawObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Передаем информацию при нажатии на Panel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
// TODO отправка цвета в Drag&Drop
|
||||||
|
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
|
||||||
|
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_airplane != null)
|
||||||
|
{
|
||||||
|
_airplane.EntityAirPlane.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
DrawObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_airplane is DrawningAirBomber)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_airplane?.EntityAirPlane is EntityAirBomber _airbomber)
|
||||||
|
{
|
||||||
|
_airbomber.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
}
|
||||||
|
DrawObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Передача объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_airplane != null)
|
||||||
|
{
|
||||||
|
AirPlaneDelegate?.Invoke(_airplane);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
120
AirBomber/FormAirPlaneConfig.resx
Normal file
120
AirBomber/FormAirPlaneConfig.resx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<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>
|
||||||
142
AirBomber/MovementStrategy/AbstractStrategy.cs
Normal file
142
AirBomber/MovementStrategy/AbstractStrategy.cs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
public StrategyStatus 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 = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="movementDirection">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(MovementDirection movementDirection)
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
AirBomber/MovementStrategy/IMoveableObject.cs
Normal file
27
AirBomber/MovementStrategy/IMoveableObject.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка переместить объект в указанном направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||||
|
bool TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
||||||
54
AirBomber/MovementStrategy/MoveToBorder.cs
Normal file
54
AirBomber/MovementStrategy/MoveToBorder.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.MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
AirBomber/MovementStrategy/MoveToCenter.cs
Normal file
56
AirBomber/MovementStrategy/MoveToCenter.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
63
AirBomber/MovementStrategy/MoveableAirPlane.cs
Normal file
63
AirBomber/MovementStrategy/MoveableAirPlane.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using AirBomber.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
internal class MoveableAirPlane : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект класса DrawningBoat или его наследника
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningAirPlane? _airPlane = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningAirPlane">Объект класса DrawningCar</param>
|
||||||
|
public MoveableAirPlane(DrawningAirPlane drawningAirPlane)
|
||||||
|
{
|
||||||
|
_airPlane = drawningAirPlane;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_airPlane == null || _airPlane.EntityAirPlane == null || !_airPlane.GetPosX.HasValue || !_airPlane.GetPosY.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_airPlane.GetPosX.Value, _airPlane.GetPosY.Value, _airPlane.GetWidth, _airPlane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_airPlane?.EntityAirPlane?.Step ?? 0);
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_airPlane == null || _airPlane.EntityAirPlane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _airPlane.MoveTransport(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертация из MovementDirection в DirectionType
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">MovementDirection</param>
|
||||||
|
/// <returns>DirectionType</returns>
|
||||||
|
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||||
|
{
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
MovementDirection.Left => DirectionType.Left,
|
||||||
|
MovementDirection.Right => DirectionType.Right,
|
||||||
|
MovementDirection.Up => DirectionType.Up,
|
||||||
|
MovementDirection.Down => DirectionType.Down,
|
||||||
|
_ => DirectionType.Unknow,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
18
AirBomber/MovementStrategy/MovementDirection.cs
Normal file
18
AirBomber/MovementStrategy/MovementDirection.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
|
||||||
|
Down = 2,
|
||||||
|
|
||||||
|
Left = 3,
|
||||||
|
|
||||||
|
Right = 4,
|
||||||
|
}
|
||||||
75
AirBomber/MovementStrategy/ObjectParameters.cs
Normal file
75
AirBomber/MovementStrategy/ObjectParameters.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _x;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _y;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
AirBomber/MovementStrategy/StrategyStatus.cs
Normal file
25
AirBomber/MovementStrategy/StrategyStatus.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber.MovementStrategy;
|
||||||
|
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Всё готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
||||||
@@ -1,17 +1,45 @@
|
|||||||
namespace AirBomber
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AirBomber;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static class Program
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
{
|
{
|
||||||
/// <summary>
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
/// The main entry point for the application.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
/// </summary>
|
ApplicationConfiguration.Initialize();
|
||||||
[STAThread]
|
ServiceCollection services = new();
|
||||||
static void Main()
|
ConfigureServices(services);
|
||||||
{
|
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
Application.Run(serviceProvider.GetRequiredService<FormAirPlaneCollection>());
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new FormAirBomber());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
|
||||||
|
services.AddSingleton<FormAirPlaneCollection>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(new LoggerConfiguration().ReadFrom.Configuration(new ConfigurationBuilder().
|
||||||
|
AddJsonFile($"{pathNeed}serilog.json").Build()).CreateLogger());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
AirBomber/serilog.json
Normal file
15
AirBomber/serilog.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": { "path": "log.log" }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Applicatoin": "Sample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user