2 Commits
Lab04 ... Lab05

14 changed files with 878 additions and 217 deletions

View File

@@ -0,0 +1,10 @@
using ProectMilitaryAircraft.Draw;
namespace ProectMilitaryAircraft;
/// <summary>
/// Делегат передачи объекта класса - прорисовки
/// </summary>
/// <param name="aircraft"></param>
public delegate void AircraftDelegate(DrawningAircraft aircraft);

View File

@@ -12,30 +12,83 @@ 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)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
_startPosX = 0;
_startPosY = 0;
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
for (int y = 0; y <= _pictureHeight; y = y + _placeSizeHeight)
{
if ((_pictureHeight - _placeSizeHeight) > _startPosY)
{
DrawPlace(g);
_startPosY = _startPosY + _placeSizeHeight;
}
}
_startPosX = _startPosX + _placeSizeWidth;
_startPosY = 0;
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
protected override void SetObjectPosition(Graphics g)
{
for(int i = 0; i < _collection?.Count; i++)
_startPosX = 5;
_startPosY = 5;
int i = 0;
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
{
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
{
DrawningAircraft airplane = _collection?.Get(i);
if (airplane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
airplane.SetPosition(((inRow - 1 - (i % inRow)) * _placeSizeWidth), ((_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight));
airplane.DrawTransport(g);
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;
}
}
}

View File

@@ -11,13 +11,13 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects;
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр : ограничение - ссылочный тип</typeparam>
public class ListgenericObjects<T>
public class ListgenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Список объектов, которые храниим
/// </summary>
private readonly List<T>? _collection;
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _collection;
/// <summary>
/// Максимально допустимое число объектов в списке
@@ -28,91 +28,51 @@ public class ListgenericObjects<T>
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public CollectionType GetCollectionType => CollectionType.List;
/// <summary>
/// Конструктор
/// </summary>
public ListgenericObjects(int count)
public ListgenericObjects()
{
_maxCount = count;
_collection = new();
}
/// <summary>
/// Получение объекта из набора позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? this[int position]
public T? Get(int position)
{
get
{
if (position < 0 || position >= _maxCount)
{
return null;
}
return _collection?[position];
}
if (position < 0 || position >= Count) return null;
return _collection[position];
set
{
if (!(position >= 0 && position < Count && _collection?.Count < _maxCount))
{
return;
}
_collection?.Insert(position, value);
return;
}
}
public bool Insert(T obj)
{
if (_collection?.Count == _maxCount)
if (Count != _maxCount)
{
return false;
_collection.Add(obj);
return true;
}
Insert(obj, 0);
return true;
return false;
}
public bool Insert(T obj, int position)
{
if (_collection?.Count == _maxCount)
if (position > 0 && position <= _maxCount && Count != _maxCount)
{
return false;
_collection.Insert(position, obj);
return true;
}
Insert(obj, 0);
return true;
return false;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count)
if (_collection[position] != null)
{
return false;
}
_collection?.RemoveAt(position);
return true;
}
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetTheAirplanes(int? maxTheAirplanes = null)
{
for (int i = 0; i < _collection?.Count; ++i)
{
yield return _collection?[i];
if (maxTheAirplanes.HasValue && i == maxTheAirplanes.Value)
{
yield break;
}
_collection.RemoveAt(position);
return true;
}
return false;
}
}

View File

@@ -16,71 +16,103 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _massive;
public int Count => _massive.Length;
private T?[] _collection;
public int SetMaxCount { set { if (value > 0) { _massive = new T?[value]; } } }
public int Count => _collection.Length;
public int SetMaxCount
{
set
{
if (value > 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_massive = Array.Empty<T>();
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
if (position < 0 || position >= Count) return null;
return _massive[position];
if (_collection[position] != null)
{
return _collection[position];
}
else
{
return null;
}
}
public bool Insert(T obj)
{
int index = 0;
while (_massive[index] != null)
for (int i = 0; i < _collection.Length; i++)
{
index++;
if (index == Count) { return true; } // false?
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
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)
if (_collection[position] == null)
{
return false;
}
if (_massive[position] == null)
{
_massive[position] = obj;
_collection[position] = obj;
return true;
}
int index = position;
while (_massive[index] != null) index++;
if (index == Count) return false;
for (int i = index; i > position; i--)
if (_collection[position] != null)
{
_massive[i] = _massive[i - 1];
for (int i = position; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
break;
}
for (int i = position; i <= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
break;
}
}
_massive[position] = obj;
return true;
return false;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count) return false;
_massive[position] = null;
return true;
if (_collection[position] != null)
{
_collection[position] = null;
return true;
}
return false;
}
}
}

View File

@@ -30,7 +30,7 @@ public class StorageCollection<T>
}
if (collectionType == CollectionType.List)
{
_storages.Add(name, new MassiveGenericObjects<T>());
_storages.Add(name, new ListgenericObjects<T>());
}
}

View File

@@ -120,8 +120,10 @@ public class DrawningAircraft
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetpictureSize(int width, int height)
{
// TODO провека, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была установлена
if (width <= _drawningMilitaryAircraftWidth || height <= _drawingMilitaryAircraftHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
return true;
@@ -138,8 +140,12 @@ public class DrawningAircraft
{
return;
}
//TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
if (x > _pictureWidth || x < 0 || y > _pictureHeight || y < 0)
{
x = 0;
y = 0;
}
_startPosX = x;
_startPosY = y;
}
@@ -169,24 +175,21 @@ public class DrawningAircraft
return true;
//Вправо
case DirectionType.Right:
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
if (_startPosX.Value + EntityAircraft.Step <= _pictureWidth.Value)
if (_startPosX.Value + _drawningMilitaryAircraftWidth + EntityAircraft.Step < _pictureWidth)
{
if (_startPosX + 98 <= _pictureWidth)
_startPosX += (int)EntityAircraft.Step;
_startPosX += (int)EntityAircraft.Step;
}
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
return true;
//Влево
case DirectionType.Down:
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
if (_startPosY.Value + EntityAircraft.Step <= _pictureHeight.Value)
if (_startPosY.Value + _drawingMilitaryAircraftHeight + EntityAircraft.Step < _pictureHeight)
{
if (_startPosY + 90 <= _pictureHeight)
_startPosY += (int)EntityAircraft.Step;
_startPosY += (int)EntityAircraft.Step;
}
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
return true;
default:
return false;

View File

@@ -44,33 +44,6 @@ public class DrawningMilitaryAircraft : DrawningAircraft
Pen pen = new(Color.Black);
Brush abr = new SolidBrush(airCraft.AdditionalColor);
Brush br = new SolidBrush(airCraft.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);
base.DrawTransport(g);
//Ракеты

View File

@@ -11,7 +11,12 @@ namespace ProectMilitaryAircraft.Entities;
/// Класс-сущность "Cамолет"
/// </summary>
public class EntityAircraft
{
{
public void SetBodyColor(Color color)
{
BodyColor = color;
}
/// <summary>
/// Скорость
/// </summary>
@@ -24,7 +29,7 @@ public class EntityAircraft
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
public double Step => Speed * 100 / Weight;
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
@@ -38,5 +43,6 @@ public class EntityAircraft
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@@ -4,6 +4,11 @@
/// </summary>
public class EntityMilitaryAircraft : EntityAircraft
{
public void SAdditionalColor(Color color)
{
AdditionalColor = color;
}
/// <summary>
/// Доп. цвет
/// </summary>

View File

@@ -31,7 +31,6 @@
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonAddAircraft = new Button();
buttonAddMilitaryAircraft = new Button();
buttonRefresh = new Button();
maskedTextBox = new MaskedTextBox();
buttonGoToCheck = new Button();
@@ -70,7 +69,6 @@
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddAircraft);
panelCompanyTools.Controls.Add(buttonAddMilitaryAircraft);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonGoToCheck);
@@ -92,17 +90,6 @@
buttonAddAircraft.UseVisualStyleBackColor = true;
buttonAddAircraft.Click += ButtonAddAircraft_Click;
//
// buttonAddMilitaryAircraft
//
buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMilitaryAircraft.Location = new Point(4, 45);
buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft";
buttonAddMilitaryAircraft.Size = new Size(178, 45);
buttonAddMilitaryAircraft.TabIndex = 2;
buttonAddMilitaryAircraft.Text = "Добавление военного самолета";
buttonAddMilitaryAircraft.UseVisualStyleBackColor = true;
buttonAddMilitaryAircraft.Click += ButtonAddMilitaryAircraft_Click;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@@ -280,7 +267,6 @@
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddMilitaryAircraft;
private Button buttonAddAircraft;
private Button buttonRefresh;
private Button buttonGoToCheck;

View File

@@ -48,70 +48,44 @@ public partial class FormAircraftCollection : Form
}
/// <summary>
/// Создание объекта класса-перемещения
/// Добавление самолета
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObj(string type)
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddAircraft_Click(object sender, EventArgs e)
{
if (_company == null)
if (listBoxCollection.SelectedIndex == -1) return;
var obj = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
if (obj == null) return;
FormAircraftConfig form = new();
form.Show();
form.AddEvent(SetAircraft);
}
/// <summary>
/// Добавление самолета в коллекцмю
/// </summary>
/// <param name="aircraft"></param>
private void SetAircraft(DrawningAircraft aircraft)
{
if (_company == null || aircraft == 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
if (_company + aircraft)
{
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)
else
{
color = dialog.Color;
MessageBox.Show("не удалось добавить объект");
}
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>
@@ -261,7 +235,7 @@ public partial class FormAircraftCollection : Form
return;
}
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString()?? string.Empty];
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString()?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллкция не проиницилизирована");
@@ -271,10 +245,12 @@ public partial class FormAircraftCollection : Form
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, collection);
pictureBox.Image = _company.Show();
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
}

View File

@@ -0,0 +1,371 @@
namespace ProectMilitaryAircraft
{
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()
{
groupBoxConfig = new GroupBox();
groupBoxColors = new GroupBox();
panelPurple = new Panel();
panelBlack = new Panel();
panelGray = new Panel();
panelWhite = new Panel();
panelYellow = new Panel();
panelBlue = new Panel();
panelGreen = new Panel();
panelRed = new Panel();
checkBoxSymbolism = new CheckBox();
checkBoxRokets = new CheckBox();
checkBoxPin = new CheckBox();
numericUpDownWeight = new NumericUpDown();
labelWeight = new Label();
numericUpDownSpeed = new NumericUpDown();
labelSpeed = new Label();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
pictureBoxObject = new PictureBox();
buttonAdd = new Button();
buttonCancel = new Button();
panelObject = new Panel();
labelAdditionalColor = new Label();
labelBodyColor = new Label();
groupBoxConfig.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
panelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxConfig
//
groupBoxConfig.Controls.Add(groupBoxColors);
groupBoxConfig.Controls.Add(checkBoxSymbolism);
groupBoxConfig.Controls.Add(checkBoxRokets);
groupBoxConfig.Controls.Add(checkBoxPin);
groupBoxConfig.Controls.Add(numericUpDownWeight);
groupBoxConfig.Controls.Add(labelWeight);
groupBoxConfig.Controls.Add(numericUpDownSpeed);
groupBoxConfig.Controls.Add(labelSpeed);
groupBoxConfig.Controls.Add(labelModifiedObject);
groupBoxConfig.Controls.Add(labelSimpleObject);
groupBoxConfig.Dock = DockStyle.Left;
groupBoxConfig.Location = new Point(0, 0);
groupBoxConfig.Name = "groupBoxConfig";
groupBoxConfig.Size = new Size(496, 314);
groupBoxConfig.TabIndex = 0;
groupBoxConfig.TabStop = false;
groupBoxConfig.Text = "Параметры";
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Location = new Point(308, 32);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(154, 89);
groupBoxColors.TabIndex = 9;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(114, 55);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(30, 27);
panelPurple.TabIndex = 1;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(78, 55);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(30, 27);
panelBlack.TabIndex = 1;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(42, 55);
panelGray.Name = "panelGray";
panelGray.Size = new Size(30, 27);
panelGray.TabIndex = 1;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(6, 55);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(30, 27);
panelWhite.TabIndex = 1;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(114, 22);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(30, 27);
panelYellow.TabIndex = 1;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(78, 22);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(30, 27);
panelBlue.TabIndex = 1;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(42, 22);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(30, 27);
panelGreen.TabIndex = 1;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(6, 22);
panelRed.Name = "panelRed";
panelRed.Size = new Size(30, 27);
panelRed.TabIndex = 0;
//
// checkBoxSymbolism
//
checkBoxSymbolism.AutoSize = true;
checkBoxSymbolism.Location = new Point(6, 155);
checkBoxSymbolism.Name = "checkBoxSymbolism";
checkBoxSymbolism.Size = new Size(200, 19);
checkBoxSymbolism.TabIndex = 8;
checkBoxSymbolism.Text = "Признак наличия \"Символики\"";
checkBoxSymbolism.UseVisualStyleBackColor = true;
//
// checkBoxRokets
//
checkBoxRokets.AutoSize = true;
checkBoxRokets.Location = new Point(6, 130);
checkBoxRokets.Name = "checkBoxRokets";
checkBoxRokets.Size = new Size(166, 19);
checkBoxRokets.TabIndex = 7;
checkBoxRokets.Text = "Признак наличия \"Ракет\"";
checkBoxRokets.UseVisualStyleBackColor = true;
//
// checkBoxPin
//
checkBoxPin.AutoSize = true;
checkBoxPin.Location = new Point(6, 105);
checkBoxPin.Name = "checkBoxPin";
checkBoxPin.Size = new Size(274, 19);
checkBoxPin.TabIndex = 6;
checkBoxPin.Text = "Признак наличия \"Штырь на носу самолета\"";
checkBoxPin.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(74, 58);
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(83, 23);
numericUpDownWeight.TabIndex = 5;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(6, 60);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(29, 15);
labelWeight.TabIndex = 4;
labelWeight.Text = "Вес:";
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(74, 32);
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(83, 23);
numericUpDownSpeed.TabIndex = 3;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(6, 34);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(62, 15);
labelSpeed.TabIndex = 2;
labelSpeed.Text = "Скорость:";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(382, 146);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(100, 34);
labelModifiedObject.TabIndex = 1;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(276, 146);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(100, 34);
labelSimpleObject.TabIndex = 0;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.BorderStyle = BorderStyle.FixedSingle;
pictureBoxObject.Location = new Point(3, 63);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(224, 164);
pictureBoxObject.TabIndex = 1;
pictureBoxObject.TabStop = false;
//
// buttonAdd
//
buttonAdd.Location = new Point(505, 240);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 23);
buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(605, 240);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отменить";
buttonCancel.UseVisualStyleBackColor = true;
//
// panelObject
//
panelObject.AllowDrop = true;
panelObject.Controls.Add(labelAdditionalColor);
panelObject.Controls.Add(labelBodyColor);
panelObject.Controls.Add(pictureBoxObject);
panelObject.Location = new Point(502, 4);
panelObject.Name = "panelObject";
panelObject.Size = new Size(230, 230);
panelObject.TabIndex = 4;
panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(145, 0);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(85, 46);
labelAdditionalColor.TabIndex = 3;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += LabelColor_DragDrop;
labelAdditionalColor.DragEnter += LabelColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(0, 0);
labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(88, 46);
labelBodyColor.TabIndex = 2;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += LabelColor_DragDrop;
labelBodyColor.DragEnter += LabelColor_DragEnter;
//
// FormAircraftConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(810, 314);
Controls.Add(panelObject);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(groupBoxConfig);
Name = "FormAircraftConfig";
Text = "Созданиие объекта";
groupBoxConfig.ResumeLayout(false);
groupBoxConfig.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
panelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private Label labelModifiedObject;
private Label labelSimpleObject;
private NumericUpDown numericUpDownWeight;
private Label labelWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelSpeed;
private CheckBox checkBoxPin;
private CheckBox checkBoxSymbolism;
private CheckBox checkBoxRokets;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
private Panel panelObject;
private Label labelAdditionalColor;
private Label labelBodyColor;
}
}

View File

@@ -0,0 +1,166 @@
using ProectMilitaryAircraft.Draw;
using ProectMilitaryAircraft.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProectMilitaryAircraft;
/// <summary>
/// Форма конфигурации объекта
/// </summary>
public partial class FormAircraftConfig : Form
{
/// <summary>
/// Объект - прорисовка самолета
/// </summary>
private DrawningAircraft? _aircraft;
/// <summary>
/// Событие для передачи объекта
/// </summary>
private event AircraftDelegate? _aircraftDelegate;
/// <summary>
/// Конструктор
/// </summary>
public FormAircraftConfig()
{
InitializeComponent();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelYellow.MouseDown += Panel_MouseDown;
panelWhite.MouseDown += Panel_MouseDown;
panelGray.MouseDown += Panel_MouseDown;
panelBlack.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="aircraftDelegate"></param>
public void AddEvent(AircraftDelegate aircraftDelegate)
{
_aircraftDelegate += aircraftDelegate;
}
/// <summary>
/// Отрисовка объекта
/// </summary>
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_aircraft?.SetpictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_aircraft?.SetPosition(5, 5);
_aircraft?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой инф. (ее типа на соотв. требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
{
case "labelSimpleObject":
_aircraft = new DrawningAircraft((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
break;
case "labelModifiedObject":
_aircraft = new DrawningMilitaryAircraft((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPin.Checked, checkBoxRokets.Checked, checkBoxSymbolism.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawObject();
}
/// <summary>
/// Передаем информацию принажатии на Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
//todo прописать логику смены цветов для продвинутого объекта
/// <summary>
/// Передача объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_aircraft != null)
{
_aircraftDelegate?.Invoke(_aircraft);
Close();
}
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_aircraft == null) return;
switch (((Label)sender).Name)
{
case "labelBodyColor":
_aircraft.EntityAircraft?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (_aircraft == null) return;
(_aircraft.EntityAircraft as EntityMilitaryAircraft)?.SAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawObject();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}

View 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>