This commit is contained in:
Александр Чегодаев 2023-12-14 01:06:57 +04:00
parent 160e1ae53b
commit 8d8e031953
13 changed files with 340 additions and 190 deletions

View File

@ -8,7 +8,6 @@ using System.Threading.Tasks;
namespace ProjectCruiser
{
internal class CruiserGenericCollection<T, U>
where T : DrawningCruiser
where U : IMoveableObject
@ -43,17 +42,17 @@ namespace ProjectCruiser
public static bool operator -(CruiserGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
return collect._collection.Remove(pos);
collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowCruiser()
@ -86,16 +85,18 @@ namespace ProjectCruiser
{
int Ix = 3;
int Iy = 15;
for (int i = 0; i < _collection.Count - 1; i++)
int i = 0;
foreach (var cruiser in _collection.GetCruiser())
{
_collection.Get(i)?.SetPosition(Ix, Iy);
_collection.Get(i)?.DrawTransport(g);
_collection[i]?.SetPosition(Ix, Iy);
_collection[i]?.DrawTransport(g);
Ix += _placeSizeWidth;
if (Ix + _placeSizeHeight > _pictureWidth)
{
Ix = 0;
Iy = _placeSizeHeight;
}
i++;
}
}
}

View File

@ -0,0 +1,59 @@
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser
{
internal class CruiserGenericStorage
{
readonly Dictionary<string, CruiserGenericCollection<DrawningCruiser,
DrawningObjectCruiser>> _CruiserStorages;
public List<string> Keys => _CruiserStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
{
_CruiserStorages = new Dictionary<string,
CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
if (!_CruiserStorages.ContainsKey(name))
{
var ustaCollection = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(_pictureWidth, _pictureHeight);
_CruiserStorages.Add(name, ustaCollection);
}
}
public void DelSet(string name)
{
if (_CruiserStorages.ContainsKey(name))
{
_CruiserStorages.Remove(name);
}
}
public CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>? this[string ind]
{
get
{
if (_CruiserStorages.ContainsKey(ind))
{
return _CruiserStorages[ind];
}
return null;
}
}
}
}

View File

@ -131,7 +131,6 @@ namespace ProjectCruiser.DrawningObjects
return;
}
Pen pen = new(Color.Black);
Brush BodyColor = new SolidBrush(EntityCruiser.BodyColor);
GraphicsPath path1 = new GraphicsPath();

View File

@ -29,7 +29,6 @@ namespace ProjectCruiser.DrawningObjects
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(cruiserDou.AdditionalColor);
Brush brBlack = new SolidBrush(Color.Black);
@ -50,7 +49,9 @@ namespace ProjectCruiser.DrawningObjects
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 18, 15, 12);
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 33, 15, 12);
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 33, 15, 12);
}
}
}
}

View File

@ -5,7 +5,6 @@ namespace ProjectCruiser
{
public partial class FormCruiser : Form
{
private DrawningCruiser? _drawningCruiser;
private AbstractStrategy? _abstractStrategy;

View File

@ -28,90 +28,151 @@
/// </summary>
private void InitializeComponent()
{
groupBox1 = new GroupBox();
maskedTextBoxNumber = new MaskedTextBox();
ButtonRefreshCollection = new Button();
ButtonRemoveCruiser = new Button();
buttonAddCruiser = new Button();
pictureBoxCollection = new PictureBox();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.listBoxStorage = new System.Windows.Forms.ListBox();
this.textBoxStorageName = new System.Windows.Forms.MaskedTextBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.buttonAddCruiser = new System.Windows.Forms.Button();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(ButtonRefreshCollection);
groupBox1.Controls.Add(ButtonRemoveCruiser);
groupBox1.Controls.Add(buttonAddCruiser);
groupBox1.Location = new Point(844, 12);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(196, 319);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
this.groupBox1.Controls.Add(this.ButtonRemoveCruiser);
this.groupBox1.Controls.Add(this.buttonAddCruiser);
this.groupBox1.Location = new System.Drawing.Point(643, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(196, 436);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.listBoxStorage);
this.groupBox2.Controls.Add(this.textBoxStorageName);
this.groupBox2.Controls.Add(this.ButtonAddObject);
this.groupBox2.Controls.Add(this.ButtonDelObject);
this.groupBox2.Location = new System.Drawing.Point(9, 24);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(179, 256);
this.groupBox2.TabIndex = 4;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Наборы";
//
// listBoxStorage
//
this.listBoxStorage.FormattingEnabled = true;
this.listBoxStorage.ItemHeight = 15;
this.listBoxStorage.Location = new System.Drawing.Point(6, 93);
this.listBoxStorage.Name = "listBoxStorage";
this.listBoxStorage.Size = new System.Drawing.Size(167, 109);
this.listBoxStorage.TabIndex = 5;
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
//
// textBoxStorageName
//
this.textBoxStorageName.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.textBoxStorageName.Location = new System.Drawing.Point(6, 22);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(167, 26);
this.textBoxStorageName.TabIndex = 4;
//
// ButtonAddObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(6, 54);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(167, 33);
this.ButtonAddObject.TabIndex = 3;
this.ButtonAddObject.Text = "Добавить набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(6, 217);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(167, 33);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Font = new Font("Lucida Sans Unicode", 9F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxNumber.Location = new Point(29, 78);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(130, 26);
maskedTextBoxNumber.TabIndex = 3;
this.maskedTextBoxNumber.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.maskedTextBoxNumber.Location = new System.Drawing.Point(34, 325);
this.maskedTextBoxNumber.Mask = "00";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(130, 26);
this.maskedTextBoxNumber.TabIndex = 3;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.Location = new Point(6, 195);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(184, 33);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = "Обовить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
this.ButtonRefreshCollection.Location = new System.Drawing.Point(6, 396);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(184, 33);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обовить коллекцию";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveCruiser
//
ButtonRemoveCruiser.Location = new Point(6, 136);
ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
ButtonRemoveCruiser.Size = new Size(184, 33);
ButtonRemoveCruiser.TabIndex = 1;
ButtonRemoveCruiser.Text = "Удалить Крейсер";
ButtonRemoveCruiser.UseVisualStyleBackColor = true;
ButtonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(6, 357);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(184, 33);
this.ButtonRemoveCruiser.TabIndex = 1;
this.ButtonRemoveCruiser.Text = "Удалить крейсер";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// buttonAddCruiser
//
buttonAddCruiser.Location = new Point(6, 22);
buttonAddCruiser.Name = "buttonAddCruiser";
buttonAddCruiser.Size = new Size(184, 33);
buttonAddCruiser.TabIndex = 0;
buttonAddCruiser.Text = "Добавить Крейсер";
buttonAddCruiser.UseVisualStyleBackColor = true;
buttonAddCruiser.Click += buttonAddCruiser_Click;
this.buttonAddCruiser.Location = new System.Drawing.Point(6, 286);
this.buttonAddCruiser.Name = "buttonAddCruiser";
this.buttonAddCruiser.Size = new System.Drawing.Size(184, 33);
this.buttonAddCruiser.TabIndex = 0;
this.buttonAddCruiser.Text = "Добавить крейсер";
this.buttonAddCruiser.UseVisualStyleBackColor = true;
this.buttonAddCruiser.Click += new System.EventHandler(this.buttonAddCruiser_Click);
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, -1);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(838, 432);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, -1);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(637, 449);
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBoxCollection.TabIndex = 1;
this.pictureBoxCollection.TabStop = false;
//
// FormCruiserCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1062, 489);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBox1);
Name = "FormCruiserCollection";
Text = "FormCruiserCollection";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(851, 458);
this.Controls.Add(this.pictureBoxCollection);
this.Controls.Add(this.groupBox1);
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false);
}
#endregion
@ -122,5 +183,10 @@
private Button ButtonRemoveCruiser;
private Button buttonAddCruiser;
private PictureBox pictureBoxCollection;
private GroupBox groupBox2;
private ListBox listBoxStorage;
private MaskedTextBox textBoxStorageName;
private Button ButtonAddObject;
private Button ButtonDelObject;
}
}

View File

@ -14,23 +14,87 @@ namespace ProjectCruiser
{
public partial class FormCruiserCollection : Form
{
private readonly CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser> _cruiser;
private readonly CruiserGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
_cruiser = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(pictureBoxCollection.Width, pictureBoxCollection.Height);
_storage = new CruiserGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
}
private void ReloadObjects()
{
int index = listBoxStorage.SelectedIndex;
listBoxStorage.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorage.Items.Add(_storage.Keys[i]);
}
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
>= listBoxStorage.Items.Count))
{
listBoxStorage.SelectedIndex = 0;
}
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
index < listBoxStorage.Items.Count)
{
listBoxStorage.SelectedIndex = index;
}
}
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 listBoxStorage_SelectedIndexChanged(object sender,
EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowCruiser();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void buttonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
FormCruiser form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_cruiser + form.SelectedCruiser > -1)
if (obj + form.SelectedCruiser > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _cruiser.ShowCruiser();
pictureBoxCollection.Image = obj.ShowCruiser();
}
else
{
@ -41,15 +105,26 @@ namespace ProjectCruiser
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.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 (_cruiser - pos != null)
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _cruiser.ShowCruiser();
pictureBoxCollection.Image = obj.ShowCruiser();
}
else
{
@ -59,7 +134,17 @@ namespace ProjectCruiser
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _cruiser.ShowCruiser();
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowCruiser();
}
}
}

View File

@ -1,64 +1,4 @@
<?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.
-->
<root>
<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">

View File

@ -9,7 +9,6 @@ namespace ProjectCruiser.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }

View File

@ -9,7 +9,6 @@ using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
public class DrawningObjectCruiser : IMoveableObject
{
private readonly DrawningCruiser? _drawningCruiser = null;

View File

@ -6,13 +6,15 @@ using System.Threading.Tasks;
namespace ProjectCruiser.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;

View File

@ -9,14 +9,16 @@ namespace ProjectCruiser
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _places;
private readonly T?[] _places;
public int Count => _places.Count;
public int Count => _places.Length;
private readonly int _maxCount;
public SetGeneric(int count)
{
_places = new T?[count];
_maxCount = count;
_places = new List<T?>(count);
}
public int Insert(T cruiser)
@ -26,51 +28,49 @@ namespace ProjectCruiser
public int Insert(T cruiser, int position)
{
if (position < 0 && position > Count)
{
if (position < 0 || position >= _maxCount)
return -1;
}
if (_places[position] != null)
{
int d = 0;
for (int j = 1; j < Count - position; j++)
{
if (_places[position + j] == null)
{
d = position + j;
break;
}
}
if (d == 0)
{
return -1;
}
for (int j = d; j > position; j--)
{
_places[j] = _places[j - 1];
}
}
_places[position] = cruiser;
if (Count >= _maxCount)
return -1;
_places.Insert(position, cruiser);
return position;
}
public bool Remove(int position)
{
if (position < 0 || position >= _places.Length)
{
return false;
}
_places[position] = null;
if ((position < 0) || (position > _maxCount)) return false;
_places.RemoveAt(position);
return true;
}
public T? Get(int position)
public T? this[int position]
{
if (position < 0 || position >= _places.Length)
get
{
return null;
if (position < 0 || position > _maxCount)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
}
}
public IEnumerable<T?> GetCruiser(int? maxCruiser = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCruiser.HasValue && i == maxCruiser.Value)
{
yield break;
}
}
return _places[position];
}
}
}