Compare commits
2 Commits
bc3d9cac6b
...
96ea01165a
Author | SHA1 | Date | |
---|---|---|---|
|
96ea01165a | ||
|
34ea2c9158 |
@ -0,0 +1,123 @@
|
|||||||
|
using ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Абстракция компании, хранящий коллекцию самолётов
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 140;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 60;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция самолётов
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObjects<DrawningPlane>? _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<DrawningPlane> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="plane">Добавляемый объект</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(AbstractCompany company, DrawningPlane plane)
|
||||||
|
{
|
||||||
|
if (company._collection == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return company._collection.Insert(plane);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора удаления для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawningPlane operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
if (company._collection == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return company._collection.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение случайного объекта из коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DrawningPlane? GetRandomObject()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всей коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap? Show()
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
DrawBackgound(graphics);
|
||||||
|
|
||||||
|
SetObjectsPosition();
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
DrawningPlane? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод заднего фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
protected abstract void DrawBackgound(Graphics g);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстановка объектов
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
namespace ProjectSeaplane.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>
|
||||||
|
int Insert(T obj);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
|
T? Remove(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
using ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private T?[] _collection;
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
_collection = Array.Empty<T?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= 0 && position < Count)
|
||||||
|
{
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; ++i)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
for (int i = position; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = position - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Count())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (_collection[position] != null)
|
||||||
|
{
|
||||||
|
T obj = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
using ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация абстрактной компании - плейншеринг
|
||||||
|
/// </summary>
|
||||||
|
public class PlaneSharingService : AbstractCompany
|
||||||
|
{
|
||||||
|
private List<Tuple<int, int>> locCoord = new List<Tuple<int, int>>();
|
||||||
|
private int countInRow;
|
||||||
|
private int countRow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public PlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningPlane>? collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackgound(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new Pen(Color.Brown);
|
||||||
|
int x = 1, y = 0;
|
||||||
|
while (y + _placeSizeHeight <= _pictureHeight)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
while (x + _placeSizeWidth <= _pictureWidth)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
g.DrawLine(pen, x, y, x + _placeSizeWidth, y);
|
||||||
|
g.DrawLine(pen, x, y, x, y + _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, x, y + _placeSizeHeight, x + _placeSizeWidth, y + _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, x + _placeSizeWidth, y + _placeSizeHeight, x + _placeSizeWidth, y);
|
||||||
|
locCoord.Add(new Tuple<int, int>(x, y));
|
||||||
|
x += _placeSizeWidth + 2;
|
||||||
|
}
|
||||||
|
countInRow = count;
|
||||||
|
x = 1;
|
||||||
|
y += _placeSizeHeight + 5;
|
||||||
|
countRow++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
if (locCoord == null || _collection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int row = countRow, col = 1;
|
||||||
|
for (int i = 0; i < _collection?.Count; i++, col++)
|
||||||
|
{
|
||||||
|
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(i)?.SetPosition(locCoord[row * countInRow - col].Item1 + 5, locCoord[row * countInRow - col].Item2 + 5);
|
||||||
|
if (col == countInRow)
|
||||||
|
{
|
||||||
|
col = 0;
|
||||||
|
row--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
173
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
generated
Normal file
173
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
namespace ProjectSeaplane
|
||||||
|
{
|
||||||
|
partial class FormPlaneCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonGoToCheck = new Button();
|
||||||
|
buttonRemovePlane = new Button();
|
||||||
|
maskedTextBoxPosition = new MaskedTextBox();
|
||||||
|
buttonAddSeaplane = new Button();
|
||||||
|
buttonAddPlane = 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(buttonRemovePlane);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddSeaplane);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(710, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(144, 529);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(6, 429);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(126, 44);
|
||||||
|
buttonRefresh.TabIndex = 6;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonGoToCheck.Location = new Point(6, 346);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(126, 44);
|
||||||
|
buttonGoToCheck.TabIndex = 5;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonRemovePlane
|
||||||
|
//
|
||||||
|
buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRemovePlane.Location = new Point(6, 265);
|
||||||
|
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||||
|
buttonRemovePlane.Size = new Size(126, 44);
|
||||||
|
buttonRemovePlane.TabIndex = 4;
|
||||||
|
buttonRemovePlane.Text = "Удалить самолёт";
|
||||||
|
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemovePlane.Click += ButtonRemovePlane_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
maskedTextBoxPosition.Location = new Point(6, 208);
|
||||||
|
maskedTextBoxPosition.Mask = "00";
|
||||||
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
maskedTextBoxPosition.Size = new Size(126, 23);
|
||||||
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonAddSeaplane
|
||||||
|
//
|
||||||
|
buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddSeaplane.Location = new Point(6, 126);
|
||||||
|
buttonAddSeaplane.Name = "buttonAddSeaplane";
|
||||||
|
buttonAddSeaplane.Size = new Size(126, 44);
|
||||||
|
buttonAddSeaplane.TabIndex = 2;
|
||||||
|
buttonAddSeaplane.Text = "Добавление гидросамолёта";
|
||||||
|
buttonAddSeaplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddSeaplane.Click += ButtonAddSeaplane_Click;
|
||||||
|
//
|
||||||
|
// buttonAddPlane
|
||||||
|
//
|
||||||
|
buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddPlane.Location = new Point(6, 78);
|
||||||
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
|
buttonAddPlane.Size = new Size(126, 42);
|
||||||
|
buttonAddPlane.TabIndex = 1;
|
||||||
|
buttonAddPlane.Text = "Добавление самолёта";
|
||||||
|
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddPlane.Click += ButtonAddPlane_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(126, 23);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(710, 529);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormPlaneCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(854, 529);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormPlaneCollection";
|
||||||
|
Text = "Коллекция самолётов";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private Button buttonAddPlane;
|
||||||
|
private Button buttonAddSeaplane;
|
||||||
|
private Button buttonRemovePlane;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
}
|
||||||
|
}
|
186
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
Normal file
186
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
using ProjectSeaplane.CollectionGenericObjects;
|
||||||
|
using ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форма работы с компанией и её коллекцией
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormPlaneCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Компания
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormPlaneCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор компании
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningPlane>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление обычного самолёта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление гидросамолёта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new();
|
||||||
|
DrawningPlane _drawningPlane;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningPlane):
|
||||||
|
_drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningSeaplane):
|
||||||
|
_drawningPlane = new DrawningSeaplane(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
GetColor(random),
|
||||||
|
GetColor(random),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((_company + _drawningPlane) != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение цвета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="random">Генератор случайных чисел</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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 ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
if ((_company - pos) != null)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawningPlane? plane = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (plane == null)
|
||||||
|
{
|
||||||
|
plane = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormSeaplane form = new FormSeaplane();
|
||||||
|
form.SetPlane = plane;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx
Normal file
120
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -29,12 +29,10 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxSeaplane = new PictureBox();
|
pictureBoxSeaplane = new PictureBox();
|
||||||
buttonCreateSeaplane = new Button();
|
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonCreatePlane = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStrategyStep = new Button();
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
|
||||||
@ -45,27 +43,16 @@
|
|||||||
pictureBoxSeaplane.Dock = DockStyle.Fill;
|
pictureBoxSeaplane.Dock = DockStyle.Fill;
|
||||||
pictureBoxSeaplane.Location = new Point(0, 0);
|
pictureBoxSeaplane.Location = new Point(0, 0);
|
||||||
pictureBoxSeaplane.Name = "pictureBoxSeaplane";
|
pictureBoxSeaplane.Name = "pictureBoxSeaplane";
|
||||||
pictureBoxSeaplane.Size = new Size(900, 500);
|
pictureBoxSeaplane.Size = new Size(900, 517);
|
||||||
pictureBoxSeaplane.TabIndex = 0;
|
pictureBoxSeaplane.TabIndex = 0;
|
||||||
pictureBoxSeaplane.TabStop = false;
|
pictureBoxSeaplane.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreateSeaplane
|
|
||||||
//
|
|
||||||
buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateSeaplane.Location = new Point(12, 465);
|
|
||||||
buttonCreateSeaplane.Name = "buttonCreateSeaplane";
|
|
||||||
buttonCreateSeaplane.Size = new Size(196, 23);
|
|
||||||
buttonCreateSeaplane.TabIndex = 1;
|
|
||||||
buttonCreateSeaplane.Text = "Создать гидросамолёт";
|
|
||||||
buttonCreateSeaplane.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
|
|
||||||
//
|
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
|
buttonLeft.BackgroundImage = Properties.Resources.arrow_left;
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonLeft.Location = new Point(768, 451);
|
buttonLeft.Location = new Point(768, 468);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(35, 35);
|
buttonLeft.Size = new Size(35, 35);
|
||||||
buttonLeft.TabIndex = 2;
|
buttonLeft.TabIndex = 2;
|
||||||
@ -77,7 +64,7 @@
|
|||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = Properties.Resources.arrow_up;
|
buttonUp.BackgroundImage = Properties.Resources.arrow_up;
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonUp.Location = new Point(808, 411);
|
buttonUp.Location = new Point(808, 428);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(35, 35);
|
buttonUp.Size = new Size(35, 35);
|
||||||
buttonUp.TabIndex = 3;
|
buttonUp.TabIndex = 3;
|
||||||
@ -89,7 +76,7 @@
|
|||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = Properties.Resources.arrow_down;
|
buttonDown.BackgroundImage = Properties.Resources.arrow_down;
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonDown.Location = new Point(808, 451);
|
buttonDown.Location = new Point(808, 468);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(35, 35);
|
buttonDown.Size = new Size(35, 35);
|
||||||
buttonDown.TabIndex = 4;
|
buttonDown.TabIndex = 4;
|
||||||
@ -101,24 +88,13 @@
|
|||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = Properties.Resources.arrow_right;
|
buttonRight.BackgroundImage = Properties.Resources.arrow_right;
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonRight.Location = new Point(849, 451);
|
buttonRight.Location = new Point(849, 468);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(35, 35);
|
buttonRight.Size = new Size(35, 35);
|
||||||
buttonRight.TabIndex = 5;
|
buttonRight.TabIndex = 5;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreatePlane
|
|
||||||
//
|
|
||||||
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreatePlane.Location = new Point(214, 465);
|
|
||||||
buttonCreatePlane.Name = "buttonCreatePlane";
|
|
||||||
buttonCreatePlane.Size = new Size(196, 23);
|
|
||||||
buttonCreatePlane.TabIndex = 6;
|
|
||||||
buttonCreatePlane.Text = "Создать самолёт";
|
|
||||||
buttonCreatePlane.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreatePlane.Click += ButtonCreatePlane_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
@ -143,15 +119,13 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(900, 500);
|
ClientSize = new Size(900, 517);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreatePlane);
|
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreateSeaplane);
|
|
||||||
Controls.Add(pictureBoxSeaplane);
|
Controls.Add(pictureBoxSeaplane);
|
||||||
Name = "FormSeaplane";
|
Name = "FormSeaplane";
|
||||||
Text = "Гидросамолёт";
|
Text = "Гидросамолёт";
|
||||||
@ -162,12 +136,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxSeaplane;
|
private PictureBox pictureBoxSeaplane;
|
||||||
private Button buttonCreateSeaplane;
|
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonCreatePlane;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using ProjectSeaplane.MovementStrategy;
|
using ProjectSeaplane.MovementStrategy;
|
||||||
|
|
||||||
namespace ProjectSeaplane;
|
namespace ProjectSeaplane;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форма работы с объектом "Спортивный автомобиль"
|
/// Форма работы с объектом "Спортивный автомобиль"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -17,6 +18,21 @@ public partial class FormSeaplane : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _strategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта
|
||||||
|
/// </summary>
|
||||||
|
public DrawningPlane SetPlane
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawningPlane = value;
|
||||||
|
_drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,7 +43,7 @@ public partial class FormSeaplane : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод прорисовки машины
|
/// Метод прорисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
@ -41,51 +57,6 @@ public partial class FormSeaplane : Form
|
|||||||
pictureBoxSeaplane.Image = bmp;
|
pictureBoxSeaplane.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Создание объекта класса-перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">Тип создаваемого объекта</param>
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningPlane):
|
|
||||||
_drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
||||||
break;
|
|
||||||
case nameof(DrawningSeaplane):
|
|
||||||
_drawningPlane = new DrawningSeaplane(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
|
||||||
_drawningPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать гидросамолёт"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать самолёт"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -131,6 +102,7 @@ public partial class FormSeaplane : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comboBoxStrategy.Enabled)
|
if (comboBoxStrategy.Enabled)
|
||||||
{
|
{
|
||||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
@ -145,6 +117,7 @@ public partial class FormSeaplane : Form
|
|||||||
}
|
}
|
||||||
_strategy.SetData(new MoveablePlane(_drawningPlane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
_strategy.SetData(new MoveablePlane(_drawningPlane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_strategy == null)
|
if (_strategy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -11,7 +11,7 @@ namespace ProjectSeaplane
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormSeaplane());
|
Application.Run(new FormPlaneCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user