почти готовая лаба
This commit is contained in:
parent
738f84f43a
commit
fe3e0c632f
@ -31,11 +31,11 @@ namespace Sailboat.Generics
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 160;
|
||||
private readonly int _placeSizeHeight = 180;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
@ -59,14 +59,14 @@ namespace Sailboat.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(BoatsGenericCollection<T, U> collect, T?
|
||||
public static int operator +(BoatsGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -133,9 +133,14 @@ namespace Sailboat.Generics
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
DrawingBoat boat = _collection.Get(i);
|
||||
|
||||
if (boat != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
boat.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
||||
boat.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
125
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
Normal file
125
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
namespace Sailboat
|
||||
{
|
||||
partial class FormBoatCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panelTools = new System.Windows.Forms.Panel();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panelTools.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(700, 450);
|
||||
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar;
|
||||
this.panelTools.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.panelTools.Controls.Add(this.buttonRefreshCollection);
|
||||
this.panelTools.Controls.Add(this.buttonRemoveBoat);
|
||||
this.panelTools.Controls.Add(this.buttonAddBoat);
|
||||
this.panelTools.Location = new System.Drawing.Point(707, 12);
|
||||
this.panelTools.Name = "panelTools";
|
||||
this.panelTools.Size = new System.Drawing.Size(209, 426);
|
||||
this.panelTools.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(40, 87);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 210);
|
||||
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonRefreshCollection.TabIndex = 2;
|
||||
this.buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click);
|
||||
//
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(16, 159);
|
||||
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonRemoveBoat.TabIndex = 1;
|
||||
this.buttonRemoveBoat.Text = "Удалить лодку";
|
||||
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
|
||||
//
|
||||
// buttonAddBoat
|
||||
//
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(16, 14);
|
||||
this.buttonAddBoat.Name = "buttonAddBoat";
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonAddBoat.TabIndex = 0;
|
||||
this.buttonAddBoat.Text = "Добавить лодку";
|
||||
this.buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click);
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(929, 450);
|
||||
this.Controls.Add(this.panelTools);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormBoatCollection";
|
||||
this.Text = "FormBoatCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panelTools.ResumeLayout(false);
|
||||
this.panelTools.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemoveBoat;
|
||||
private Button buttonAddBoat;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
}
|
||||
}
|
68
Sailboat/Sailboat/FormBoatCollection.cs
Normal file
68
Sailboat/Sailboat/FormBoatCollection.cs
Normal file
@ -0,0 +1,68 @@
|
||||
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 Sailboat.DrawingObjects;
|
||||
using Sailboat.Generics;
|
||||
using Sailboat.MovementStrategy;
|
||||
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
public partial class FormBoatCollection : Form
|
||||
{
|
||||
private readonly BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> _boats;
|
||||
public FormBoatCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_boats = new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void buttonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormSailboat 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();
|
||||
}
|
||||
}
|
||||
}
|
60
Sailboat/Sailboat/FormBoatCollection.resx
Normal file
60
Sailboat/Sailboat/FormBoatCollection.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<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">
|
||||
<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>
|
14
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
14
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonCreateSailboat = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonSelectBoat = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSailboat)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -144,11 +145,23 @@
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// buttonSelectBoat
|
||||
//
|
||||
this.buttonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectBoat.Location = new System.Drawing.Point(688, 97);
|
||||
this.buttonSelectBoat.Name = "buttonSelectBoat";
|
||||
this.buttonSelectBoat.Size = new System.Drawing.Size(149, 33);
|
||||
this.buttonSelectBoat.TabIndex = 9;
|
||||
this.buttonSelectBoat.Text = "Выбрать лодку";
|
||||
this.buttonSelectBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectBoat.Click += new System.EventHandler(this.buttonSelectBoat_Click);
|
||||
//
|
||||
// FormSailboat
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.buttonSelectBoat);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonCreateSailboat);
|
||||
@ -178,5 +191,6 @@
|
||||
private Button buttonCreateSailboat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectBoat;
|
||||
}
|
||||
}
|
@ -8,9 +8,12 @@ namespace Sailboat
|
||||
{
|
||||
private DrawingBoat? _drawingBoat;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingBoat? SelectedBoat { get; private set; }
|
||||
public FormSailboat()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBoat = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
@ -27,17 +30,38 @@ namespace Sailboat
|
||||
private void buttonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
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;
|
||||
}
|
||||
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateSailboat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingBoat = new DrawingSailboat(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)),
|
||||
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;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialogAddColor = new();
|
||||
if (dialogAddColor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogAddColor.Color;
|
||||
}
|
||||
|
||||
_drawingBoat = new DrawingSailboat(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
@ -84,7 +108,7 @@ namespace Sailboat
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectBoat(_drawingBoat), pictureBoxSailboat.Width,
|
||||
_abstractStrategy.SetData(_drawingBoat.GetMoveableObject, pictureBoxSailboat.Width,
|
||||
pictureBoxSailboat.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
@ -92,6 +116,7 @@ namespace Sailboat
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
@ -100,5 +125,11 @@ namespace Sailboat
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBoat = _drawingBoat;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Sailboat
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormSailboat());
|
||||
Application.Run(new FormBoatCollection());
|
||||
}
|
||||
}
|
||||
}
|
@ -29,10 +29,9 @@ namespace Sailboat.Generics
|
||||
/// </summary>
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat)
|
||||
public int Insert(T boat)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
return true;
|
||||
return Insert(boat, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -40,15 +39,36 @@ namespace Sailboat.Generics
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat, int position)
|
||||
public int Insert(T boat, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
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 true;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -57,8 +77,12 @@ namespace Sailboat.Generics
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -68,7 +92,10 @@ namespace Sailboat.Generics
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user