Лабораторная работа №3
This commit is contained in:
parent
adb2f3668b
commit
fa5d91263c
@ -0,0 +1,107 @@
|
||||
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);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackGround(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition(Graphics g)
|
||||
{
|
||||
for(int i = 0; i < _collection?.Count; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
@ -29,7 +28,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка прошла не успешно</returns>
|
||||
bool Insert (T obj);
|
||||
bool Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@ -44,12 +43,12 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло успешно, false - удаление прошло не успешно</returns>
|
||||
bool Remove (int position);
|
||||
bool Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get (int position);
|
||||
T? Get(int position);
|
||||
}
|
||||
|
@ -1,60 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
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
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
{
|
||||
/// <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()
|
||||
/// <typeparam name="T">Параметр : Ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
_massive = Array.Empty<T>();
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
//TODO Проверка позиции
|
||||
return _massive[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
//TODO Проверка позиции
|
||||
//TODO проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой позиции
|
||||
// и идет вставка туда, если нет после, ищем до
|
||||
//TODO Вставка
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
//TODO Проверка позиции
|
||||
//TODO Удаление объекта из массива, просвоив элементу массива значение null
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
173
ProectMilitaryAircraft/ProectMilitaryAircraft/FormAircraftCollection.Designer.cs
generated
Normal file
173
ProectMilitaryAircraft/ProectMilitaryAircraft/FormAircraftCollection.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -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()
|
||||
{
|
||||
pictureBoxMilitaryAircraft = new PictureBox();
|
||||
buttonCreateMA = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateA = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMilitaryAircraft).BeginInit();
|
||||
@ -49,17 +47,6 @@
|
||||
pictureBoxMilitaryAircraft.TabIndex = 0;
|
||||
pictureBoxMilitaryAircraft.TabStop = false;
|
||||
//
|
||||
// buttonCreateMA
|
||||
//
|
||||
buttonCreateMA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateMA.Location = new Point(12, 616);
|
||||
buttonCreateMA.Name = "buttonCreateMA";
|
||||
buttonCreateMA.Size = new Size(172, 23);
|
||||
buttonCreateMA.TabIndex = 1;
|
||||
buttonCreateMA.Text = "Создать военный самолет";
|
||||
buttonCreateMA.UseVisualStyleBackColor = true;
|
||||
buttonCreateMA.Click += ButtonCreateMA_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -116,17 +103,6 @@
|
||||
buttonDown.UseVisualStyleBackColor = false;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateA
|
||||
//
|
||||
buttonCreateA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateA.Location = new Point(199, 616);
|
||||
buttonCreateA.Name = "buttonCreateA";
|
||||
buttonCreateA.Size = new Size(172, 23);
|
||||
buttonCreateA.TabIndex = 6;
|
||||
buttonCreateA.Text = "Создать самолет";
|
||||
buttonCreateA.UseVisualStyleBackColor = true;
|
||||
buttonCreateA.Click += ButtonCreateA_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@ -156,12 +132,10 @@
|
||||
ClientSize = new Size(953, 651);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateA);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateMA);
|
||||
Controls.Add(pictureBoxMilitaryAircraft);
|
||||
Name = "FormMilitaryAircraft";
|
||||
Text = "Военный самолет";
|
||||
@ -172,12 +146,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxMilitaryAircraft;
|
||||
private Button buttonCreateMA;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateA;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
@ -25,6 +25,19 @@ namespace ProectMilitaryAircraft
|
||||
/// </summary>
|
||||
private AbstractStrategys? _AbstractStrategy;
|
||||
|
||||
|
||||
public DrawningAircraft SetAircraft
|
||||
{
|
||||
set
|
||||
{
|
||||
_DrawningAircraft = value;
|
||||
_DrawningAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_AbstractStrategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
|
@ -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 FormMilitaryAircraft());
|
||||
Application.Run(new FormAircraftCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user