лаба 3!!!!!!!

This commit is contained in:
a.puchkina 2023-10-24 23:36:05 +04:00
parent d4c53d0543
commit e9aede7e6e
9 changed files with 673 additions and 47 deletions

View File

@ -38,6 +38,7 @@
buttonCreateAirplaneWithRadar = new Button();
buttonStep = new Button();
comboBoxStrategy = new ComboBox();
buttonSelectAirplane = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirplane).BeginInit();
SuspendLayout();
//
@ -45,8 +46,9 @@
//
pictureBoxAirplane.Dock = DockStyle.Fill;
pictureBoxAirplane.Location = new Point(0, 0);
pictureBoxAirplane.Margin = new Padding(4, 4, 4, 4);
pictureBoxAirplane.Name = "pictureBoxAirplane";
pictureBoxAirplane.Size = new Size(882, 453);
pictureBoxAirplane.Size = new Size(1102, 566);
pictureBoxAirplane.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxAirplane.TabIndex = 0;
pictureBoxAirplane.TabStop = false;
@ -54,9 +56,10 @@
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 412);
buttonCreate.Location = new Point(15, 515);
buttonCreate.Margin = new Padding(4, 4, 4, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29);
buttonCreate.Size = new Size(118, 36);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
@ -67,9 +70,10 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.Up;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(798, 375);
buttonUp.Location = new Point(998, 469);
buttonUp.Margin = new Padding(4, 4, 4, 4);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.Size = new Size(38, 38);
buttonUp.TabIndex = 2;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
@ -79,9 +83,10 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(762, 411);
buttonLeft.Location = new Point(952, 514);
buttonLeft.Margin = new Padding(4, 4, 4, 4);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.Size = new Size(38, 38);
buttonLeft.TabIndex = 3;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
@ -91,9 +96,10 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(834, 411);
buttonRight.Location = new Point(1042, 514);
buttonRight.Margin = new Padding(4, 4, 4, 4);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.Size = new Size(38, 38);
buttonRight.TabIndex = 4;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
@ -103,9 +109,10 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(798, 411);
buttonDown.Location = new Point(998, 514);
buttonDown.Margin = new Padding(4, 4, 4, 4);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.Size = new Size(38, 38);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
@ -113,9 +120,10 @@
// buttonCreateAirplaneWithRadar
//
buttonCreateAirplaneWithRadar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAirplaneWithRadar.Location = new Point(112, 411);
buttonCreateAirplaneWithRadar.Location = new Point(140, 514);
buttonCreateAirplaneWithRadar.Margin = new Padding(4, 4, 4, 4);
buttonCreateAirplaneWithRadar.Name = "buttonCreateAirplaneWithRadar";
buttonCreateAirplaneWithRadar.Size = new Size(198, 30);
buttonCreateAirplaneWithRadar.Size = new Size(248, 38);
buttonCreateAirplaneWithRadar.TabIndex = 6;
buttonCreateAirplaneWithRadar.Text = "Создать с дополнениями";
buttonCreateAirplaneWithRadar.UseVisualStyleBackColor = true;
@ -124,9 +132,10 @@
// buttonStep
//
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStep.Location = new Point(788, 34);
buttonStep.Location = new Point(985, 42);
buttonStep.Margin = new Padding(4, 4, 4, 4);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.Size = new Size(118, 36);
buttonStep.TabIndex = 7;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
@ -138,16 +147,28 @@
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "в центр", "к гарнице" });
comboBoxStrategy.Location = new Point(731, 0);
comboBoxStrategy.Location = new Point(914, 0);
comboBoxStrategy.Margin = new Padding(4, 4, 4, 4);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.Size = new Size(188, 33);
comboBoxStrategy.TabIndex = 8;
//
// buttonSelectAirplane
//
buttonSelectAirplane.Location = new Point(483, 515);
buttonSelectAirplane.Name = "buttonSelectAirplane";
buttonSelectAirplane.Size = new Size(222, 34);
buttonSelectAirplane.TabIndex = 9;
buttonSelectAirplane.Text = "Выбрать самолет";
buttonSelectAirplane.UseVisualStyleBackColor = true;
buttonSelectAirplane.Click += buttonSelectAirplane_Click;
//
// AirplaneWithRadarForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453);
ClientSize = new Size(1102, 566);
Controls.Add(buttonSelectAirplane);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep);
Controls.Add(buttonCreateAirplaneWithRadar);
@ -157,6 +178,7 @@
Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxAirplane);
Margin = new Padding(4, 4, 4, 4);
Name = "AirplaneWithRadarForm";
StartPosition = FormStartPosition.CenterScreen;
Text = "AirplaneWithRadarForm";
@ -176,5 +198,6 @@
private Button buttonCreateAirplaneWithRadar;
private Button buttonStep;
private ComboBox comboBoxStrategy;
private Button buttonSelectAirplane;
}
}

View File

@ -24,7 +24,11 @@ namespace AirplaneWithRadar
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
/// <summary>
/// Выбранный самолет
/// </summary>
public DrawningAirplane? SelectedAirplane { get; private set; }
/// <summary>
/// Инициализация формы
@ -32,8 +36,9 @@ namespace AirplaneWithRadar
public AirplaneWithRadarForm()
{
InitializeComponent();
_strategy = null;
SelectedAirplane = null;
}
/// <summary>
/// Метод прорисовки самолета
/// </summary>
@ -48,7 +53,6 @@ namespace AirplaneWithRadar
_drawningAirplane.DrawTransport(gr);
pictureBoxAirplane.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать самолет"
/// </summary>
@ -57,25 +61,44 @@ namespace AirplaneWithRadar
private void buttonCreateAirplane_Click(object sender, EventArgs e)
{
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
Color additionalColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
additionalColor = dialog.Color;
}
_drawningAirplane = new DrawningAirplane(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)),
bodyColor, additionalColor,
pictureBoxAirplane.Width, pictureBoxAirplane.Height);
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void buttonCreateAirplaneWithRadar_Click(object sender, EventArgs e)
{
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
Color additionalColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
additionalColor = dialog.Color;
}
_drawningAirplane = new DrawningAirplaneWithRadar(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)),
bodyColor,
additionalColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxAirplane.Width, pictureBoxAirplane.Height);
@ -126,36 +149,42 @@ namespace AirplaneWithRadar
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
_strategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectAirplane(_drawningAirplane), pictureBoxAirplane.Width,
_strategy.SetData(_drawningAirplane.GetMoveableObject, pictureBoxAirplane.Width,
pictureBoxAirplane.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.MakeStep();
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
_strategy = null;
}
}
/// <summary>
/// Выбор самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSelectAirplane_Click(object sender, EventArgs e)
{
SelectedAirplane = _drawningAirplane;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.DrawningObjects;
using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar.Generics
{
/// <summary>
/// Параметризованный класс для набора объектов DrawningAirplane
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class AirplanesGenericCollection<T, U>
where T : DrawningAirplane
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 200;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 85;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public AirplanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(AirplanesGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj) ?? -1;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(AirplanesGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowAirplanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private 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);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
T t = _collection.Get(i);
if (t != null)
{
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
if (t is DrawningAirplane) (t as DrawningAirplane).DrawTransport(g);
else t.DrawTransport(g);
}
}
}
}
}

View File

@ -5,6 +5,7 @@ using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.Entities;
using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar.DrawningObjects
@ -13,6 +14,10 @@ namespace AirplaneWithRadar.DrawningObjects
/// </summary>
public class DrawningAirplane
{
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawningAirplane
/// </summary>
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
/// <summary>
/// Класс-сущность
/// </summary>
@ -60,8 +65,8 @@ namespace AirplaneWithRadar.DrawningObjects
{
return;
}
EntityAirplane = new EntityAirplane(speed, weight, bodyColor, additionalColor);
EntityAirplane = new EntityAirplane(speed, weight, bodyColor,
additionalColor);
}
/// <summary>
/// Конструктор
@ -136,8 +141,6 @@ namespace AirplaneWithRadar.DrawningObjects
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>

View File

@ -0,0 +1,126 @@
namespace AirplaneWithRadar
{
partial class FormAirplaneCollection
{
/// <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()
{
groupBoxInstruments = new GroupBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonUpdate = new Button();
buttonAdd = new Button();
buttonDelete = new Button();
pictureBoxCollection = new PictureBox();
groupBoxInstruments.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// groupBoxInstruments
//
groupBoxInstruments.Controls.Add(maskedTextBoxNumber);
groupBoxInstruments.Controls.Add(buttonUpdate);
groupBoxInstruments.Controls.Add(buttonAdd);
groupBoxInstruments.Controls.Add(buttonDelete);
groupBoxInstruments.Dock = DockStyle.Right;
groupBoxInstruments.Location = new Point(776, 0);
groupBoxInstruments.Name = "groupBoxInstruments";
groupBoxInstruments.Size = new Size(212, 582);
groupBoxInstruments.TabIndex = 5;
groupBoxInstruments.TabStop = false;
groupBoxInstruments.Text = "Инструменты";
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(39, 177);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(148, 31);
maskedTextBoxNumber.TabIndex = 5;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(22, 309);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(178, 62);
buttonUpdate.TabIndex = 4;
buttonUpdate.Text = "Обновить коллекцию";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(22, 66);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(178, 38);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить самолет";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(22, 214);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(178, 38);
buttonDelete.TabIndex = 3;
buttonDelete.Text = "Удалить самолет";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Dock = DockStyle.Fill;
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(776, 582);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxCollection.TabIndex = 6;
pictureBoxCollection.TabStop = false;
//
// FormAirplaneCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(988, 582);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBoxInstruments);
Name = "FormAirplaneCollection";
Text = "FormAirplaneCollection";
groupBoxInstruments.ResumeLayout(false);
groupBoxInstruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonAdd;
private Button buttonUpdate;
private Button buttonDelete;
private GroupBox groupBoxInstruments;
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,89 @@
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;
using AirplaneWithRadar.DrawningObjects;
using AirplaneWithRadar.Generics;
using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar
{
/// <summary>
/// Форма для работы с набором объектов класса DrawningAirplane
/// </summary>
public partial class FormAirplaneCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly AirplanesGenericCollection<DrawningAirplane,
DrawningObjectAirplane> _airplanes;
/// <summary>
/// Конструктор
/// </summary>
public FormAirplaneCollection()
{
InitializeComponent();
_airplanes = new AirplanesGenericCollection<DrawningAirplane,
DrawningObjectAirplane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
AirplaneWithRadarForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_airplanes + form.SelectedAirplane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_airplanes - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonUpdate_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
}
}
}

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

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

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.Generics
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T?[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
_places = new T?[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый самолет</param>
/// <returns></returns>
public int Insert(T airplane)
{
return Insert(airplane, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T airplane, int position)
{
int nullIndex = -1, i;
if (position < 0 || position >= Count)
{
return -1;
}
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0) return -1;
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = airplane;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= Count) return false;
_places[position] = null;
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
{
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}