diff --git a/ProjectMachine/ProjectMachine/FormMachine.Designer.cs b/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
index c89e945..9fcc35e 100644
--- a/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
+++ b/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
@@ -168,6 +168,7 @@
this.buttonSelectTank.TabIndex = 8;
this.buttonSelectTank.Text = "Выбрать";
this.buttonSelectTank.UseVisualStyleBackColor = true;
+ this.buttonSelectTank.Click += new System.EventHandler(this.buttonSelectTank_Click);
//
// FormMachine
//
diff --git a/ProjectMachine/ProjectMachine/FormMachine.cs b/ProjectMachine/ProjectMachine/FormMachine.cs
index 50cc88a..237b6c8 100644
--- a/ProjectMachine/ProjectMachine/FormMachine.cs
+++ b/ProjectMachine/ProjectMachine/FormMachine.cs
@@ -40,7 +40,13 @@ namespace ProjectMachine
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
@@ -110,7 +116,7 @@ namespace ProjectMachine
///
///
///
- private void ButtonSelectCar_Click(object sender, EventArgs e)
+ private void buttonSelectTank_Click(object sender, EventArgs e)
{
SelectedTank = _machine;
DialogResult = DialogResult.OK;
diff --git a/ProjectMachine/ProjectMachine/FormMapWithSetTank.Designer.cs b/ProjectMachine/ProjectMachine/FormMapWithSetTank.Designer.cs
index ccdb92f..aaf171e 100644
--- a/ProjectMachine/ProjectMachine/FormMapWithSetTank.Designer.cs
+++ b/ProjectMachine/ProjectMachine/FormMapWithSetTank.Designer.cs
@@ -28,12 +28,199 @@
///
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
+ this.groupBoxTools = new System.Windows.Forms.GroupBox();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.buttonShowOnMap = new System.Windows.Forms.Button();
+ this.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonRemoveTank = new System.Windows.Forms.Button();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonAddTank = new System.Windows.Forms.Button();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ this.groupBoxTools.Controls.Add(this.buttonLeft);
+ this.groupBoxTools.Controls.Add(this.buttonUp);
+ this.groupBoxTools.Controls.Add(this.buttonRight);
+ this.groupBoxTools.Controls.Add(this.buttonDown);
+ this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
+ this.groupBoxTools.Controls.Add(this.buttonShowStorage);
+ this.groupBoxTools.Controls.Add(this.buttonRemoveTank);
+ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBoxTools.Controls.Add(this.buttonAddTank);
+ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBoxTools.Location = new System.Drawing.Point(807, 0);
+ this.groupBoxTools.Name = "groupBoxTools";
+ this.groupBoxTools.Size = new System.Drawing.Size(233, 546);
+ this.groupBoxTools.TabIndex = 0;
+ this.groupBoxTools.TabStop = false;
+ this.groupBoxTools.Text = "Инструменты";
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::ProjectMachine.Properties.Resources.лево;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(69, 491);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(34, 30);
+ this.buttonLeft.TabIndex = 13;
+ this.buttonLeft.Text = " \r\n\r\n";
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::ProjectMachine.Properties.Resources.вверх;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(105, 455);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(34, 30);
+ this.buttonUp.TabIndex = 12;
+ this.buttonUp.Text = " \r\n\r\n";
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::ProjectMachine.Properties.Resources.право;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(141, 491);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(34, 30);
+ this.buttonRight.TabIndex = 11;
+ this.buttonRight.Text = " \r\n\r\n";
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::ProjectMachine.Properties.Resources.вниз;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(105, 491);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(34, 30);
+ this.buttonDown.TabIndex = 10;
+ this.buttonDown.Text = " \r\n\r\n";
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Город"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(26, 35);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
+ this.comboBoxSelectorMap.TabIndex = 9;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // buttonShowOnMap
+ //
+ this.buttonShowOnMap.Location = new System.Drawing.Point(25, 379);
+ this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
+ this.buttonShowOnMap.TabIndex = 6;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Location = new System.Drawing.Point(25, 291);
+ this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
+ this.buttonShowStorage.TabIndex = 5;
+ this.buttonShowStorage.Text = "Посмотреть хранилище";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonRemoveTank
+ //
+ this.buttonRemoveTank.Location = new System.Drawing.Point(25, 205);
+ this.buttonRemoveTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemoveTank.Name = "buttonRemoveTank";
+ this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
+ this.buttonRemoveTank.TabIndex = 4;
+ this.buttonRemoveTank.Text = "Удалить танк";
+ this.buttonRemoveTank.UseVisualStyleBackColor = true;
+ this.buttonRemoveTank.Click += new System.EventHandler(this.ButtonRemoveTank_Click);
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(26, 170);
+ this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
+ this.maskedTextBoxPosition.TabIndex = 3;
+ this.maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddTank
+ //
+ this.buttonAddTank.Location = new System.Drawing.Point(25, 82);
+ this.buttonAddTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddTank.Name = "buttonAddTank";
+ this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
+ this.buttonAddTank.TabIndex = 2;
+ this.buttonAddTank.Text = "Добавить танк";
+ this.buttonAddTank.UseVisualStyleBackColor = true;
+ this.buttonAddTank.Click += new System.EventHandler(this.ButtonAddTank_Click);
+ //
+ // pictureBox
+ //
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(807, 546);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetTank
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
+ this.ClientSize = new System.Drawing.Size(1040, 546);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBoxTools);
+ this.Name = "FormMapWithSetTank";
this.Text = "FormMapWithSetTank";
+ this.groupBoxTools.ResumeLayout(false);
+ this.groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
}
#endregion
+
+ private GroupBox groupBoxTools;
+ private PictureBox pictureBox;
+ private Button buttonShowOnMap;
+ private Button buttonShowStorage;
+ private Button buttonRemoveTank;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonAddTank;
+ private ComboBox comboBoxSelectorMap;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonRight;
+ private Button buttonDown;
}
}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/FormMapWithSetTank.cs b/ProjectMachine/ProjectMachine/FormMapWithSetTank.cs
index 26928fc..cb44d13 100644
--- a/ProjectMachine/ProjectMachine/FormMapWithSetTank.cs
+++ b/ProjectMachine/ProjectMachine/FormMapWithSetTank.cs
@@ -12,9 +12,153 @@ namespace ProjectMachine
{
public partial class FormMapWithSetTank : Form
{
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetTankGeneric _mapTankCollectionGeneric;
+ ///
+ /// Конструктор
+ ///
public FormMapWithSetTank()
{
InitializeComponent();
}
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Город":
+ map = new TownMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapTankCollectionGeneric = new MapWithSetTankGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapTankCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddTank_Click(object sender, EventArgs e)
+ {
+ if (_mapTankCollectionGeneric == null)
+ {
+ return;
+ }
+ FormMachine form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawningObject tank = new(form.SelectedTank);
+ if ((_mapTankCollectionGeneric + tank) > -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveTank_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if ((_mapTankCollectionGeneric - pos) != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapTankCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapTankCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapTankCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapTankCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapTankCollectionGeneric.MoveObject(dir);
+ }
}
}
+
diff --git a/ProjectMachine/ProjectMachine/FormMapWithSetTank.resx b/ProjectMachine/ProjectMachine/FormMapWithSetTank.resx
index 1af7de1..f298a7b 100644
--- a/ProjectMachine/ProjectMachine/FormMapWithSetTank.resx
+++ b/ProjectMachine/ProjectMachine/FormMapWithSetTank.resx
@@ -1,64 +1,4 @@
-
-
-
+
diff --git a/ProjectMachine/ProjectMachine/MapWithSetTankGeneric.cs b/ProjectMachine/ProjectMachine/MapWithSetTankGeneric.cs
index 7b39378..c69531e 100644
--- a/ProjectMachine/ProjectMachine/MapWithSetTankGeneric.cs
+++ b/ProjectMachine/ProjectMachine/MapWithSetTankGeneric.cs
@@ -26,11 +26,11 @@ namespace ProjectMachine
///
/// Размер занимаемого объектом места (ширина)
///
- private readonly int _placeSizeWidth = 210;
+ private readonly int _placeSizeWidth = 200;
///
/// Размер занимаемого объектом места (высота)
///
- private readonly int _placeSizeHeight = 90;
+ private readonly int _placeSizeHeight = 70;
///
/// Набор объектов
///
@@ -58,11 +58,11 @@ namespace ProjectMachine
/// Перегрузка оператора сложения
///
///
- ///
+ ///
///
- public static bool operator + (MapWithSetTankGeneric map, T car)
+ public static int operator +(MapWithSetTankGeneric map, T tank)
{
- return map._setTank.Insert(car);
+ return map._setTank.Insert(tank);
}
///
/// Перегрузка оператора вычитания
@@ -70,8 +70,7 @@ namespace ProjectMachine
///
///
///
- public static bool operator -(MapWithSetTankGeneric map, int
- position)
+ public static T operator -(MapWithSetTankGeneric map, int position)
{
return map._setTank.Remove(position);
}
@@ -81,10 +80,11 @@ namespace ProjectMachine
///
public Bitmap ShowSet()
{
+ Shaking();
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
- DrawCars(gr);
+ DrawTanks(gr);
return bmp;
}
///
@@ -96,10 +96,10 @@ namespace ProjectMachine
Shaking();
for (int i = 0; i < _setTank.Count; i++)
{
- var car = _setTank.Get(i);
- if (car != null)
+ var tank = _setTank.Get(i);
+ if (tank != null)
{
- return _map.CreateMap(_pictureWidth, _pictureHeight, car);
+ return _map.CreateMap(_pictureWidth, _pictureHeight, tank);
}
}
return new(_pictureWidth, _pictureHeight);
@@ -150,7 +150,9 @@ namespace ProjectMachine
///
private void DrawBackground(Graphics g)
{
- Pen pen = new(Color.Black, 3);
+ Pen pen = new(Color.Black, 6);
+ Brush br = new SolidBrush(Color.Moccasin);
+ g.FillRectangle(br, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
@@ -166,12 +168,23 @@ namespace ProjectMachine
/// Метод прорисовки объектов
///
///
- private void DrawCars(Graphics g)
+ private void DrawTanks(Graphics g)
{
- for (int i = 0; i < _setTank.Count; i++)
+ int i = 0;
+ int j = 0;
+ for (int k = 0; k < _setTank.Count; k++)
{
- // TODO установка позиции
- _setTank.Get(i)?.DrawningObject(g);
+ _setTank.Get(k)?.SetObject(j + 10, i + 20, _pictureWidth, _pictureHeight);
+ _setTank.Get(k)?.DrawningObject(g);
+ if (j >= _pictureWidth - 2*_placeSizeWidth)
+ {
+ j = 0;
+ i += _placeSizeHeight;
+ }
+ else
+ {
+ j += _placeSizeWidth;
+ }
}
}
}
diff --git a/ProjectMachine/ProjectMachine/Program.cs b/ProjectMachine/ProjectMachine/Program.cs
index 4d6e0f6..3db1ecc 100644
--- a/ProjectMachine/ProjectMachine/Program.cs
+++ b/ProjectMachine/ProjectMachine/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectMachine
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetTank());
}
}
}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/SetTankGeneric.cs b/ProjectMachine/ProjectMachine/SetTankGeneric.cs
index a3b382c..5c1fb15 100644
--- a/ProjectMachine/ProjectMachine/SetTankGeneric.cs
+++ b/ProjectMachine/ProjectMachine/SetTankGeneric.cs
@@ -32,39 +32,63 @@ namespace ProjectMachine
///
/// Добавление объекта в набор
///
- /// Добавляемый автомобиль
+ /// Добавляемый танк
///
- public bool Insert(T car)
+ public int Insert(T tank)
{
- // TODO вставка в начало набора
- return true;
+ if (tank == null)
+ {
+ return -1;
+ }
+ for (int i = Count -1; i > 0; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[0] = tank;
+ return 0;
}
///
/// Добавление объекта в набор на конкретную позицию
///
- /// Добавляемый автомобиль
+ /// Добавляемый танк
/// Позиция
///
- public bool Insert(T car, int position)
+ public int Insert(T tank, int position)
{
- // TODO проверка позиции
- // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
- // TODO вставка по позиции
- _places[position] = car;
- return true;
+ if (position < 0 || position > Count)
+ {
+ return -1;
+ }
+ int firstNullElementIndex = position; //индекс первого нулевого элемента
+ while(_places[firstNullElementIndex] != null)
+ {
+ if (firstNullElementIndex >= Count)
+ {
+ return -1;
+ }
+ firstNullElementIndex++;
+ }
+ for (int i = firstNullElementIndex; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = tank;
+ return 0;
}
///
/// Удаление объекта из набора с конкретной позиции
///
///
///
- public bool Remove(int position)
+ public T Remove(int position)
{
- // TODO проверка позиции
- // TODO удаление объекта из массива, присовив элементу массива значение null
- return true;
+ if (_places[position] == null)
+ {
+ return null;
+ }
+ var result = _places[position];
+ _places[position] = null;
+ return result;
}
///
/// Получение объекта из набора по позиции
@@ -73,8 +97,11 @@ namespace ProjectMachine
///
public T Get(int position)
{
- // TODO проверка позиции
- return _places[position];
+ if (_places[position] != null)
+ {
+ return _places[position];
+ }
+ return null;
}
}