Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
a02e68e555 | |||
bf6fe472fc | |||
f9a3d57a17 | |||
25d0161b03 | |||
34bd3079ab | |||
88833f3f18 | |||
6be2956699 | |||
22f93d7571 | |||
ce4eb04c93 | |||
ea56167cc9 | |||
933f648c24 | |||
570494812c | |||
7603d99eb9 | |||
321144f895 | |||
d24c649c28 |
97
AircraftCarrier/AircraftCarrier/AbstractStrategy.cs
Normal file
97
AircraftCarrier/AircraftCarrier/AbstractStrategy.cs
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// Перемещаемый объект
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
/// Статус перемещения
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
/// Ширина поля
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
/// Высота поля
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
/// Статус перемещения
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
/// Установка данных
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
|
height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
/// Шаг перемещения
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
/// Перемещение влево
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||||
|
/// Параметры объекта
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
/// Шаг объекта
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
/// Перемещение к цели
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
/// Достигнута ли цель
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// <param name="directionType">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(Direction directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,4 +8,19 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
103
AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs
Normal file
103
AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
namespace AircraftCarrier.Generics
|
||||||
|
{
|
||||||
|
internal class AircraftsGenericCollection<T, U>
|
||||||
|
where T : DrawningAircraft
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
private readonly int _placeSizeWidth = 170;
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
private readonly int _placeSizeHeight = 50;
|
||||||
|
/// Набор объектов
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// Конструктор
|
||||||
|
public AircraftsGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
public static int operator +(AircraftsGenericCollection<T, U> collect, T?
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
public static bool operator -(AircraftsGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowAircrafts()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
|
1; ++j)
|
||||||
|
{
|
||||||
|
//линия рамзетки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int Width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int Height = _pictureHeight / _placeSizeHeight;
|
||||||
|
int i = 0;
|
||||||
|
foreach (var aircraft in _collection.GetAircrafts())
|
||||||
|
{
|
||||||
|
if (aircraft != null)
|
||||||
|
{
|
||||||
|
aircraft.SetPosition(i % Width * _placeSizeWidth + 3, (Height - i / Width - 1) * _placeSizeHeight +5);
|
||||||
|
aircraft.DrawTransport(g);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs
Normal file
60
AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
namespace AircraftCarrier.Generics
|
||||||
|
{
|
||||||
|
/// Класс для хранения коллекции
|
||||||
|
internal class AircraftsGenericStorage
|
||||||
|
{
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
readonly Dictionary<string, AircraftsGenericCollection<DrawningAircraft,
|
||||||
|
DrawningObjectAircraft>> _AircraftStorages;
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
public List<string> Keys => _AircraftStorages.Keys.ToList();
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Конструктор
|
||||||
|
public AircraftsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_AircraftStorages = new Dictionary<string,
|
||||||
|
AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// Добавление набора
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_AircraftStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_AircraftStorages.Add(name, new AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Удаление набора
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_AircraftStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_AircraftStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Доступ к набору
|
||||||
|
public AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_AircraftStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _AircraftStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
AircraftCarrier/AircraftCarrier/Direction.cs
Normal file
27
AircraftCarrier/AircraftCarrier/Direction.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
139
AircraftCarrier/AircraftCarrier/DrawningAircraft.cs
Normal file
139
AircraftCarrier/AircraftCarrier/DrawningAircraft.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.Entities;
|
||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
namespace AircraftCarrier.DrawningObjects
|
||||||
|
{
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
public class DrawningAircraft
|
||||||
|
{
|
||||||
|
/// Класс-сущность
|
||||||
|
public EntityAircraft? EntityAircraft { get; protected set; }
|
||||||
|
/// Ширина окна
|
||||||
|
public int _pictureWidth;
|
||||||
|
/// Высота окна
|
||||||
|
public int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected readonly int _AircraftWidth = 164;
|
||||||
|
protected readonly int _AircraftHeight = 40;
|
||||||
|
/// Координата X объекта
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
/// Координата Y объекта
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
/// Ширина объекта
|
||||||
|
public int GetWidth => _AircraftWidth;
|
||||||
|
/// Высота объекта
|
||||||
|
public int GetHeight => _AircraftHeight;
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectAircraft(this);
|
||||||
|
public bool CanMove(Direction direction)
|
||||||
|
{
|
||||||
|
if (EntityAircraft == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
Direction.Left => _startPosX - EntityAircraft.Step > 0,
|
||||||
|
//вверх
|
||||||
|
Direction.Up => _startPosY - EntityAircraft.Step > 0,
|
||||||
|
// вправо
|
||||||
|
Direction.Right => _startPosX + EntityAircraft.Step + _AircraftWidth < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
Direction.Down => _startPosY + EntityAircraft.Step + _AircraftHeight < _pictureHeight,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityAircraft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case Direction.Left:
|
||||||
|
_startPosX -= (int)EntityAircraft.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case Direction.Up:
|
||||||
|
_startPosY -= (int)EntityAircraft.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case Direction.Right:
|
||||||
|
_startPosX += (int)EntityAircraft.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case Direction.Down:
|
||||||
|
_startPosY += (int)EntityAircraft.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Конструктор
|
||||||
|
public DrawningAircraft(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
|
{
|
||||||
|
if (width < _AircraftWidth || height < _AircraftHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// Конструктор
|
||||||
|
protected DrawningAircraft(int speed, double weight, Color bodyColor,int
|
||||||
|
width, int height, int AircraftWidth, int AircraftHeight)
|
||||||
|
{
|
||||||
|
if (width < _AircraftWidth || height < _AircraftHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_AircraftWidth = AircraftWidth;
|
||||||
|
_AircraftHeight = AircraftHeight;
|
||||||
|
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
/// Установка позиции
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
if (_startPosX < 0 || _startPosY < 0 || _startPosX > (_pictureWidth - _AircraftWidth) || _startPosY > (_pictureHeight - _AircraftHeight))
|
||||||
|
{
|
||||||
|
_startPosX = 50;
|
||||||
|
_startPosY = 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// Прорисовка объекта
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAircraft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush budyBrush = new SolidBrush(EntityAircraft.BodyColor);
|
||||||
|
g.DrawLine(pen, _startPosX + 4, _startPosY, _startPosX + 124, _startPosY);
|
||||||
|
g.DrawLine(pen, _startPosX + 124, _startPosY, _startPosX + 164, _startPosY + 20);
|
||||||
|
g.DrawLine(pen, _startPosX + 164, _startPosY + 20, _startPosX + 124, _startPosY + 40);
|
||||||
|
g.DrawLine(pen, _startPosX + 164, _startPosY + 20, _startPosX + 124, _startPosY + 40);
|
||||||
|
g.DrawLine(pen, _startPosX + 124, _startPosY + 40, _startPosX + 4, _startPosY + 40);
|
||||||
|
g.DrawLine(pen, _startPosX + 4, _startPosY + 40, _startPosX + 4, _startPosY);
|
||||||
|
g.FillRectangle(budyBrush, _startPosX, _startPosY + 6, 4, 12);
|
||||||
|
g.FillRectangle(budyBrush, _startPosX, _startPosY + 24, 4, 12);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 13, 14, 14);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 63, _startPosY + 13, 27, 14);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 9, 14, 22);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
AircraftCarrier/AircraftCarrier/DrawningAircraftCarrier.cs
Normal file
43
AircraftCarrier/AircraftCarrier/DrawningAircraftCarrier.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.Entities;
|
||||||
|
namespace AircraftCarrier.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningAircraftCarrier : DrawningAircraft
|
||||||
|
{
|
||||||
|
public DrawningAircraftCarrier(int speed, double weight, Color bodyColor, Color additionalColor, bool cabin, bool runway, int width, int height) :
|
||||||
|
base(speed, weight, bodyColor, width, height, 164, 40)
|
||||||
|
{
|
||||||
|
if (EntityAircraft != null)
|
||||||
|
{
|
||||||
|
EntityAircraft = new EntityAircraftCarrier(speed, weight, bodyColor,
|
||||||
|
additionalColor, cabin, runway);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAircraft is not EntityAircraftCarrier aircraftCarrie)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Brush additionalBrush = new SolidBrush(aircraftCarrie.AdditionalColor);
|
||||||
|
Pen pen = new(Color.White);
|
||||||
|
if (aircraftCarrie.Cabin)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 4, _startPosY + 13, 59, 14);
|
||||||
|
g.DrawLine(pen, _startPosX + 62, _startPosY + 19, _startPosX + 52, _startPosY + 19);
|
||||||
|
g.DrawLine(pen, _startPosX + 47, _startPosY + 19, _startPosX + 37, _startPosY + 19);
|
||||||
|
g.DrawLine(pen, _startPosX + 32, _startPosY + 19, _startPosX + 22, _startPosY + 19);
|
||||||
|
g.DrawLine(pen, _startPosX + 17, _startPosY + 19, _startPosX + 7, _startPosY + 19);
|
||||||
|
}
|
||||||
|
if (aircraftCarrie.Runway)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY, 15, 9);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
AircraftCarrier/AircraftCarrier/DrawningObjectAircraft.cs
Normal file
35
AircraftCarrier/AircraftCarrier/DrawningObjectAircraft.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectAircraft : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningAircraft? _drawningAircraft = null;
|
||||||
|
public DrawningObjectAircraft(DrawningAircraft drawningAircraft)
|
||||||
|
{
|
||||||
|
_drawningAircraft = drawningAircraft;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningAircraft == null || _drawningAircraft.EntityAircraft ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningAircraft.GetPosX,
|
||||||
|
_drawningAircraft.GetPosY, _drawningAircraft.GetWidth, _drawningAircraft.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningAircraft?.EntityAircraft?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(Direction direction) =>
|
||||||
|
_drawningAircraft?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(Direction direction) =>
|
||||||
|
_drawningAircraft?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
29
AircraftCarrier/AircraftCarrier/EntityAircraft.cs
Normal file
29
AircraftCarrier/AircraftCarrier/EntityAircraft.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.Entities
|
||||||
|
{
|
||||||
|
/// Класс-сущность "Автомобиль"
|
||||||
|
public class EntityAircraft
|
||||||
|
{
|
||||||
|
/// Скорость
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// Вес
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// Основной цвет
|
||||||
|
public Color BodyColor { get; set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
/// Конструктор с параметрами
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityAircraft(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs
Normal file
25
AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.Entities
|
||||||
|
{
|
||||||
|
/// Класс-сущность "Спортивный автомобиль"
|
||||||
|
public class EntityAircraftCarrier : EntityAircraft
|
||||||
|
{
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
public Color AdditionalColor { get; set; }
|
||||||
|
/// Признак (опция) наличия кабины
|
||||||
|
public bool Cabin { get; private set; }
|
||||||
|
/// Признак (опция) наличия взлетной полосы
|
||||||
|
public bool Runway { get; private set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public EntityAircraftCarrier(int speed, double weight, Color bodyColor, Color additionalColor, bool cabin, bool runway) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Cabin = cabin;
|
||||||
|
Runway = runway;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
AircraftCarrier/AircraftCarrier/Form1.Designer.cs
generated
39
AircraftCarrier/AircraftCarrier/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace AircraftCarrier
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace AircraftCarrier
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
194
AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs
generated
Normal file
194
AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs
generated
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
partial class FormAircraftCarrier
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
buttonUp = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
ButtonCreateAircraftCarrier = new Button();
|
||||||
|
ButtonCreateAircraft = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStep = new Button();
|
||||||
|
buttonSelectAircraft = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(1033, 724);
|
||||||
|
pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBox.TabIndex = 0;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
pictureBox.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = Properties.Resources.Icon_Up;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(942, 637);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 2;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = Properties.Resources.Icon_Left;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(906, 673);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 3;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = Properties.Resources.Icon_Down;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(942, 673);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 4;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = Properties.Resources.Icon_Right;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(978, 673);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 5;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// ButtonCreateAircraftCarrier
|
||||||
|
//
|
||||||
|
ButtonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ButtonCreateAircraftCarrier.Location = new Point(234, 664);
|
||||||
|
ButtonCreateAircraftCarrier.Name = "ButtonCreateAircraftCarrier";
|
||||||
|
ButtonCreateAircraftCarrier.Size = new Size(204, 39);
|
||||||
|
ButtonCreateAircraftCarrier.TabIndex = 6;
|
||||||
|
ButtonCreateAircraftCarrier.Text = "Создать военный корабль";
|
||||||
|
ButtonCreateAircraftCarrier.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCreateAircraftCarrier.Click += ButtonCreateAircraftCarrier_Click;
|
||||||
|
//
|
||||||
|
// ButtonCreateAircraft
|
||||||
|
//
|
||||||
|
ButtonCreateAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ButtonCreateAircraft.Location = new Point(12, 664);
|
||||||
|
ButtonCreateAircraft.Name = "ButtonCreateAircraft";
|
||||||
|
ButtonCreateAircraft.Size = new Size(204, 39);
|
||||||
|
ButtonCreateAircraft.TabIndex = 7;
|
||||||
|
ButtonCreateAircraft.Text = "Создать корабль";
|
||||||
|
ButtonCreateAircraft.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCreateAircraft.Click += ButtonCreateAircraft_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
|
comboBoxStrategy.Location = new Point(857, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(151, 28);
|
||||||
|
comboBoxStrategy.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStep.Location = new Point(914, 46);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(94, 29);
|
||||||
|
buttonStep.TabIndex = 9;
|
||||||
|
buttonStep.Text = "Шаг";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStep_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectAircraft
|
||||||
|
//
|
||||||
|
buttonSelectAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonSelectAircraft.Location = new Point(456, 664);
|
||||||
|
buttonSelectAircraft.Name = "buttonSelectAircraft";
|
||||||
|
buttonSelectAircraft.Size = new Size(204, 39);
|
||||||
|
buttonSelectAircraft.TabIndex = 10;
|
||||||
|
buttonSelectAircraft.Text = "Выбрать объект";
|
||||||
|
buttonSelectAircraft.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectAircraft.Click += buttonSelectAircraft_Click;
|
||||||
|
//
|
||||||
|
// FormAircraftCarrier
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1033, 724);
|
||||||
|
Controls.Add(buttonSelectAircraft);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(ButtonCreateAircraft);
|
||||||
|
Controls.Add(ButtonCreateAircraftCarrier);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Name = "FormAircraftCarrier";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "AircraftCarrier";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button ButtonCreateAircraft;
|
||||||
|
private Button ButtonCreateAircraftCarrier;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStep;
|
||||||
|
private Button buttonSelectAircraft;
|
||||||
|
}
|
||||||
|
}
|
132
AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs
Normal file
132
AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
public partial class FormAircraftCarrier : Form
|
||||||
|
{
|
||||||
|
private DrawningAircraft? _drawingAircraft;
|
||||||
|
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawningAircraft? SelectedAircraft { get; private set; }
|
||||||
|
public FormAircraftCarrier()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedAircraft = null;
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingAircraft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawingAircraft.DrawTransport(gr);
|
||||||
|
pictureBox.Image = bmp;
|
||||||
|
}
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingAircraft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawingAircraft.MoveTransport(Direction.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawingAircraft.MoveTransport(Direction.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawingAircraft.MoveTransport(Direction.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawingAircraft.MoveTransport(Direction.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonCreateAircraft_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingAircraft = new DrawningAircraft(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color, pictureBox.Width, pictureBox.Height);
|
||||||
|
_drawingAircraft.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
_drawingAircraft = new DrawningAircraftCarrier(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), pictureBox.Width, pictureBox.Height);
|
||||||
|
_drawingAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingAircraft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(_drawingAircraft.GetMoveableObject,
|
||||||
|
pictureBox.Width, pictureBox.Height);
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonSelectAircraft_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAircraft = _drawingAircraft;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
|
|
||||||
Version 2.0
|
Version 2.0
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
The primary goals of this format is to allow a simple XML format
|
||||||
that is mostly human readable. The generation and parsing of the
|
that is mostly human readable. The generation and parsing of the
|
||||||
various data types are done through the TypeConverter classes
|
various data types are done through the TypeConverter classes
|
||||||
associated with the data types.
|
associated with the data types.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
... ado.net/XML headers & schema ...
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
<resheader name="version">2.0</resheader>
|
<resheader name="version">2.0</resheader>
|
||||||
@ -26,36 +26,36 @@
|
|||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
<comment>This is a comment</comment>
|
<comment>This is a comment</comment>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
There are any number of "resheader" rows that contain simple
|
||||||
name/value pairs.
|
name/value pairs.
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
Each data row contains a name, and value. The row also contains a
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
text/value conversion through the TypeConverter architecture.
|
text/value conversion through the TypeConverter architecture.
|
||||||
Classes that don't support this are serialized and stored with the
|
Classes that don't support this are serialized and stored with the
|
||||||
mimetype set.
|
mimetype set.
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
The mimetype is used for serialized objects, and tells the
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
read any of the formats listed below.
|
read any of the formats listed below.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
value : The object must be serialized into a byte array
|
value : The object must be serialized into a byte array
|
||||||
: using a System.ComponentModel.TypeConverter
|
: using a System.ComponentModel.TypeConverter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
-->
|
-->
|
209
AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs
generated
Normal file
209
AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs
generated
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
partial class FormAircraftCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
PanelTools = new Panel();
|
||||||
|
labelTools = new Label();
|
||||||
|
PanelSets = new Panel();
|
||||||
|
ButtonRemoveObject = new Button();
|
||||||
|
listBoxStorage = new ListBox();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
labelSets = new Label();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
ButtonRemoveAircraft = new Button();
|
||||||
|
MaskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
ButtonAddAircraft = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
PanelTools.SuspendLayout();
|
||||||
|
PanelSets.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(793, 724);
|
||||||
|
pictureBoxCollection.TabIndex = 0;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// PanelTools
|
||||||
|
//
|
||||||
|
PanelTools.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
PanelTools.Controls.Add(labelTools);
|
||||||
|
PanelTools.Controls.Add(PanelSets);
|
||||||
|
PanelTools.Controls.Add(ButtonRefreshCollection);
|
||||||
|
PanelTools.Controls.Add(ButtonRemoveAircraft);
|
||||||
|
PanelTools.Controls.Add(MaskedTextBoxNumber);
|
||||||
|
PanelTools.Controls.Add(ButtonAddAircraft);
|
||||||
|
PanelTools.Location = new Point(799, 12);
|
||||||
|
PanelTools.Name = "PanelTools";
|
||||||
|
PanelTools.Size = new Size(232, 712);
|
||||||
|
PanelTools.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelTools
|
||||||
|
//
|
||||||
|
labelTools.AutoSize = true;
|
||||||
|
labelTools.Location = new Point(16, -4);
|
||||||
|
labelTools.Name = "labelTools";
|
||||||
|
labelTools.Size = new Size(103, 20);
|
||||||
|
labelTools.TabIndex = 5;
|
||||||
|
labelTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// PanelSets
|
||||||
|
//
|
||||||
|
PanelSets.Controls.Add(ButtonRemoveObject);
|
||||||
|
PanelSets.Controls.Add(listBoxStorage);
|
||||||
|
PanelSets.Controls.Add(ButtonAddObject);
|
||||||
|
PanelSets.Controls.Add(textBoxStorageName);
|
||||||
|
PanelSets.Controls.Add(labelSets);
|
||||||
|
PanelSets.Location = new Point(16, 37);
|
||||||
|
PanelSets.Name = "PanelSets";
|
||||||
|
PanelSets.Size = new Size(204, 339);
|
||||||
|
PanelSets.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// ButtonRemoveObject
|
||||||
|
//
|
||||||
|
ButtonRemoveObject.Location = new Point(20, 286);
|
||||||
|
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
||||||
|
ButtonRemoveObject.Size = new Size(168, 41);
|
||||||
|
ButtonRemoveObject.TabIndex = 4;
|
||||||
|
ButtonRemoveObject.Text = "Удалить набор";
|
||||||
|
ButtonRemoveObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveObject.Click += ButtonRemoveObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorage
|
||||||
|
//
|
||||||
|
listBoxStorage.FormattingEnabled = true;
|
||||||
|
listBoxStorage.ItemHeight = 20;
|
||||||
|
listBoxStorage.Location = new Point(29, 147);
|
||||||
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
|
listBoxStorage.Size = new Size(150, 124);
|
||||||
|
listBoxStorage.TabIndex = 3;
|
||||||
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(20, 83);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(168, 41);
|
||||||
|
ButtonAddObject.TabIndex = 2;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(41, 41);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(125, 27);
|
||||||
|
textBoxStorageName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelSets
|
||||||
|
//
|
||||||
|
labelSets.AutoSize = true;
|
||||||
|
labelSets.Location = new Point(11, 9);
|
||||||
|
labelSets.Name = "labelSets";
|
||||||
|
labelSets.Size = new Size(55, 20);
|
||||||
|
labelSets.TabIndex = 0;
|
||||||
|
labelSets.Text = "Набор";
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(36, 572);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(168, 41);
|
||||||
|
ButtonRefreshCollection.TabIndex = 3;
|
||||||
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveAircraft
|
||||||
|
//
|
||||||
|
ButtonRemoveAircraft.Location = new Point(36, 497);
|
||||||
|
ButtonRemoveAircraft.Name = "ButtonRemoveAircraft";
|
||||||
|
ButtonRemoveAircraft.Size = new Size(168, 41);
|
||||||
|
ButtonRemoveAircraft.TabIndex = 2;
|
||||||
|
ButtonRemoveAircraft.Text = "Удалить судно";
|
||||||
|
ButtonRemoveAircraft.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveAircraft.Click += ButtonRemoveAircraft_Click;
|
||||||
|
//
|
||||||
|
// MaskedTextBoxNumber
|
||||||
|
//
|
||||||
|
MaskedTextBoxNumber.Location = new Point(57, 438);
|
||||||
|
MaskedTextBoxNumber.Name = "MaskedTextBoxNumber";
|
||||||
|
MaskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
|
MaskedTextBoxNumber.TabIndex = 1;
|
||||||
|
MaskedTextBoxNumber.Text = "_";
|
||||||
|
//
|
||||||
|
// ButtonAddAircraft
|
||||||
|
//
|
||||||
|
ButtonAddAircraft.Location = new Point(36, 391);
|
||||||
|
ButtonAddAircraft.Name = "ButtonAddAircraft";
|
||||||
|
ButtonAddAircraft.Size = new Size(168, 41);
|
||||||
|
ButtonAddAircraft.TabIndex = 0;
|
||||||
|
ButtonAddAircraft.Text = "Добавить судно";
|
||||||
|
ButtonAddAircraft.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||||
|
//
|
||||||
|
// FormAircraftCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1033, 724);
|
||||||
|
Controls.Add(PanelTools);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormAircraftCollection";
|
||||||
|
Text = "FormAircraftCollection";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
PanelTools.ResumeLayout(false);
|
||||||
|
PanelTools.PerformLayout();
|
||||||
|
PanelSets.ResumeLayout(false);
|
||||||
|
PanelSets.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private Panel PanelTools;
|
||||||
|
private MaskedTextBox MaskedTextBoxNumber;
|
||||||
|
private Button ButtonAddAircraft;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private Button ButtonRemoveAircraft;
|
||||||
|
private Panel PanelSets;
|
||||||
|
private Label labelTools;
|
||||||
|
private Label labelSets;
|
||||||
|
private Button ButtonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private Button ButtonRemoveObject;
|
||||||
|
private ListBox listBoxStorage;
|
||||||
|
}
|
||||||
|
}
|
145
AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs
Normal file
145
AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
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 AircraftCarrier.DrawningObjects;
|
||||||
|
using AircraftCarrier.Generics;
|
||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
public partial class FormAircraftCollection : Form
|
||||||
|
{
|
||||||
|
private readonly AircraftsGenericStorage _storage;
|
||||||
|
public FormAircraftCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new AircraftsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorage.SelectedIndex;
|
||||||
|
listBoxStorage.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowAircrafts();
|
||||||
|
}
|
||||||
|
private void ButtonRemoveObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект{listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddAircraft_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var formMonorailConfig = new FormAircraftConfig();
|
||||||
|
formMonorailConfig.AddEvent(AddAircraft);
|
||||||
|
formMonorailConfig.Show();
|
||||||
|
}
|
||||||
|
private void AddAircraft(DrawningAircraft aircraft)
|
||||||
|
{
|
||||||
|
aircraft._pictureHeight = pictureBoxCollection.Height;
|
||||||
|
aircraft._pictureWidth = pictureBoxCollection.Width;
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj + aircraft != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveAircraft_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(MaskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AircraftCarrier/AircraftCarrier/FormAircraftCollection.resx
Normal file
120
AircraftCarrier/AircraftCarrier/FormAircraftCollection.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>
|
355
AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs
generated
Normal file
355
AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs
generated
Normal file
@ -0,0 +1,355 @@
|
|||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
partial class FormAircraftConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBoxParameters = new GroupBox();
|
||||||
|
panelColor = new Panel();
|
||||||
|
panelRed = new Panel();
|
||||||
|
panelPurple = new Panel();
|
||||||
|
panelGreen = new Panel();
|
||||||
|
panelBlack = new Panel();
|
||||||
|
panelGray = new Panel();
|
||||||
|
panelBlue = new Panel();
|
||||||
|
panelYellow = new Panel();
|
||||||
|
panelWhite = new Panel();
|
||||||
|
labelHardObject = new Label();
|
||||||
|
labelSimpleObject = new Label();
|
||||||
|
checkBoxCabin = new CheckBox();
|
||||||
|
checkBoxRunWay = new CheckBox();
|
||||||
|
numericUpDownWeight = new NumericUpDown();
|
||||||
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
|
label_Weight = new Label();
|
||||||
|
label_Speed = new Label();
|
||||||
|
pictureBoxObject = new PictureBox();
|
||||||
|
panelObject = new Panel();
|
||||||
|
labelAdditionalColor = new Label();
|
||||||
|
labelMainColor = new Label();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
groupBoxParameters.SuspendLayout();
|
||||||
|
panelColor.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||||
|
panelObject.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxParameters
|
||||||
|
//
|
||||||
|
groupBoxParameters.Controls.Add(panelColor);
|
||||||
|
groupBoxParameters.Controls.Add(labelHardObject);
|
||||||
|
groupBoxParameters.Controls.Add(labelSimpleObject);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxCabin);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxRunWay);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownWeight);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownSpeed);
|
||||||
|
groupBoxParameters.Controls.Add(label_Weight);
|
||||||
|
groupBoxParameters.Controls.Add(label_Speed);
|
||||||
|
groupBoxParameters.Location = new Point(12, 7);
|
||||||
|
groupBoxParameters.Name = "groupBoxParameters";
|
||||||
|
groupBoxParameters.Size = new Size(549, 304);
|
||||||
|
groupBoxParameters.TabIndex = 0;
|
||||||
|
groupBoxParameters.TabStop = false;
|
||||||
|
groupBoxParameters.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// panelColor
|
||||||
|
//
|
||||||
|
panelColor.Controls.Add(panelRed);
|
||||||
|
panelColor.Controls.Add(panelPurple);
|
||||||
|
panelColor.Controls.Add(panelGreen);
|
||||||
|
panelColor.Controls.Add(panelBlack);
|
||||||
|
panelColor.Controls.Add(panelGray);
|
||||||
|
panelColor.Controls.Add(panelBlue);
|
||||||
|
panelColor.Controls.Add(panelYellow);
|
||||||
|
panelColor.Controls.Add(panelWhite);
|
||||||
|
panelColor.Location = new Point(282, 55);
|
||||||
|
panelColor.Name = "panelColor";
|
||||||
|
panelColor.Size = new Size(250, 140);
|
||||||
|
panelColor.TabIndex = 10;
|
||||||
|
panelColor.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
panelRed.BackColor = Color.Red;
|
||||||
|
panelRed.Location = new Point(15, 14);
|
||||||
|
panelRed.Name = "panelRed";
|
||||||
|
panelRed.Size = new Size(38, 44);
|
||||||
|
panelRed.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
panelPurple.BackColor = Color.Purple;
|
||||||
|
panelPurple.Location = new Point(195, 83);
|
||||||
|
panelPurple.Name = "panelPurple";
|
||||||
|
panelPurple.Size = new Size(38, 44);
|
||||||
|
panelPurple.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
panelGreen.BackColor = Color.Lime;
|
||||||
|
panelGreen.Location = new Point(73, 14);
|
||||||
|
panelGreen.Name = "panelGreen";
|
||||||
|
panelGreen.Size = new Size(38, 44);
|
||||||
|
panelGreen.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
panelBlack.BackColor = Color.Black;
|
||||||
|
panelBlack.Location = new Point(137, 83);
|
||||||
|
panelBlack.Name = "panelBlack";
|
||||||
|
panelBlack.Size = new Size(38, 44);
|
||||||
|
panelBlack.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
panelGray.BackColor = Color.Gray;
|
||||||
|
panelGray.Location = new Point(73, 83);
|
||||||
|
panelGray.Name = "panelGray";
|
||||||
|
panelGray.Size = new Size(38, 44);
|
||||||
|
panelGray.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
panelBlue.BackColor = Color.Blue;
|
||||||
|
panelBlue.Location = new Point(137, 14);
|
||||||
|
panelBlue.Name = "panelBlue";
|
||||||
|
panelBlue.Size = new Size(38, 44);
|
||||||
|
panelBlue.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
panelYellow.BackColor = Color.Yellow;
|
||||||
|
panelYellow.Location = new Point(195, 14);
|
||||||
|
panelYellow.Name = "panelYellow";
|
||||||
|
panelYellow.Size = new Size(38, 44);
|
||||||
|
panelYellow.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
panelWhite.BackColor = Color.White;
|
||||||
|
panelWhite.Location = new Point(15, 83);
|
||||||
|
panelWhite.Name = "panelWhite";
|
||||||
|
panelWhite.Size = new Size(38, 44);
|
||||||
|
panelWhite.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelHardObject
|
||||||
|
//
|
||||||
|
labelHardObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelHardObject.Location = new Point(419, 228);
|
||||||
|
labelHardObject.Name = "labelHardObject";
|
||||||
|
labelHardObject.Size = new Size(113, 41);
|
||||||
|
labelHardObject.TabIndex = 9;
|
||||||
|
labelHardObject.Text = "Продвинутый";
|
||||||
|
labelHardObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelHardObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleObject.Location = new Point(297, 228);
|
||||||
|
labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
labelSimpleObject.Size = new Size(113, 41);
|
||||||
|
labelSimpleObject.TabIndex = 8;
|
||||||
|
labelSimpleObject.Text = "Простой";
|
||||||
|
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// checkBoxCabin
|
||||||
|
//
|
||||||
|
checkBoxCabin.AutoSize = true;
|
||||||
|
checkBoxCabin.Location = new Point(18, 245);
|
||||||
|
checkBoxCabin.Name = "checkBoxCabin";
|
||||||
|
checkBoxCabin.Size = new Size(258, 24);
|
||||||
|
checkBoxCabin.TabIndex = 5;
|
||||||
|
checkBoxCabin.Text = "Обозначение рубки управления";
|
||||||
|
checkBoxCabin.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxRunWay
|
||||||
|
//
|
||||||
|
checkBoxRunWay.AutoSize = true;
|
||||||
|
checkBoxRunWay.Location = new Point(18, 189);
|
||||||
|
checkBoxRunWay.Name = "checkBoxRunWay";
|
||||||
|
checkBoxRunWay.Size = new Size(251, 24);
|
||||||
|
checkBoxRunWay.TabIndex = 4;
|
||||||
|
checkBoxRunWay.Text = "Обозначение взлетной полосы";
|
||||||
|
checkBoxRunWay.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
numericUpDownWeight.Location = new Point(117, 109);
|
||||||
|
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(87, 27);
|
||||||
|
numericUpDownWeight.TabIndex = 3;
|
||||||
|
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
numericUpDownSpeed.Location = new Point(117, 53);
|
||||||
|
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(87, 27);
|
||||||
|
numericUpDownSpeed.TabIndex = 2;
|
||||||
|
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label_Weight
|
||||||
|
//
|
||||||
|
label_Weight.AutoSize = true;
|
||||||
|
label_Weight.Location = new Point(18, 111);
|
||||||
|
label_Weight.Name = "label_Weight";
|
||||||
|
label_Weight.Size = new Size(36, 20);
|
||||||
|
label_Weight.TabIndex = 1;
|
||||||
|
label_Weight.Text = "Вес:";
|
||||||
|
//
|
||||||
|
// label_Speed
|
||||||
|
//
|
||||||
|
label_Speed.AutoSize = true;
|
||||||
|
label_Speed.Location = new Point(18, 55);
|
||||||
|
label_Speed.Name = "label_Speed";
|
||||||
|
label_Speed.Size = new Size(76, 20);
|
||||||
|
label_Speed.TabIndex = 0;
|
||||||
|
label_Speed.Text = "Скорость:";
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
pictureBoxObject.Location = new Point(30, 55);
|
||||||
|
pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
pictureBoxObject.Size = new Size(249, 169);
|
||||||
|
pictureBoxObject.TabIndex = 1;
|
||||||
|
pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
panelObject.AllowDrop = true;
|
||||||
|
panelObject.Controls.Add(labelAdditionalColor);
|
||||||
|
panelObject.Controls.Add(labelMainColor);
|
||||||
|
panelObject.Controls.Add(pictureBoxObject);
|
||||||
|
panelObject.Location = new Point(567, 21);
|
||||||
|
panelObject.Name = "panelObject";
|
||||||
|
panelObject.Size = new Size(303, 242);
|
||||||
|
panelObject.TabIndex = 2;
|
||||||
|
panelObject.DragDrop += PanelObject_DragDrop;
|
||||||
|
panelObject.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// labelAdditionalColor
|
||||||
|
//
|
||||||
|
labelAdditionalColor.AllowDrop = true;
|
||||||
|
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAdditionalColor.Location = new Point(167, 13);
|
||||||
|
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||||
|
labelAdditionalColor.Size = new Size(112, 39);
|
||||||
|
labelAdditionalColor.TabIndex = 3;
|
||||||
|
labelAdditionalColor.Text = "Доп. Цвет";
|
||||||
|
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
|
||||||
|
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||||
|
//
|
||||||
|
// labelMainColor
|
||||||
|
//
|
||||||
|
labelMainColor.AllowDrop = true;
|
||||||
|
labelMainColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelMainColor.Location = new Point(30, 12);
|
||||||
|
labelMainColor.Name = "labelMainColor";
|
||||||
|
labelMainColor.Size = new Size(113, 39);
|
||||||
|
labelMainColor.TabIndex = 2;
|
||||||
|
labelMainColor.Text = "Цвет";
|
||||||
|
labelMainColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelMainColor.DragDrop += labelMainColor_DragDrop;
|
||||||
|
labelMainColor.DragEnter += labelColor_DragEnter;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(597, 282);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(113, 29);
|
||||||
|
buttonAdd.TabIndex = 3;
|
||||||
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(734, 282);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(112, 29);
|
||||||
|
buttonCancel.TabIndex = 4;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormAircraftConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(882, 323);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(panelObject);
|
||||||
|
Controls.Add(groupBoxParameters);
|
||||||
|
Name = "FormAircraftConfig";
|
||||||
|
Text = "FormAircraftConfig";
|
||||||
|
groupBoxParameters.ResumeLayout(false);
|
||||||
|
groupBoxParameters.PerformLayout();
|
||||||
|
panelColor.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||||
|
panelObject.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxParameters;
|
||||||
|
private Label label_Weight;
|
||||||
|
private Label label_Speed;
|
||||||
|
private CheckBox checkBoxCabin;
|
||||||
|
private CheckBox checkBoxRunWay;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Label labelHardObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Panel panelObject;
|
||||||
|
private Label labelAdditionalColor;
|
||||||
|
private Label labelMainColor;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Panel panelColor;
|
||||||
|
private Panel panelRed;
|
||||||
|
}
|
||||||
|
}
|
128
AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs
Normal file
128
AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
using AircraftCarrier.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
public partial class FormAircraftConfig : Form
|
||||||
|
{
|
||||||
|
/// Переменная-выбранная машина
|
||||||
|
DrawningAircraft? _Aircraft = null;
|
||||||
|
/// Событие
|
||||||
|
private event Action<DrawningAircraft>? EventAddAircraft;
|
||||||
|
/// Конструктор
|
||||||
|
public FormAircraftConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += panelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += panelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += panelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += panelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += panelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += panelColor_MouseDown;
|
||||||
|
|
||||||
|
buttonCancel.Click += (s, e) => Close();
|
||||||
|
}
|
||||||
|
public void AddEvent(Action<DrawningAircraft> ev)
|
||||||
|
{
|
||||||
|
if (EventAddAircraft == null)
|
||||||
|
{
|
||||||
|
EventAddAircraft = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddAircraft += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawAircraft()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_Aircraft?.SetPosition(5, 5);
|
||||||
|
_Aircraft?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
/// Передаем информацию при нажатии на Label
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_Aircraft = new DrawningAircraft((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||||
|
pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
case "labelHardObject":
|
||||||
|
_Aircraft = new DrawningAircraftCarrier((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRunWay.Checked,
|
||||||
|
checkBoxCabin.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawAircraft();
|
||||||
|
}
|
||||||
|
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
|
||||||
|
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_Aircraft == null)
|
||||||
|
return;
|
||||||
|
_Aircraft.EntityAircraft.BodyColor = (Color)e.Data?.GetData(typeof(Color));
|
||||||
|
DrawAircraft();
|
||||||
|
}
|
||||||
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_Aircraft == null || _Aircraft is not DrawningAircraftCarrier)
|
||||||
|
return;
|
||||||
|
((EntityAircraftCarrier)_Aircraft.EntityAircraft).AdditionalColor = (Color)e.Data?.GetData(typeof(Color));
|
||||||
|
DrawAircraft();
|
||||||
|
}
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddAircraft?.Invoke(_Aircraft);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AircraftCarrier/AircraftCarrier/FormAircraftConfig.resx
Normal file
120
AircraftCarrier/AircraftCarrier/FormAircraftConfig.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>
|
22
AircraftCarrier/AircraftCarrier/IMoveableObject.cs
Normal file
22
AircraftCarrier/AircraftCarrier/IMoveableObject.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AircraftCarrier.DrawningObjects;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// Получение координаты X объекта
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
/// Шаг объекта
|
||||||
|
int GetStep { get; }
|
||||||
|
/// Проверка, можно ли переместиться по нужному направлению
|
||||||
|
bool CheckCanMove(Direction direction);
|
||||||
|
/// Изменение направления пермещения объекта
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
}
|
||||||
|
}
|
25
AircraftCarrier/AircraftCarrier/MoveToBorder.cs
Normal file
25
AircraftCarrier/AircraftCarrier/MoveToBorder.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using AircraftCarrier.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
internal class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return false;
|
||||||
|
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return;
|
||||||
|
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
||||||
|
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
AircraftCarrier/AircraftCarrier/MoveToCenter.cs
Normal file
55
AircraftCarrier/AircraftCarrier/MoveToCenter.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
AircraftCarrier/AircraftCarrier/ObjectParameters.cs
Normal file
39
AircraftCarrier/AircraftCarrier/ObjectParameters.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
/// Левая граница
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
/// Верхняя граница
|
||||||
|
public int TopBorder => _y;
|
||||||
|
/// Правая граница
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
/// Нижняя граница
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
/// Середина объекта
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
/// Середина объекта
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
/// Конструктор
|
||||||
|
/// <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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,16 +2,14 @@ namespace AircraftCarrier
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
Application.Run(new FormAircraftCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
103
AircraftCarrier/AircraftCarrier/Properties/Resources.Designer.cs
generated
Normal file
103
AircraftCarrier/AircraftCarrier/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace AircraftCarrier.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AircraftCarrier.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Icon_Down {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Icon_Down", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Icon_Left {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Icon_Left", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Icon_Right {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Icon_Right", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Icon_Up {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Icon_Up", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
133
AircraftCarrier/AircraftCarrier/Properties/Resources.resx
Normal file
133
AircraftCarrier/AircraftCarrier/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?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>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="Icon_Down" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Icon_Down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon_Left" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Icon_Left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon_Right" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Icon_Right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Icon_Up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Down.png
Normal file
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Left.png
Normal file
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Right.png
Normal file
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Up.png
Normal file
BIN
AircraftCarrier/AircraftCarrier/Resources/Icon_Up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
75
AircraftCarrier/AircraftCarrier/SetGeneric.cs
Normal file
75
AircraftCarrier/AircraftCarrier/SetGeneric.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.Generics
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// Список объектов, которые храним
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
public int Count => _places.Count;
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
private readonly int _maxCount;
|
||||||
|
/// Конструктор
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
public int Insert(T Aircraft)
|
||||||
|
{
|
||||||
|
return Insert(Aircraft, 0);
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
public int Insert(T Aircraft, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
_places.Insert(position, Aircraft);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return false;
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Проход по списку
|
||||||
|
public IEnumerable<T?> GetAircrafts(int? maxAircrafts = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxAircrafts.HasValue && i == maxAircrafts.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
AircraftCarrier/AircraftCarrier/Status.cs
Normal file
14
AircraftCarrier/AircraftCarrier/Status.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AircraftCarrier.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user