ISEbd-11_Sharonov_I.A.Lab03_Simple #3

Closed
357Sharonov wants to merge 2 commits from Lab03 into Lab02
10 changed files with 847 additions and 78 deletions

View File

@ -0,0 +1,115 @@
using ProjectSeaplane.Drawnings;
namespace ProjectSeaplane.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 180;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 100;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция cамолетов
/// </summary>
protected ICollectionGenericObjects<DrawingBasicSeaplane>? _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<DrawingBasicSeaplane> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="seaplane">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawingBasicSeaplane seaplane)
{
return company._collection.Insert(seaplane);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawingBasicSeaplane operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawingBasicSeaplane? 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)
{
DrawingBasicSeaplane? 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();
}

View File

@ -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);
}

View File

@ -0,0 +1,120 @@
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)
{
// TODO проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
// TODO вставка в свободное место набора
int index = 0;
Review

Правильнее было вызвать Insert(T obj, 0);

Правильнее было вызвать Insert(T obj, 0);
while (index < _collection.Length)
{
if (_collection[index] == null)
{
_collection[index] = obj;
return index;
}
index++;
}
return -1;
}
public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
if (position >= _collection.Length || position < 0)
{
return -1;
}
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
int index;
for (index = position + 1; index < _collection.Length; ++index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
for (index = position - 1; index >= 0; --index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
return -1;
}
public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= _collection.Length || position < 0)
{
return null;
}
T obj = _collection[position];
_collection[position] = null;
return obj;
}
}

View File

@ -0,0 +1,59 @@
using ProjectSeaplane.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectSeaplane.CollectionGenericObjects;
public class PlanePark : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public PlanePark(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBasicSeaplane> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
int width = _pictureWidth - 1;
int height = _pictureHeight / 2;
Pen pen = new(Color.RosyBrown, 3);
g.DrawLine(pen, width, height, 5, height);
g.DrawLine(pen, width, height - 100, 5, height - 100);
Pen pen2 = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth; i+=50)
{
g.DrawLine(pen2, width-i, height - 50, width - (i+30), height -50);
}
}
protected override void SetObjectsPosition()
{
int count = 0;
int megacount = 0;
for (int y = _pictureHeight - 100; y - 50 > 0; y -= 100)
{
megacount++;
if (y < _pictureHeight / 2 && y > (_pictureHeight / 2) - 100)
{
y -= 200;
}
for (int x = _pictureWidth - 200; x - 120 > 0; x -= _placeSizeHeight + 75)
{
_collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(count)?.SetPosition(x, y);
count++;
}
}
}
}

View File

@ -0,0 +1,178 @@
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();
buttonDelSeaplane = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddSeaplane = new Button();
buttonAddBasicSeaplane = new Button();
СomboBoxSelectorCompany = 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(buttonDelSeaplane);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddSeaplane);
groupBoxTools.Controls.Add(buttonAddBasicSeaplane);
groupBoxTools.Controls.Add(СomboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(854, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(180, 398);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.FlatStyle = FlatStyle.Flat;
buttonRefresh.Location = new Point(6, 474);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(168, 43);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.FlatStyle = FlatStyle.Flat;
buttonGoToCheck.Location = new Point(6, 353);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(168, 43);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonDelSeaplane
//
buttonDelSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelSeaplane.FlatStyle = FlatStyle.Flat;
buttonDelSeaplane.Location = new Point(6, 249);
buttonDelSeaplane.Name = "buttonDelSeaplane";
buttonDelSeaplane.Size = new Size(168, 43);
buttonDelSeaplane.TabIndex = 4;
buttonDelSeaplane.Text = "Удалить самолет";
buttonDelSeaplane.UseVisualStyleBackColor = true;
buttonDelSeaplane.Click += ButtonnDelSeaplane_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 220);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(168, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddSeaplane
//
buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddSeaplane.FlatStyle = FlatStyle.Flat;
buttonAddSeaplane.Location = new Point(6, 135);
buttonAddSeaplane.Name = "buttonAddSeaplane";
buttonAddSeaplane.Size = new Size(168, 43);
buttonAddSeaplane.TabIndex = 2;
buttonAddSeaplane.Text = "Добавление гидросамолета";
buttonAddSeaplane.UseVisualStyleBackColor = true;
buttonAddSeaplane.Click += ButtonAddSeaplane_Click;
//
// buttonAddBasicSeaplane
//
buttonAddBasicSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBasicSeaplane.FlatStyle = FlatStyle.Flat;
buttonAddBasicSeaplane.Location = new Point(6, 86);
buttonAddBasicSeaplane.Name = "buttonAddBasicSeaplane";
buttonAddBasicSeaplane.Size = new Size(168, 43);
buttonAddBasicSeaplane.TabIndex = 1;
buttonAddBasicSeaplane.Text = "Добавление самолета";
buttonAddBasicSeaplane.UseVisualStyleBackColor = true;
buttonAddBasicSeaplane.Click += ButtonAddBasicSeaplane_Click;
//
// СomboBoxSelectorCompany
//
СomboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
СomboBoxSelectorCompany.FormattingEnabled = true;
СomboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
СomboBoxSelectorCompany.Location = new Point(6, 22);
СomboBoxSelectorCompany.Name = "СomboBoxSelectorCompany";
СomboBoxSelectorCompany.Size = new Size(168, 23);
СomboBoxSelectorCompany.TabIndex = 0;
СomboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(854, 398);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1034, 398);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormPlaneCollection";
Text = "Коллекция самолетов";
Load += FormPlaneCollection_Load;
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private Button buttonAddBasicSeaplane;
private ComboBox СomboBoxSelectorCompany;
private Button buttonAddSeaplane;
private Button buttonGoToCheck;
private Button buttonDelSeaplane;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonRefresh;
}
}

View File

@ -0,0 +1,193 @@
using ProjectSeaplane.CollectionGenericObjects;
using ProjectSeaplane.Drawnings;
namespace ProjectSeaplane;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormPlaneCollection : Form
{
/// <summary>
/// Компания
/// </summary>
AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormPlaneCollection()
{
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (СomboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new PlanePark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingBasicSeaplane>());
break;
}
}
/// <summary>
/// Добавление обычного самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBasicSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBasicSeaplane));
/// <summary>
/// Добавление гидросамолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSeaplane));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawingBasicSeaplane drawingBasicSeaplane;
switch (type)
{
case nameof(DrawingBasicSeaplane):
drawingBasicSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawingSeaplane):
// TODO вызов диалогового окна для выбора цвета
drawingBasicSeaplane = new DrawingSeaplane(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 + drawingBasicSeaplane != -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 ButtonnDelSeaplane_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.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;
}
DrawingBasicSeaplane? seaplane = null;
int counter = 100;
while (seaplane == null)
{
seaplane = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (seaplane == null)
{
return;
}
FormSeaplane form = new()
{
SetSeaplane = seaplane
};
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();
}
private void FormPlaneCollection_Load(object sender, EventArgs e)
{
}
}

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>

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxSeaplane = new PictureBox();
ButtonCreateSeaplane = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonUp = new Button();
buttonRight = new Button();
ButtonCreateBasicSeaplane = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
@ -49,17 +47,6 @@
pictureBoxSeaplane.TabIndex = 0;
pictureBoxSeaplane.TabStop = false;
//
// ButtonCreateSeaplane
//
ButtonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateSeaplane.Location = new Point(12, 349);
ButtonCreateSeaplane.Name = "ButtonCreateSeaplane";
ButtonCreateSeaplane.Size = new Size(256, 23);
ButtonCreateSeaplane.TabIndex = 1;
ButtonCreateSeaplane.Text = "Создать гидросамолет с обвесами";
ButtonCreateSeaplane.UseVisualStyleBackColor = true;
ButtonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -112,17 +99,6 @@
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
// ButtonCreateBasicSeaplane
//
ButtonCreateBasicSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBasicSeaplane.Location = new Point(288, 349);
ButtonCreateBasicSeaplane.Name = "ButtonCreateBasicSeaplane";
ButtonCreateBasicSeaplane.Size = new Size(234, 23);
ButtonCreateBasicSeaplane.TabIndex = 8;
ButtonCreateBasicSeaplane.Text = "Создать гидросамолет без обвесов";
ButtonCreateBasicSeaplane.UseVisualStyleBackColor = true;
ButtonCreateBasicSeaplane.Click += ButtonCreateBasicSeaplane_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -150,12 +126,10 @@
ClientSize = new Size(757, 379);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(ButtonCreateBasicSeaplane);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(ButtonCreateSeaplane);
Controls.Add(pictureBoxSeaplane);
Name = "FormSeaplane";
Text = "Гидросамолет";
@ -166,12 +140,10 @@
#endregion
private PictureBox pictureBoxSeaplane;
private Button ButtonCreateSeaplane;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private Button ButtonCreateBasicSeaplane;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -27,6 +27,17 @@ namespace ProjectSeaplane
/// <summary>
/// Метод прорисовки самолета
/// </summary>
public DrawingBasicSeaplane SetSeaplane
{
set
{
_drawingSeaplane = value;
_drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
private void Draw()
{
if (_drawingSeaplane == null)
@ -39,54 +50,7 @@ namespace ProjectSeaplane
_drawingSeaplane.DrawTransport(gr);
pictureBoxSeaplane.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawingBasicSeaplane):
_drawingSeaplane = new DrawingBasicSeaplane(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(DrawingSeaplane):
_drawingSeaplane = new DrawingSeaplane(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;
}
_drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
_drawingSeaplane.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(DrawingSeaplane));
}
/// <summary>
/// Обработка нажатия кнопки "Создать гидросамолет без обвесов"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateBasicSeaplane_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingBasicSeaplane));
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
@ -163,7 +127,7 @@ namespace ProjectSeaplane
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace ProjectSeaplane
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormSeaplane());
Application.Run(new FormPlaneCollection());
}
}
}