Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de8bd02d0f |
@@ -1,107 +0,0 @@
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 120;
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 110;
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота онка
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Коллекция автомобилей
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningAircraft>? _collection = null;
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция автомобилей</param>
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAircraft> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="aircraft">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningAircraft aircraft)
|
||||
{
|
||||
return company._collection?.Insert(aircraft) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удлаяемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningAircraft? GetRandomObject()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics g = Graphics.FromImage(bitmap);
|
||||
DrawBackGround(g);
|
||||
|
||||
SetObjectPosition(g);
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
DrawningAircraft? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(g);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
protected abstract void DrawBackGround(Graphics g);
|
||||
protected abstract void SetObjectPosition(Graphics g);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
public class AircraftSharingService : AbstractCompany
|
||||
{
|
||||
public AircraftSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAircraft> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
private int? _startPosX;
|
||||
private int? _startPosY;
|
||||
private int? ObjPositionX;
|
||||
private int? ObjPositionY;
|
||||
|
||||
private void DrawPlace(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, _placeSizeWidth, _placeSizeHeight);
|
||||
}
|
||||
|
||||
private void DrawPosition(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 2, 2);
|
||||
}
|
||||
protected override void DrawBackGround(Graphics g)
|
||||
{
|
||||
_startPosX = 0;
|
||||
_startPosY = 0;
|
||||
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
|
||||
{
|
||||
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
|
||||
{
|
||||
for (int y = 0; y <= _pictureHeight; y = y + _placeSizeHeight)
|
||||
{
|
||||
if ((_pictureHeight - _placeSizeHeight) > _startPosY)
|
||||
{
|
||||
DrawPlace(g);
|
||||
_startPosY = _startPosY + _placeSizeHeight;
|
||||
}
|
||||
}
|
||||
_startPosX = _startPosX + _placeSizeWidth;
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition(Graphics g)
|
||||
{
|
||||
_startPosX = 5;
|
||||
_startPosY = 5;
|
||||
int i = 0;
|
||||
|
||||
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
|
||||
{
|
||||
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
|
||||
{
|
||||
ObjPositionX = _startPosX;
|
||||
|
||||
for (int y = 0; y <= _pictureHeight; y = y + _placeSizeHeight)
|
||||
{
|
||||
if ((_pictureHeight - _placeSizeHeight) > _startPosY)
|
||||
{
|
||||
ObjPositionY = _startPosY;
|
||||
if (i < (_collection?.Count))
|
||||
{
|
||||
DrawningAircraft obj = _collection.Get(i);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
obj.SetpictureSize(_pictureWidth, _pictureHeight);
|
||||
obj.SetPosition(Convert.ToInt32(ObjPositionX), Convert.ToInt32(ObjPositionY));
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
_startPosY = _startPosY + _placeSizeHeight;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
_startPosX = _startPosX + _placeSizeWidth;
|
||||
|
||||
_startPosY = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"> Параметр : ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка прошла не успешно</returns>
|
||||
bool Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка прошла не успешно</returns>
|
||||
bool Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло успешно, false - удаление прошло не успешно</returns>
|
||||
bool Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : Ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _massive;
|
||||
public int Count => _massive.Length;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _massive = new T?[value]; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_massive = Array.Empty<T>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _massive[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
int index = 0;
|
||||
while (_massive[index] != null)
|
||||
{
|
||||
index++;
|
||||
if (index == Count) { return true; } // false?
|
||||
}
|
||||
|
||||
while (index != 0)
|
||||
{
|
||||
_massive[index] = _massive[index - 1];
|
||||
index--;
|
||||
}
|
||||
_massive[0] = obj;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_massive[position] == null)
|
||||
{
|
||||
_massive[position] = obj;
|
||||
return true;
|
||||
}
|
||||
int index = position;
|
||||
while (_massive[index] != null) index++;
|
||||
if (index == Count) return false;
|
||||
for (int i = index; i > position; i--)
|
||||
{
|
||||
_massive[i] = _massive[i - 1];
|
||||
}
|
||||
_massive[position] = obj;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return false;
|
||||
_massive[position] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,37 +4,32 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
namespace ProectMilitaryAircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Навравление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
Up =1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
Down =2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
Left =3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4,
|
||||
Right =4,
|
||||
|
||||
}
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
public class DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityAircraft? EntityAircraft { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прописовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координа прорисовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningMilitaryAircraftWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawingMilitaryAircraftHeight = 110;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Координа Х
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningMilitaryAircraftWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawingMilitaryAircraftHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAircraft()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Констуктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningMilitaryAircraftWidth">Ширина прорисовки самолета</param>
|
||||
/// <param name="drawingMilitaryAircraftHeight">Высота прорисовки самолета</param>
|
||||
|
||||
protected DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height, int drawningMilitaryAircraftWidth, int drawingMilitaryAircraftHeight) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_drawningMilitaryAircraftWidth = drawningMilitaryAircraftWidth;
|
||||
_drawingMilitaryAircraftHeight = drawingMilitaryAircraftHeight;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width"> Ширина поля</param>
|
||||
/// <param name="height"> Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetpictureSize(int width, int height)
|
||||
{
|
||||
if (width <= _drawningMilitaryAircraftWidth || height <= _drawingMilitaryAircraftHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата Х</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x > _pictureWidth || x < 0 || y > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAircraft.Step > 0)
|
||||
{
|
||||
if (_startPosX - 50 <= _pictureWidth)
|
||||
_startPosX -= (int)EntityAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAircraft.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
|
||||
if (_startPosX.Value + _drawningMilitaryAircraftWidth + EntityAircraft.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAircraft.Step;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
|
||||
if (_startPosY.Value + _drawingMilitaryAircraftHeight + EntityAircraft.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAircraft.Step;
|
||||
}
|
||||
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush br = new SolidBrush(EntityAircraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за отрисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Констуктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Доп. цвет</param>
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
|
||||
public DrawningMilitaryAircraft(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism, int width, int height) :base (speed, weight, bodyColor, width, height,120, 110)
|
||||
{
|
||||
if (EntityAircraft != null)
|
||||
{
|
||||
EntityAircraft = new EntityMilitaryAircraft(speed, weight, bodyColor, additionalColor, pin, rokets, symbolism);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraft is not EntityMilitaryAircraft airCraft || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush abr = new SolidBrush(airCraft.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//Ракеты
|
||||
if (airCraft.Rokets)
|
||||
{
|
||||
//Ракеты 1-3
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
|
||||
|
||||
//Ракеты 4-6
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
}
|
||||
|
||||
if (airCraft.Symbolism)
|
||||
{
|
||||
//Символ
|
||||
g.FillEllipse(abr, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillRectangle(abr, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
}
|
||||
|
||||
if (airCraft.Pin)
|
||||
{
|
||||
//Носовая часть
|
||||
g.FillEllipse(abr, _startPosX.Value + 78, _startPosY.Value + 37, 10, 5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProectMilitaryAircraft;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за отрисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityMilitaryAircraft? EntityMilitaryAircraft { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прописовки самолета
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координа прорисовки самолета
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningMilitaryAircraftWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawingMilitaryAircraftHeight = 110;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Доп. цвет</param>
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism)
|
||||
{
|
||||
EntityMilitaryAircraft = new EntityMilitaryAircraft();
|
||||
EntityMilitaryAircraft.Init(speed, weight, bodyColor, additionalColor, pin, rokets, symbolism);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width"> Ширина поля</param>
|
||||
/// <param name="height"> Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetpictureSize(int width, int height)
|
||||
{
|
||||
if (width <= _drawningMilitaryAircraftWidth || height <= _drawingMilitaryAircraftHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата Х</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition (int x, int y)
|
||||
{
|
||||
int endx = x + _drawningMilitaryAircraftWidth;
|
||||
|
||||
int endy = y + _drawingMilitaryAircraftHeight;
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (endx > _pictureWidth || x < 0 || endy > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityMilitaryAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(direction)
|
||||
{
|
||||
//Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityMilitaryAircraft.Step > 0)
|
||||
{
|
||||
if (_startPosX -50 <= _pictureWidth)
|
||||
_startPosX -= (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityMilitaryAircraft.Step > 0)
|
||||
{
|
||||
_startPosY -= (int) EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityMilitaryAircraft.Step <= _pictureWidth.Value)
|
||||
{
|
||||
if (_startPosX + 98 <= _pictureWidth)
|
||||
_startPosX += (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityMilitaryAircraft.Step <= _pictureHeight.Value)
|
||||
{
|
||||
if (_startPosY + 90 <= _pictureHeight)
|
||||
_startPosY += (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMilitaryAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush abr = new SolidBrush(EntityMilitaryAircraft.AdditionalColor);
|
||||
Brush br = new SolidBrush(EntityMilitaryAircraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value +25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value +40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
//Ракеты
|
||||
|
||||
if (EntityMilitaryAircraft.Rokets)
|
||||
{
|
||||
//Ракеты 1-3
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
|
||||
|
||||
//Ракеты 4-6
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
}
|
||||
|
||||
if (EntityMilitaryAircraft.Symbolism)
|
||||
{
|
||||
//Символ
|
||||
g.FillEllipse(abr, _startPosX.Value +15, _startPosY.Value +35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillRectangle(abr, _startPosX.Value + 30, _startPosY.Value +35, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
}
|
||||
|
||||
if (EntityMilitaryAircraft.Pin)
|
||||
{
|
||||
//Носовая часть
|
||||
g.FillEllipse(abr, _startPosX.Value + 78, _startPosY.Value + 37, 10, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Entities;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Cамолет"
|
||||
/// </summary>
|
||||
public class EntityAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
namespace ProectMilitaryAircraft.Entities;
|
||||
namespace ProectMilitaryAircraft;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный самолет"
|
||||
/// </summary>
|
||||
public class EntityMilitaryAircraft : EntityAircraft
|
||||
public class EntityMilitaryAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get;private set; }
|
||||
/// <summary>
|
||||
/// Доп. цвет
|
||||
/// </summary>
|
||||
@@ -11,7 +23,7 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия "Штыря на носу самолета"
|
||||
/// </summary>
|
||||
public bool Pin { get; private set; }
|
||||
public bool Pin { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия "Ракет"
|
||||
/// </summary>
|
||||
@@ -21,6 +33,14 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// </summary>
|
||||
public bool Symbolism { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// </summary>
|
||||
public double Step
|
||||
{
|
||||
get { return Speed * 100 / Weight; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -31,8 +51,11 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
public EntityMilitaryAircraft(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism) :base(speed, weight, bodyColor)
|
||||
public void Init( int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism )
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Pin = pin;
|
||||
Rokets = rokets;
|
||||
@@ -1,173 +0,0 @@
|
||||
namespace ProectMilitaryAircraft
|
||||
{
|
||||
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()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveAircraft = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddMilitaryAircraft = new Button();
|
||||
buttonAddAircraft = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveAircraft);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddMilitaryAircraft);
|
||||
groupBoxTools.Controls.Add(buttonAddAircraft);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(607, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(194, 563);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = " Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 450);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(182, 45);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(6, 299);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(182, 45);
|
||||
buttonGoToCheck.TabIndex = 4;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveAircraft
|
||||
//
|
||||
buttonRemoveAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveAircraft.Location = new Point(6, 208);
|
||||
buttonRemoveAircraft.Name = "buttonRemoveAircraft";
|
||||
buttonRemoveAircraft.Size = new Size(182, 45);
|
||||
buttonRemoveAircraft.TabIndex = 3;
|
||||
buttonRemoveAircraft.Text = " Удалить самолет";
|
||||
buttonRemoveAircraft.UseVisualStyleBackColor = true;
|
||||
buttonRemoveAircraft.Click += ButtonRemoveAircraft_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 179);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(182, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddMilitaryAircraft
|
||||
//
|
||||
buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMilitaryAircraft.Location = new Point(6, 112);
|
||||
buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft";
|
||||
buttonAddMilitaryAircraft.Size = new Size(182, 45);
|
||||
buttonAddMilitaryAircraft.TabIndex = 2;
|
||||
buttonAddMilitaryAircraft.Text = "Добавление военного самолета";
|
||||
buttonAddMilitaryAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddMilitaryAircraft.Click += ButtonAddMilitaryAircraft_Click;
|
||||
//
|
||||
// buttonAddAircraft
|
||||
//
|
||||
buttonAddAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAircraft.Location = new Point(6, 70);
|
||||
buttonAddAircraft.Name = "buttonAddAircraft";
|
||||
buttonAddAircraft.Size = new Size(182, 36);
|
||||
buttonAddAircraft.TabIndex = 1;
|
||||
buttonAddAircraft.Text = "Добавление самолета";
|
||||
buttonAddAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 22);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(182, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedValueChanged += ComboBoxSelectorCompany_SelectedValueChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(607, 563);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormAircraftCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(801, 563);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormAircraftCollection";
|
||||
Text = "Коллекция самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddMilitaryAircraft;
|
||||
private Button buttonAddAircraft;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRemoveAircraft;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
using ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
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 ProectMilitaryAircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и её коллекцией
|
||||
/// </summary>
|
||||
public partial class FormAircraftCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormAircraftCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObj(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random rnd = new();
|
||||
DrawningAircraft drawningAircraft;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraft):
|
||||
drawningAircraft = new DrawningAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), pictureBox.Width, pictureBox.Height);
|
||||
|
||||
break;
|
||||
|
||||
case nameof(DrawningMilitaryAircraft):
|
||||
drawningAircraft = new DrawningMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + drawningAircraft)
|
||||
{
|
||||
MessageBox.Show("Не удалось добаить объект");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
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;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление обычного самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAircraft_Click(object sender, EventArgs e) => CreateObj(nameof(DrawningAircraft));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление военного самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddMilitaryAircraft_Click(object sender, EventArgs e) => CreateObj(nameof(DrawningMilitaryAircraft));
|
||||
|
||||
/// <summary>
|
||||
/// Удаление самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveAircraft_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передать на тесты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningAircraft? aircraft = null;
|
||||
int counter = 100;
|
||||
while(aircraft == null)
|
||||
{
|
||||
aircraft = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (aircraft == null) { return; }
|
||||
|
||||
FormMilitaryAircraft form = new()
|
||||
{
|
||||
SetAircraft = aircraft
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?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>
|
||||
@@ -29,12 +29,11 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxMilitaryAircraft = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMilitaryAircraft).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -43,10 +42,21 @@
|
||||
pictureBoxMilitaryAircraft.Dock = DockStyle.Fill;
|
||||
pictureBoxMilitaryAircraft.Location = new Point(0, 0);
|
||||
pictureBoxMilitaryAircraft.Name = "pictureBoxMilitaryAircraft";
|
||||
pictureBoxMilitaryAircraft.Size = new Size(893, 612);
|
||||
pictureBoxMilitaryAircraft.Size = new Size(1108, 499);
|
||||
pictureBoxMilitaryAircraft.TabIndex = 0;
|
||||
pictureBoxMilitaryAircraft.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 464);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@@ -54,7 +64,7 @@
|
||||
buttonLeft.BackgroundImage = Properties.Resources.Left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonLeft.Location = new Point(764, 571);
|
||||
buttonLeft.Location = new Point(979, 458);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
@@ -68,7 +78,7 @@
|
||||
buttonUp.BackgroundImage = Properties.Resources.Up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonUp.Location = new Point(805, 530);
|
||||
buttonUp.Location = new Point(1020, 417);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
@@ -82,7 +92,7 @@
|
||||
buttonRight.BackgroundImage = Properties.Resources.Right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonRight.Location = new Point(846, 571);
|
||||
buttonRight.Location = new Point(1061, 458);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 4;
|
||||
@@ -96,46 +106,23 @@
|
||||
buttonDown.BackgroundImage = Properties.Resources.Down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonDown.Location = new Point(805, 571);
|
||||
buttonDown.Location = new Point(1020, 458);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.UseVisualStyleBackColor = false;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К ценру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(763, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStrategyStep.Location = new Point(810, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormMilitaryAircraft
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(893, 612);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
ClientSize = new Size(1108, 499);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxMilitaryAircraft);
|
||||
Name = "FormMilitaryAircraft";
|
||||
Text = "Военный самолет";
|
||||
@@ -146,11 +133,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxMilitaryAircraft;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
||||
@@ -7,62 +7,48 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
namespace ProectMilitaryAircraft
|
||||
{
|
||||
public partial class FormMilitaryAircraft : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAircraft? _DrawningAircraft;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategys? _AbstractStrategy;
|
||||
|
||||
|
||||
public DrawningAircraft SetAircraft
|
||||
{
|
||||
set
|
||||
{
|
||||
_DrawningAircraft = value;
|
||||
_DrawningAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_AbstractStrategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
private DrawningMilitaryAircraft? _DrawningMilitaryAircraft;
|
||||
public FormMilitaryAircraft()
|
||||
{
|
||||
InitializeComponent();
|
||||
_AbstractStrategy = null;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
if (_DrawningMilitaryAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_DrawningAircraft.DrawTransport(gr);
|
||||
_DrawningMilitaryAircraft.DrawTransport(gr);
|
||||
pictureBoxMilitaryAircraft.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_DrawningMilitaryAircraft = new DrawningMilitaryAircraft();
|
||||
_DrawningMilitaryAircraft.Init(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
_DrawningMilitaryAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
_DrawningMilitaryAircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
if (_DrawningMilitaryAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -70,64 +56,26 @@ namespace ProectMilitaryAircraft
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
|
||||
switch (name)
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Up);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Down);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Left);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Right);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_AbstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_AbstractStrategy == null) { return; }
|
||||
|
||||
_AbstractStrategy.SetData(new MoveableAircraft(_DrawningAircraft), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
}
|
||||
|
||||
if (_AbstractStrategy == null) { return; }
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_AbstractStrategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_AbstractStrategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_AbstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// класс - стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategys
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObjects? _moveableObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемеения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObjects">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObjects moveableObjects, int width, int height)
|
||||
{
|
||||
if(moveableObjects == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObjects = moveableObjects;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTrgetDestansion())
|
||||
{
|
||||
_state |= StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение Вверх
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение Вниз
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObjects?.GetObjectPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObjects?.GetStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTrgetDestansion();
|
||||
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObjects?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction"> Направление</param>
|
||||
/// <returns>true - Объект перемещен, false - перемещение невозможно-v</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategys
|
||||
{
|
||||
protected override bool IsTrgetDestansion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategys
|
||||
{
|
||||
protected override bool IsTrgetDestansion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if(objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleVertical +GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс - реалицация IMoveableObjects с использованием DrawningAircraft
|
||||
/// </summary>
|
||||
public class MoveableAircraft : IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле - объект класса DrawningAircraft или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningAircraft? _Air = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="Air">Объект класса DrawningAircraft</param>
|
||||
public MoveableAircraft(DrawningAircraft Air)
|
||||
{
|
||||
_Air = Air;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Air == null || _Air.EntityAircraft == null || !_Air.GetPosX.HasValue || !_Air.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_Air.GetPosX.Value, _Air.GetPosY.Value, _Air.GetWidth, _Air.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_Air?.EntityAircraft?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if(_Air == null || _Air.EntityAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _Air.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum MovementDirection
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
///Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4,
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Параметры - координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата Х
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Середнина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _height / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace ProectMilitaryAircraft
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAircraftCollection());
|
||||
Application.Run(new FormMilitaryAircraft());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user