PIbd-22. Stroev V.M. Lab Work 04 #6
98
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
98
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
@ -30,6 +30,12 @@
|
|||||||
{
|
{
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
|
panel2 = new Panel();
|
||||||
|
label2 = new Label();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
button1 = new Button();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
maskedTextBoxNumber = new TextBox();
|
maskedTextBoxNumber = new TextBox();
|
||||||
buttonRefreshCol = new Button();
|
buttonRefreshCol = new Button();
|
||||||
buttonDelMonorail = new Button();
|
buttonDelMonorail = new Button();
|
||||||
@ -37,32 +43,94 @@
|
|||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
|
panel2.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(5, -1);
|
pictureBoxCollection.Location = new Point(5, -1);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(931, 454);
|
pictureBoxCollection.Size = new Size(1017, 517);
|
||||||
pictureBoxCollection.TabIndex = 5;
|
pictureBoxCollection.TabIndex = 5;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
panel1.BackColor = SystemColors.Info;
|
panel1.BackColor = SystemColors.Info;
|
||||||
|
panel1.Controls.Add(panel2);
|
||||||
panel1.Controls.Add(maskedTextBoxNumber);
|
panel1.Controls.Add(maskedTextBoxNumber);
|
||||||
panel1.Controls.Add(buttonRefreshCol);
|
panel1.Controls.Add(buttonRefreshCol);
|
||||||
panel1.Controls.Add(buttonDelMonorail);
|
panel1.Controls.Add(buttonDelMonorail);
|
||||||
panel1.Controls.Add(buttonAddMonorail);
|
panel1.Controls.Add(buttonAddMonorail);
|
||||||
panel1.Controls.Add(label1);
|
panel1.Controls.Add(label1);
|
||||||
panel1.Location = new Point(942, 12);
|
panel1.Location = new Point(1025, -1);
|
||||||
panel1.Name = "panel1";
|
panel1.Name = "panel1";
|
||||||
panel1.Size = new Size(190, 429);
|
panel1.Size = new Size(204, 517);
|
||||||
panel1.TabIndex = 4;
|
panel1.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// panel2
|
||||||
|
//
|
||||||
|
panel2.Controls.Add(label2);
|
||||||
|
panel2.Controls.Add(listBoxStorages);
|
||||||
|
panel2.Controls.Add(textBoxStorageName);
|
||||||
|
panel2.Controls.Add(button1);
|
||||||
|
panel2.Controls.Add(ButtonAddObject);
|
||||||
|
panel2.Location = new Point(12, 20);
|
||||||
|
panel2.Name = "panel2";
|
||||||
|
panel2.Size = new Size(179, 263);
|
||||||
|
panel2.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(3, -3);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(66, 20);
|
||||||
|
label2.TabIndex = 8;
|
||||||
|
label2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 20;
|
||||||
|
listBoxStorages.Location = new Point(17, 109);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(144, 104);
|
||||||
|
listBoxStorages.TabIndex = 9;
|
||||||
|
listBoxStorages.Click += ListBoxObjects_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(18, 29);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(143, 27);
|
||||||
|
textBoxStorageName.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
button1.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
button1.Location = new Point(18, 219);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(143, 41);
|
||||||
|
button1.TabIndex = 5;
|
||||||
|
button1.Text = "Удалить набор";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
ButtonAddObject.Location = new Point(18, 62);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(143, 41);
|
||||||
|
ButtonAddObject.TabIndex = 6;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(29, 109);
|
maskedTextBoxNumber.Location = new Point(30, 336);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
@ -70,9 +138,9 @@
|
|||||||
// buttonRefreshCol
|
// buttonRefreshCol
|
||||||
//
|
//
|
||||||
buttonRefreshCol.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonRefreshCol.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonRefreshCol.Location = new Point(12, 237);
|
buttonRefreshCol.Location = new Point(12, 466);
|
||||||
buttonRefreshCol.Name = "buttonRefreshCol";
|
buttonRefreshCol.Name = "buttonRefreshCol";
|
||||||
buttonRefreshCol.Size = new Size(166, 41);
|
buttonRefreshCol.Size = new Size(179, 41);
|
||||||
buttonRefreshCol.TabIndex = 3;
|
buttonRefreshCol.TabIndex = 3;
|
||||||
buttonRefreshCol.Text = "Обновить коллекцию";
|
buttonRefreshCol.Text = "Обновить коллекцию";
|
||||||
buttonRefreshCol.UseVisualStyleBackColor = true;
|
buttonRefreshCol.UseVisualStyleBackColor = true;
|
||||||
@ -81,9 +149,9 @@
|
|||||||
// buttonDelMonorail
|
// buttonDelMonorail
|
||||||
//
|
//
|
||||||
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonDelMonorail.Location = new Point(12, 174);
|
buttonDelMonorail.Location = new Point(12, 369);
|
||||||
buttonDelMonorail.Name = "buttonDelMonorail";
|
buttonDelMonorail.Name = "buttonDelMonorail";
|
||||||
buttonDelMonorail.Size = new Size(166, 41);
|
buttonDelMonorail.Size = new Size(179, 41);
|
||||||
buttonDelMonorail.TabIndex = 2;
|
buttonDelMonorail.TabIndex = 2;
|
||||||
buttonDelMonorail.Text = "Удалить монорельс";
|
buttonDelMonorail.Text = "Удалить монорельс";
|
||||||
buttonDelMonorail.UseVisualStyleBackColor = true;
|
buttonDelMonorail.UseVisualStyleBackColor = true;
|
||||||
@ -92,9 +160,9 @@
|
|||||||
// buttonAddMonorail
|
// buttonAddMonorail
|
||||||
//
|
//
|
||||||
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonAddMonorail.Location = new Point(12, 29);
|
buttonAddMonorail.Location = new Point(12, 289);
|
||||||
buttonAddMonorail.Name = "buttonAddMonorail";
|
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||||
buttonAddMonorail.Size = new Size(166, 41);
|
buttonAddMonorail.Size = new Size(179, 41);
|
||||||
buttonAddMonorail.TabIndex = 1;
|
buttonAddMonorail.TabIndex = 1;
|
||||||
buttonAddMonorail.Text = "Добавить монорельс";
|
buttonAddMonorail.Text = "Добавить монорельс";
|
||||||
buttonAddMonorail.UseVisualStyleBackColor = true;
|
buttonAddMonorail.UseVisualStyleBackColor = true;
|
||||||
@ -114,7 +182,7 @@
|
|||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
BackColor = SystemColors.ControlDarkDark;
|
BackColor = SystemColors.ControlDarkDark;
|
||||||
ClientSize = new Size(1144, 453);
|
ClientSize = new Size(1228, 518);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(panel1);
|
Controls.Add(panel1);
|
||||||
Name = "FormMonorailCollection";
|
Name = "FormMonorailCollection";
|
||||||
@ -122,6 +190,8 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
panel1.PerformLayout();
|
panel1.PerformLayout();
|
||||||
|
panel2.ResumeLayout(false);
|
||||||
|
panel2.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,5 +204,11 @@
|
|||||||
private Button buttonAddMonorail;
|
private Button buttonAddMonorail;
|
||||||
private Label label1;
|
private Label label1;
|
||||||
private TextBox maskedTextBoxNumber;
|
private TextBox maskedTextBoxNumber;
|
||||||
|
private Button button1;
|
||||||
|
private Panel panel2;
|
||||||
|
private Label label2;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private Button ButtonAddObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,26 +13,97 @@ using Monorail.MovementStrategy;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class FormMonorailCollection : Form
|
public partial class FormMonorailCollection : Form
|
||||||
{
|
{
|
||||||
private readonly MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails;
|
private readonly MonorailsGenericStorage _storage;
|
||||||
|
|
||||||
public FormMonorailCollection()
|
public FormMonorailCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_monorails = new MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>
|
_storage = new MonorailsGenericStorage
|
||||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
|
}
|
||||||
|
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 ListBoxObjects_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonAddMonorail_Click(object sender, EventArgs e)
|
private void ButtonAddMonorail_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FormMonorail form = new();
|
FormMonorail form = new();
|
||||||
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_monorails + form.SelectedMonorail != -1)
|
int addedIndex = obj + form.SelectedMonorail;
|
||||||
|
if (addedIndex != -1 && addedIndex <= 20)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -42,6 +113,18 @@ namespace Monorail
|
|||||||
}
|
}
|
||||||
private void ButtonRemoveMonorail_Click(object sender, EventArgs e)
|
private void ButtonRemoveMonorail_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("Удалить объект?", "Удаление",
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
@ -57,10 +140,10 @@ namespace Monorail
|
|||||||
{
|
{
|
||||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
}
|
}
|
||||||
if (_monorails - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -69,7 +152,16 @@ namespace Monorail
|
|||||||
}
|
}
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,18 +33,18 @@ namespace Monorail.Generics
|
|||||||
}
|
}
|
||||||
return collect._collection.Insert(obj);
|
return collect._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
public static bool operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
public static T? operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
return obj;
|
||||||
}
|
}
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
public Bitmap ShowMonorails()
|
public Bitmap ShowMonorails()
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ namespace Monorail.Generics
|
|||||||
{
|
{
|
||||||
|
|
||||||
// TODO получение объекта
|
// TODO получение объекта
|
||||||
DrawningMonorail? _monorail = _collection.Get(indexPlaces);
|
DrawningMonorail? _monorail = _collection[indexPlaces];
|
||||||
indexPlaces++;
|
indexPlaces++;
|
||||||
|
|
||||||
if (_monorail != null)
|
if (_monorail != null)
|
||||||
|
52
Monorail/Monorail/Generics/MonorailsGenericStorage.cs
Normal file
52
Monorail/Monorail/Generics/MonorailsGenericStorage.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class MonorailsGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
|
||||||
|
DrawningObjectMonorail>> _monorailsStorages;
|
||||||
|
public List<string> Keys => _monorailsStorages.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
public MonorailsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_monorailsStorages = new Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
|
||||||
|
DrawningObjectMonorail>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight; ;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
//TO DO
|
||||||
|
_monorailsStorages.Add(name, new MonorailsGenericCollection<DrawningMonorail,
|
||||||
|
DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_monorailsStorages[name] == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_monorailsStorages.Remove(name);
|
||||||
|
}
|
||||||
|
public MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
//TO DO
|
||||||
|
if (_monorailsStorages[ind] == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _monorailsStorages[ind];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,59 +9,39 @@ namespace Monorail.Generics
|
|||||||
internal class SetGeneric<T>
|
internal class SetGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
public int Insert(T monorail)
|
public int Insert(T monorail)
|
||||||
{
|
{
|
||||||
if (monorail == null)
|
return Insert(monorail, 0);
|
||||||
|
}
|
||||||
|
public int Insert(T monorail, int position)
|
||||||
{
|
{
|
||||||
|
if (Count == _maxCount)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = Count-1; i != 0; i--)
|
if (position < 0 || monorail == null)
|
||||||
{
|
return -1;
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[0] = monorail;
|
|
||||||
|
|
||||||
return 0;
|
if (position >= _maxCount)
|
||||||
}
|
return -1;
|
||||||
public bool Insert(T monorail, int position)
|
|
||||||
|
|
||||||
|
if (Count == 0)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
_places.Add(monorail);
|
||||||
if (position >= Count)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
|
||||||
if (_places[position] != null)
|
|
||||||
{
|
|
||||||
for(int i = position + 1; i<Count; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
for (int j = i; j != position; j--)
|
|
||||||
{
|
|
||||||
_places[j] = _places[j - 1];
|
|
||||||
}
|
|
||||||
// TODO вставка по позиции
|
|
||||||
_places[position] = monorail;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_places[position] = monorail;
|
_places.Insert(position, monorail);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return Count;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
@ -81,8 +61,9 @@ namespace Monorail.Generics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
|
get {
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
if (position >= Count)
|
if (position >= Count)
|
||||||
{
|
{
|
||||||
@ -90,6 +71,34 @@ namespace Monorail.Generics
|
|||||||
}
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(position >= Count)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_places[position] = this[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxMonorails.HasValue && i == maxMonorails.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user