diff --git a/MotorBoat/MotorBoat/BoatGenericCollection.cs b/MotorBoat/MotorBoat/BoatGenericCollection.cs new file mode 100644 index 0000000..f3ffc8b --- /dev/null +++ b/MotorBoat/MotorBoat/BoatGenericCollection.cs @@ -0,0 +1,156 @@ +using MotorBoat.Generics; +using MotorBoat.DrawningObjects; +using MotorBoat.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorBoat.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningBoat + /// + /// + /// + internal class BoatsGenericCollection + where T : DrawningBoat + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 180; + + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 80; + + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + + /// + /// Конструктор + /// + /// + /// + public BoatsGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static int operator +(BoatsGenericCollection collect, T? + obj) + { + if (obj == null) + { + return -1; + } + return collect?._collection.Insert(obj) ?? -1; + } + + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(BoatsGenericCollection collect, int + pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return false; + } + + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowBoats() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + + /// + /// Метод отрисовки фона + /// + /// + 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); + } + } + + /// + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + T? t; + int Rows = _pictureWidth / _placeSizeWidth; + for (int i = 0; i < _collection.Count; i++) + { + t = _collection.Get(i); + if (t != null) + { + t.SetPosition(i % Rows * _placeSizeWidth, i / Rows * _placeSizeHeight + 5); + t.DrawTransport(g); + } + } + } + } +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/DrawningBoat.cs b/MotorBoat/MotorBoat/DrawningBoat.cs index 597b678..69c4dc7 100644 --- a/MotorBoat/MotorBoat/DrawningBoat.cs +++ b/MotorBoat/MotorBoat/DrawningBoat.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using MotorBoat.Entities; using MotorBoat; +using MotorBoat.MovementStrategy; namespace MotorBoat.DrawningObjects { @@ -69,6 +70,11 @@ namespace MotorBoat.DrawningObjects EntityBoat = new EntityBoat(speed, weight, bodyColor); } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new DrawningObjectBoat(this); + /// /// Конструктор /// @@ -79,8 +85,7 @@ namespace MotorBoat.DrawningObjects /// Высота картинки /// Ширина прорисовки автомобиля /// Высота прорисовки автомобиля - protected DrawningBoat(int speed, double weight, Color bodyColor, int - width, int height, int boatWidth, int boatHeight) + protected DrawningBoat(int speed, double weight, Color bodyColor, int width, int height, int boatWidth, int boatHeight) { if (width <= _boatWeight || height <= _boatHeight) return; diff --git a/MotorBoat/MotorBoat/DrawningMotorBoat.cs b/MotorBoat/MotorBoat/DrawningMotorBoat.cs index 82beac7..429c5a7 100644 --- a/MotorBoat/MotorBoat/DrawningMotorBoat.cs +++ b/MotorBoat/MotorBoat/DrawningMotorBoat.cs @@ -48,16 +48,23 @@ namespace MotorBoat.DrawningObjects Pen pen = new(Color.Black, 1); Brush additionalBrush = new SolidBrush(motorBoat.AdditionalColor); + base.DrawTransport(g); + if (motorBoat.Glass) { // стекло впереди Brush glassBrush = new SolidBrush(Color.LightBlue); - g.FillEllipse(glassBrush, _startPosX + 20, _startPosY + 15, 100, 40); - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 15, 100, 40); + Point[] glassPoints = new Point[] + { + new Point(_startPosX + 100, _startPosY + 15), + new Point(_startPosX + 120, _startPosY + 25), + new Point(_startPosX + 120, _startPosY + 45), + new Point(_startPosX + 100, _startPosY + 55) + }; + g.FillPolygon(glassBrush, glassPoints); + g.DrawPolygon(pen, glassPoints); } - base.DrawTransport(g); - if (motorBoat.Engine) { // двигатель @@ -66,4 +73,4 @@ namespace MotorBoat.DrawningObjects } } } -} +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/DrawningObjectBoat.cs b/MotorBoat/MotorBoat/DrawningObjectBoat.cs index 3dfeb4d..12cc5af 100644 --- a/MotorBoat/MotorBoat/DrawningObjectBoat.cs +++ b/MotorBoat/MotorBoat/DrawningObjectBoat.cs @@ -36,4 +36,4 @@ namespace MotorBoat.MovementStrategy public void MoveObject(DirectionType direction) => _drawningBoat?.MoveTransport(direction); } -} +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/EntityMotorBoat.cs b/MotorBoat/MotorBoat/EntityMotorBoat.cs index 1f3d488..70414a4 100644 --- a/MotorBoat/MotorBoat/EntityMotorBoat.cs +++ b/MotorBoat/MotorBoat/EntityMotorBoat.cs @@ -45,4 +45,4 @@ namespace MotorBoat.Entities Glass = glass; } } -} +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs b/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..0551667 --- /dev/null +++ b/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs @@ -0,0 +1,125 @@ +namespace MotorBoat +{ + partial class FormBoatCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxCollection = new PictureBox(); + maskedTextBoxNumber = new MaskedTextBox(); + ButtonAddBoat = new Button(); + ButtonRemoveBoat = new Button(); + ButtonRefreshCollection = new Button(); + groupBoxTools = new GroupBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + groupBoxTools.SuspendLayout(); + SuspendLayout(); + // + // pictureBoxCollection + // + pictureBoxCollection.Dock = DockStyle.Left; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(578, 461); + pictureBoxCollection.TabIndex = 1; + pictureBoxCollection.TabStop = false; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(54, 135); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(100, 23); + maskedTextBoxNumber.TabIndex = 0; + // + // ButtonAddBoat + // + ButtonAddBoat.Location = new Point(6, 22); + ButtonAddBoat.Name = "ButtonAddBoat"; + ButtonAddBoat.Size = new Size(188, 40); + ButtonAddBoat.TabIndex = 1; + ButtonAddBoat.Text = "Добавить лодку"; + ButtonAddBoat.UseVisualStyleBackColor = true; + ButtonAddBoat.Click += ButtonAddBoat_Click; + // + // ButtonRemoveBoat + // + ButtonRemoveBoat.Location = new Point(11, 171); + ButtonRemoveBoat.Name = "ButtonRemoveBoat"; + ButtonRemoveBoat.Size = new Size(183, 41); + ButtonRemoveBoat.TabIndex = 2; + ButtonRemoveBoat.Text = "Удалить лодку"; + ButtonRemoveBoat.UseVisualStyleBackColor = true; + ButtonRemoveBoat.Click += ButtonRemoveBoat_Click; + // + // ButtonRefreshCollection + // + ButtonRefreshCollection.Location = new Point(11, 218); + ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + ButtonRefreshCollection.Size = new Size(183, 39); + ButtonRefreshCollection.TabIndex = 3; + ButtonRefreshCollection.Text = "Обновить коллекцию"; + ButtonRefreshCollection.UseVisualStyleBackColor = true; + ButtonRefreshCollection.Click += ButtonRefreshCollection_Click; + // + // groupBoxTools + // + groupBoxTools.Controls.Add(ButtonRefreshCollection); + groupBoxTools.Controls.Add(ButtonRemoveBoat); + groupBoxTools.Controls.Add(ButtonAddBoat); + groupBoxTools.Controls.Add(maskedTextBoxNumber); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(584, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(200, 461); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // FormBoatCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(784, 461); + Controls.Add(groupBoxTools); + Controls.Add(pictureBoxCollection); + Name = "FormBoatCollection"; + Text = "Набор лодок"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxCollection; + private MaskedTextBox maskedTextBoxNumber; + private Button ButtonAddBoat; + private Button ButtonRemoveBoat; + private Button ButtonRefreshCollection; + private GroupBox groupBoxTools; + } +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormBoatCollection.cs b/MotorBoat/MotorBoat/FormBoatCollection.cs new file mode 100644 index 0000000..d78e35e --- /dev/null +++ b/MotorBoat/MotorBoat/FormBoatCollection.cs @@ -0,0 +1,92 @@ +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 MotorBoat.DrawningObjects; +using MotorBoat.Generics; +using MotorBoat.MovementStrategy; + +namespace MotorBoat +{ + /// + /// Форма для работы с набором объектов класса DrawningBoat + /// + public partial class FormBoatCollection : Form + { + /// + /// Набор объектов + /// + private readonly BoatsGenericCollection _boats; + + /// + /// Конструктор + /// + public FormBoatCollection() + { + InitializeComponent(); + _boats = new BoatsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddBoat_Click(object sender, EventArgs e) + { + FormMotorBoat form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_boats + form.SelectedBoat != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _boats.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveBoat_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_boats - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _boats.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _boats.ShowBoats(); + } + } +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormBoatCollection.resx b/MotorBoat/MotorBoat/FormBoatCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/MotorBoat/MotorBoat/FormBoatCollection.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs b/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs index cb6d225..159e89e 100644 --- a/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs +++ b/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs @@ -37,6 +37,7 @@ ButonCreateMotorBoat = new Button(); comboBoxStrategy = new ComboBox(); ButtonStep = new Button(); + ButtonSelectBoat = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit(); SuspendLayout(); // @@ -139,11 +140,22 @@ ButtonStep.UseVisualStyleBackColor = true; ButtonStep.Click += ButtonStep_Click; // + // ButtonSelectBoat + // + ButtonSelectBoat.Location = new Point(366, 412); + ButtonSelectBoat.Name = "ButtonSelectBoat"; + ButtonSelectBoat.Size = new Size(171, 37); + ButtonSelectBoat.TabIndex = 9; + ButtonSelectBoat.Text = "Выбрать лодку"; + ButtonSelectBoat.UseVisualStyleBackColor = true; + ButtonSelectBoat.Click += ButtonSelectBoat_Click; + // // FormMotorBoat // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(884, 461); + Controls.Add(ButtonSelectBoat); Controls.Add(ButtonStep); Controls.Add(comboBoxStrategy); Controls.Add(ButonCreateMotorBoat); @@ -155,7 +167,7 @@ Controls.Add(pictureBoxMotorBoat); Name = "FormMotorBoat"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormMotorBoat"; + Text = "Моторная лодка"; ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).EndInit(); ResumeLayout(false); PerformLayout(); @@ -172,5 +184,6 @@ private Button ButonCreateMotorBoat; private ComboBox comboBoxStrategy; private Button ButtonStep; + private Button ButtonSelectBoat; } } \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormMotorBoat.cs b/MotorBoat/MotorBoat/FormMotorBoat.cs index ba3b289..771428c 100644 --- a/MotorBoat/MotorBoat/FormMotorBoat.cs +++ b/MotorBoat/MotorBoat/FormMotorBoat.cs @@ -23,7 +23,12 @@ namespace MotorBoat /// /// /// - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + + /// + /// + /// + public DrawningBoat? SelectedBoat { get; private set; } /// /// @@ -31,6 +36,8 @@ namespace MotorBoat public FormMotorBoat() { InitializeComponent(); + _strategy = null; + SelectedBoat = null; } /// @@ -48,21 +55,6 @@ namespace MotorBoat pictureBoxMotorBoat.Image = bmp; } - /// - /// " " - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); - _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } - /// /// " " /// @@ -71,15 +63,45 @@ namespace MotorBoat private void ButonCreateMotorBoat_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; + } _drawningBoat = new DrawningMotorBoat(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)), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + /// + /// " " + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + 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; + } + _drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), + color, pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); + _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + /// /// /// @@ -123,35 +145,44 @@ namespace MotorBoat } 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 + _strategy.SetData(new DrawningObjectBoat(_drawningBoat), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); comboBoxStrategy.Enabled = false; } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } - } + /// + /// + /// + /// + /// < + private void ButtonSelectBoat_Click(object sender, EventArgs e) + { + SelectedBoat = _drawningBoat; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/MotorBoat/MotorBoat/MoveToBorder.cs b/MotorBoat/MotorBoat/MoveToBorder.cs index b451e92..28ebe45 100644 --- a/MotorBoat/MotorBoat/MoveToBorder.cs +++ b/MotorBoat/MotorBoat/MoveToBorder.cs @@ -58,4 +58,4 @@ namespace MotorBoat.MovementStrategy } } } -} +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/Program.cs b/MotorBoat/MotorBoat/Program.cs index 83aea91..8145421 100644 --- a/MotorBoat/MotorBoat/Program.cs +++ b/MotorBoat/MotorBoat/Program.cs @@ -11,7 +11,7 @@ namespace MotorBoat // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMotorBoat()); + Application.Run(new FormBoatCollection()); } } } \ No newline at end of file diff --git a/MotorBoat/MotorBoat/SetGeneric.cs b/MotorBoat/MotorBoat/SetGeneric.cs new file mode 100644 index 0000000..58727a6 --- /dev/null +++ b/MotorBoat/MotorBoat/SetGeneric.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorBoat.Generics +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public int Insert(T boat) + { + return Insert(boat, 0); + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public int Insert(T boat, 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] = boat; + return position; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (position < 0 || position >= Count) return false; + _places[position] = null; + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + if (position < 0 || position >= Count) return null; + return _places[position]; + } + } +} \ No newline at end of file diff --git a/MotorBoat/MotorBoat/Status.cs b/MotorBoat/MotorBoat/Status.cs index c34a366..4f9d72b 100644 --- a/MotorBoat/MotorBoat/Status.cs +++ b/MotorBoat/MotorBoat/Status.cs @@ -15,4 +15,4 @@ namespace MotorBoat.MovementStrategy InProgress, Finish } -} +} \ No newline at end of file