ISEbd-22 Alimova M.S. Lab Work 04 #4
@ -274,6 +274,5 @@ namespace AirBomber
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectAirPlane(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
177
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
177
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
@ -29,13 +29,19 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxCollection = new PictureBox();
|
||||
panelTools = new Panel();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemovePlane = new Button();
|
||||
buttonAddPlane = new Button();
|
||||
buttonRemovePlane = new Button();
|
||||
buttonRefreshCollection = new Button();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
groupBoxTools = new GroupBox();
|
||||
groupBoxStorages = new GroupBox();
|
||||
textBoxStorageName = new TextBox();
|
||||
buttonDelObject = new Button();
|
||||
buttonAddObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panelTools.SuspendLayout();
|
||||
groupBoxTools.SuspendLayout();
|
||||
groupBoxStorages.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
@ -44,54 +50,13 @@
|
||||
pictureBoxCollection.Dock = DockStyle.Left;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(708, 548);
|
||||
pictureBoxCollection.Size = new Size(708, 746);
|
||||
pictureBoxCollection.TabIndex = 0;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
panelTools.Controls.Add(maskedTextBoxNumber);
|
||||
panelTools.Controls.Add(buttonRefreshCollection);
|
||||
panelTools.Controls.Add(buttonRemovePlane);
|
||||
panelTools.Controls.Add(buttonAddPlane);
|
||||
panelTools.Dock = DockStyle.Right;
|
||||
panelTools.Location = new Point(719, 0);
|
||||
panelTools.Name = "panelTools";
|
||||
panelTools.Size = new Size(237, 548);
|
||||
panelTools.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(37, 218);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(160, 31);
|
||||
maskedTextBoxNumber.TabIndex = 3;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(37, 394);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(160, 86);
|
||||
buttonRefreshCollection.TabIndex = 2;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
buttonRemovePlane.Location = new Point(37, 266);
|
||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
buttonRemovePlane.Size = new Size(160, 60);
|
||||
buttonRemovePlane.TabIndex = 1;
|
||||
buttonRemovePlane.Text = "Удалить самолет";
|
||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||
buttonRemovePlane.Click += buttonRemovePlane_Click;
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
buttonAddPlane.Location = new Point(37, 94);
|
||||
buttonAddPlane.Location = new Point(76, 417);
|
||||
buttonAddPlane.Name = "buttonAddPlane";
|
||||
buttonAddPlane.Size = new Size(160, 64);
|
||||
buttonAddPlane.TabIndex = 0;
|
||||
@ -99,28 +64,128 @@
|
||||
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||
buttonAddPlane.Click += buttonAddPlane_Click;
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
buttonRemovePlane.Location = new Point(76, 549);
|
||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
buttonRemovePlane.Size = new Size(160, 60);
|
||||
buttonRemovePlane.TabIndex = 1;
|
||||
buttonRemovePlane.Text = "Удалить самолет";
|
||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||
buttonRemovePlane.Click += buttonRemovePlane_Click;
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(76, 648);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(160, 86);
|
||||
buttonRefreshCollection.TabIndex = 2;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(76, 501);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(160, 31);
|
||||
maskedTextBoxNumber.TabIndex = 3;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(groupBoxStorages);
|
||||
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTools.Location = new Point(714, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(305, 746);
|
||||
groupBoxTools.TabIndex = 4;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxStorages
|
||||
//
|
||||
groupBoxStorages.Controls.Add(textBoxStorageName);
|
||||
groupBoxStorages.Controls.Add(buttonDelObject);
|
||||
groupBoxStorages.Controls.Add(buttonAddObject);
|
||||
groupBoxStorages.Controls.Add(listBoxStorages);
|
||||
groupBoxStorages.Location = new Point(5, 30);
|
||||
groupBoxStorages.Name = "groupBoxStorages";
|
||||
groupBoxStorages.Size = new Size(294, 368);
|
||||
groupBoxStorages.TabIndex = 4;
|
||||
groupBoxStorages.TabStop = false;
|
||||
groupBoxStorages.Text = "Наборы";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(6, 54);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(281, 31);
|
||||
textBoxStorageName.TabIndex = 3;
|
||||
//
|
||||
// buttonDelObject
|
||||
//
|
||||
buttonDelObject.Location = new Point(44, 305);
|
||||
buttonDelObject.Name = "buttonDelObject";
|
||||
buttonDelObject.Size = new Size(209, 34);
|
||||
buttonDelObject.TabIndex = 2;
|
||||
buttonDelObject.Text = "Удалить набор";
|
||||
buttonDelObject.UseVisualStyleBackColor = true;
|
||||
buttonDelObject.Click += buttonDelObject_Click;
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
buttonAddObject.Location = new Point(44, 106);
|
||||
buttonAddObject.Name = "buttonAddObject";
|
||||
buttonAddObject.Size = new Size(209, 34);
|
||||
buttonAddObject.TabIndex = 1;
|
||||
buttonAddObject.Text = "Добавить набор";
|
||||
buttonAddObject.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Click += buttonAddObject_Click;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 25;
|
||||
listBoxStorages.Location = new Point(6, 160);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(281, 129);
|
||||
listBoxStorages.TabIndex = 0;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(956, 548);
|
||||
Controls.Add(panelTools);
|
||||
ClientSize = new Size(1030, 746);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name = "FormPlaneCollection";
|
||||
Text = "Набор самолетов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
panelTools.ResumeLayout(false);
|
||||
panelTools.PerformLayout();
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
groupBoxStorages.ResumeLayout(false);
|
||||
groupBoxStorages.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemovePlane;
|
||||
private Button buttonAddPlane;
|
||||
private Button buttonRemovePlane;
|
||||
private Button buttonRefreshCollection;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBoxTools;
|
||||
private GroupBox groupBoxStorages;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button buttonDelObject;
|
||||
private Button buttonAddObject;
|
||||
private ListBox listBoxStorages;
|
||||
}
|
||||
}
|
@ -15,13 +15,41 @@ namespace AirBomber
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane> _planes;
|
||||
|
||||
private readonly PlanesGenericStorage _storage;
|
||||
public FormPlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_planes = new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -30,13 +58,22 @@ namespace AirBomber
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString()?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirBomber form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_planes + form.SelectedPlane != -1)
|
||||
if (obj + form.SelectedPlane > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -51,15 +88,24 @@ namespace AirBomber
|
||||
/// <param name="e"></param>
|
||||
private void buttonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_planes - pos != null)
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -73,7 +119,44 @@ namespace AirBomber
|
||||
/// <param name="e"></param>
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
private void buttonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ namespace AirBomber
|
||||
/// <returns></returns>
|
||||
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
@ -80,7 +80,7 @@ namespace AirBomber
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
@ -103,15 +103,13 @@ namespace AirBomber
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{//линия рамзетки места
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -123,7 +121,7 @@ namespace AirBomber
|
||||
int widthObjCount = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
T? type = _collection.Get(i);
|
||||
T? type = _collection[i];
|
||||
if (type != null)
|
||||
{
|
||||
int row = i / widthObjCount;
|
||||
|
81
AirBomber/AirBomber/PlanesGenericStorage.cs
Normal file
81
AirBomber/AirBomber/PlanesGenericStorage.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class PlanesGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>> _planeStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления DONE
|
||||
if (!_planeStorages.ContainsKey(name))
|
||||
{
|
||||
_planeStorages.Add(name, new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления DONE
|
||||
if (_planeStorages.ContainsKey(name))
|
||||
{
|
||||
_planeStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора DONE
|
||||
if (_planeStorages.ContainsKey(ind))
|
||||
{
|
||||
return _planeStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,18 +12,23 @@ namespace AirBomber
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -48,32 +53,9 @@ namespace AirBomber
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
int NoEmpty = 0, temp = 0;
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] != null) NoEmpty++;
|
||||
}
|
||||
if (NoEmpty == Count - position) return -1;
|
||||
|
||||
if (position < Count && position >= 0)
|
||||
{
|
||||
for (int j = position; j < Count; j++)
|
||||
{
|
||||
if (_places[j] == null)
|
||||
{
|
||||
temp = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = temp; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
_places.Insert(position, plane);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -96,15 +78,40 @@ namespace AirBomber
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
// TODO проверка позиции DONE
|
||||
if (position < 0 || position >= Count)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
// TODO проверка позиции DONE
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции DONE
|
||||
// TODO проверка свободных мест в списке DONE
|
||||
// TODO вставка в список по позиции DONE
|
||||
if (position < 0 || position >= Count || Count == _maxCount) return;
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user