I think it's done
This commit is contained in:
parent
daa6d8c91f
commit
489f116e75
82
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
82
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
@ -29,38 +29,96 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
toolGroupBox = new System.Windows.Forms.GroupBox();
|
||||
storageGroupBox = new System.Windows.Forms.GroupBox();
|
||||
listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
delStorageButton = new System.Windows.Forms.Button();
|
||||
addStorageButton = new System.Windows.Forms.Button();
|
||||
storageAddNameBox = new System.Windows.Forms.MaskedTextBox();
|
||||
maskedTextBox = new System.Windows.Forms.MaskedTextBox();
|
||||
updateCollectionButton = new System.Windows.Forms.Button();
|
||||
deleteMonorailButton = new System.Windows.Forms.Button();
|
||||
addMonorailButton = new System.Windows.Forms.Button();
|
||||
pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
toolGroupBox.SuspendLayout();
|
||||
storageGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// toolGroupBox
|
||||
//
|
||||
toolGroupBox.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||
toolGroupBox.Controls.Add(storageGroupBox);
|
||||
toolGroupBox.Controls.Add(maskedTextBox);
|
||||
toolGroupBox.Controls.Add(updateCollectionButton);
|
||||
toolGroupBox.Controls.Add(deleteMonorailButton);
|
||||
toolGroupBox.Controls.Add(addMonorailButton);
|
||||
toolGroupBox.Location = new System.Drawing.Point(623, 12);
|
||||
toolGroupBox.Location = new System.Drawing.Point(743, 12);
|
||||
toolGroupBox.Name = "toolGroupBox";
|
||||
toolGroupBox.Size = new System.Drawing.Size(227, 426);
|
||||
toolGroupBox.Size = new System.Drawing.Size(227, 529);
|
||||
toolGroupBox.TabIndex = 0;
|
||||
toolGroupBox.TabStop = false;
|
||||
toolGroupBox.Text = "Инструменты";
|
||||
//
|
||||
// storageGroupBox
|
||||
//
|
||||
storageGroupBox.Controls.Add(listBoxStorages);
|
||||
storageGroupBox.Controls.Add(delStorageButton);
|
||||
storageGroupBox.Controls.Add(addStorageButton);
|
||||
storageGroupBox.Controls.Add(storageAddNameBox);
|
||||
storageGroupBox.Location = new System.Drawing.Point(0, 26);
|
||||
storageGroupBox.Name = "storageGroupBox";
|
||||
storageGroupBox.Size = new System.Drawing.Size(227, 317);
|
||||
storageGroupBox.TabIndex = 5;
|
||||
storageGroupBox.TabStop = false;
|
||||
storageGroupBox.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 20;
|
||||
listBoxStorages.Location = new System.Drawing.Point(6, 94);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new System.Drawing.Size(215, 184);
|
||||
listBoxStorages.TabIndex = 4;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// delStorageButton
|
||||
//
|
||||
delStorageButton.Location = new System.Drawing.Point(6, 282);
|
||||
delStorageButton.Name = "delStorageButton";
|
||||
delStorageButton.Size = new System.Drawing.Size(215, 29);
|
||||
delStorageButton.TabIndex = 3;
|
||||
delStorageButton.Text = "Удалить набор";
|
||||
delStorageButton.UseVisualStyleBackColor = true;
|
||||
delStorageButton.Click += delStorageButton_Click;
|
||||
//
|
||||
// addStorageButton
|
||||
//
|
||||
addStorageButton.Location = new System.Drawing.Point(6, 59);
|
||||
addStorageButton.Name = "addStorageButton";
|
||||
addStorageButton.Size = new System.Drawing.Size(215, 29);
|
||||
addStorageButton.TabIndex = 1;
|
||||
addStorageButton.Text = "Добавить набор";
|
||||
addStorageButton.UseVisualStyleBackColor = true;
|
||||
addStorageButton.Click += addStorageButton_Click;
|
||||
//
|
||||
// storageAddNameBox
|
||||
//
|
||||
storageAddNameBox.Location = new System.Drawing.Point(6, 26);
|
||||
storageAddNameBox.Name = "storageAddNameBox";
|
||||
storageAddNameBox.Size = new System.Drawing.Size(215, 27);
|
||||
storageAddNameBox.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new System.Drawing.Point(6, 72);
|
||||
maskedTextBox.Location = new System.Drawing.Point(6, 404);
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new System.Drawing.Size(125, 27);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
//
|
||||
// updateCollectionButton
|
||||
//
|
||||
updateCollectionButton.Location = new System.Drawing.Point(6, 151);
|
||||
updateCollectionButton.Location = new System.Drawing.Point(6, 483);
|
||||
updateCollectionButton.Name = "updateCollectionButton";
|
||||
updateCollectionButton.Size = new System.Drawing.Size(215, 40);
|
||||
updateCollectionButton.TabIndex = 3;
|
||||
@ -70,7 +128,7 @@
|
||||
//
|
||||
// deleteMonorailButton
|
||||
//
|
||||
deleteMonorailButton.Location = new System.Drawing.Point(6, 105);
|
||||
deleteMonorailButton.Location = new System.Drawing.Point(6, 437);
|
||||
deleteMonorailButton.Name = "deleteMonorailButton";
|
||||
deleteMonorailButton.Size = new System.Drawing.Size(215, 40);
|
||||
deleteMonorailButton.TabIndex = 2;
|
||||
@ -80,7 +138,7 @@
|
||||
//
|
||||
// addMonorailButton
|
||||
//
|
||||
addMonorailButton.Location = new System.Drawing.Point(6, 26);
|
||||
addMonorailButton.Location = new System.Drawing.Point(6, 358);
|
||||
addMonorailButton.Name = "addMonorailButton";
|
||||
addMonorailButton.Size = new System.Drawing.Size(215, 40);
|
||||
addMonorailButton.TabIndex = 0;
|
||||
@ -92,7 +150,7 @@
|
||||
//
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(605, 426);
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(725, 529);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
@ -100,13 +158,15 @@
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(862, 450);
|
||||
ClientSize = new System.Drawing.Size(982, 553);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(toolGroupBox);
|
||||
Name = "FormMonorailCollection";
|
||||
Text = "FormMonorailCollection";
|
||||
toolGroupBox.ResumeLayout(false);
|
||||
toolGroupBox.PerformLayout();
|
||||
storageGroupBox.ResumeLayout(false);
|
||||
storageGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -119,5 +179,11 @@
|
||||
private System.Windows.Forms.Button addMonorailButton;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBox;
|
||||
private System.Windows.Forms.GroupBox storageGroupBox;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBox1;
|
||||
private System.Windows.Forms.Button addStorageButton;
|
||||
private System.Windows.Forms.MaskedTextBox storageAddNameBox;
|
||||
private System.Windows.Forms.Button delStorageButton;
|
||||
private System.Windows.Forms.ListBox listBoxStorages;
|
||||
}
|
||||
}
|
@ -15,24 +15,56 @@ namespace Monorail
|
||||
{
|
||||
public partial class FormMonorailCollection : Form
|
||||
{
|
||||
private readonly MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails;
|
||||
private readonly MonorailGenericStorage _storage;
|
||||
|
||||
public FormMonorailCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_monorails = new MonorailGenericCollection<DrawningMonorail,
|
||||
DrawningObjectMonorail>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_storage = new MonorailGenericStorage(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addMonorailButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MonorailForm form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_monorails + form.SelectedMonorail != null)
|
||||
if (obj + form.SelectedMonorail)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -44,16 +76,26 @@ DrawningObjectMonorail>(pictureBoxCollection.Width, pictureBoxCollection.Height)
|
||||
|
||||
private void deleteMonorailButton_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("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_monorails - pos != null)
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -63,8 +105,52 @@ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
|
||||
private void updateCollectionButton_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();
|
||||
|
||||
}
|
||||
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||
}
|
||||
|
||||
private void delStorageButton_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 addStorageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageAddNameBox.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(storageAddNameBox.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
Monorail/Monorail/MonorailForm.Designer.cs
generated
20
Monorail/Monorail/MonorailForm.Designer.cs
generated
@ -48,7 +48,7 @@ namespace Monorail
|
||||
pictureBoxMonorail.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
pictureBoxMonorail.Location = new System.Drawing.Point(0, 0);
|
||||
pictureBoxMonorail.Name = "pictureBoxMonorail";
|
||||
pictureBoxMonorail.Size = new System.Drawing.Size(882, 453);
|
||||
pictureBoxMonorail.Size = new System.Drawing.Size(725, 529);
|
||||
pictureBoxMonorail.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxMonorail.TabIndex = 0;
|
||||
pictureBoxMonorail.TabStop = false;
|
||||
@ -56,7 +56,7 @@ namespace Monorail
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
buttonCreate.Location = new System.Drawing.Point(198, 401);
|
||||
buttonCreate.Location = new System.Drawing.Point(198, 477);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new System.Drawing.Size(180, 40);
|
||||
buttonCreate.TabIndex = 1;
|
||||
@ -69,7 +69,7 @@ namespace Monorail
|
||||
buttonLeft.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonLeft.Location = new System.Drawing.Point(768, 411);
|
||||
buttonLeft.Location = new System.Drawing.Point(611, 487);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
@ -81,7 +81,7 @@ namespace Monorail
|
||||
buttonRight.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonRight.Location = new System.Drawing.Point(840, 411);
|
||||
buttonRight.Location = new System.Drawing.Point(683, 487);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
buttonRight.TabIndex = 3;
|
||||
@ -93,7 +93,7 @@ namespace Monorail
|
||||
buttonUp.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonUp.Location = new System.Drawing.Point(804, 375);
|
||||
buttonUp.Location = new System.Drawing.Point(647, 451);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
buttonUp.TabIndex = 4;
|
||||
@ -105,7 +105,7 @@ namespace Monorail
|
||||
buttonDown.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonDown.Location = new System.Drawing.Point(804, 411);
|
||||
buttonDown.Location = new System.Drawing.Point(647, 487);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
buttonDown.TabIndex = 5;
|
||||
@ -134,7 +134,8 @@ namespace Monorail
|
||||
//
|
||||
// buttonCreateAdvanced
|
||||
//
|
||||
buttonCreateAdvanced.Location = new System.Drawing.Point(12, 401);
|
||||
buttonCreateAdvanced.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
buttonCreateAdvanced.Location = new System.Drawing.Point(12, 477);
|
||||
buttonCreateAdvanced.Name = "buttonCreateAdvanced";
|
||||
buttonCreateAdvanced.Size = new System.Drawing.Size(180, 40);
|
||||
buttonCreateAdvanced.TabIndex = 8;
|
||||
@ -144,7 +145,8 @@ namespace Monorail
|
||||
//
|
||||
// buttonSelectMonorail
|
||||
//
|
||||
buttonSelectMonorail.Location = new System.Drawing.Point(384, 401);
|
||||
buttonSelectMonorail.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
buttonSelectMonorail.Location = new System.Drawing.Point(384, 477);
|
||||
buttonSelectMonorail.Name = "buttonSelectMonorail";
|
||||
buttonSelectMonorail.Size = new System.Drawing.Size(180, 40);
|
||||
buttonSelectMonorail.TabIndex = 9;
|
||||
@ -156,7 +158,7 @@ namespace Monorail
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(882, 453);
|
||||
ClientSize = new System.Drawing.Size(725, 529);
|
||||
Controls.Add(buttonSelectMonorail);
|
||||
Controls.Add(buttonCreateAdvanced);
|
||||
Controls.Add(buttonStep);
|
||||
|
@ -32,25 +32,26 @@ namespace Monorail.Generics
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static int operator +(MonorailGenericCollection<T,U> collect, T? obj)
|
||||
public static bool operator +(MonorailGenericCollection<T,U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
return false;
|
||||
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator -(MonorailGenericCollection<T, U> collect, int
|
||||
public static T? operator -(MonorailGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
return collect._collection.Remove(pos);
|
||||
return false;
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowMonorails()
|
||||
@ -81,18 +82,15 @@ pos)
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
int i = 0;
|
||||
foreach(var monorail in _collection.GetMonorails())
|
||||
{
|
||||
DrawningMonorail monorail = _collection.Get(i);
|
||||
if (monorail != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
monorail.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight );
|
||||
monorail.DrawTransport(g);
|
||||
}
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
monorail.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow +1) *_placeSizeHeight );
|
||||
monorail.DrawTransport(g);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
51
Monorail/Monorail/MonorailGenericStorage.cs
Normal file
51
Monorail/Monorail/MonorailGenericStorage.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
internal class MonorailGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> _monorailStorages;
|
||||
public List<string> Keys => _monorailStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MonorailGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_monorailStorages = new Dictionary<string,
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> (_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_monorailStorages.ContainsKey(name) == null)
|
||||
return;
|
||||
_monorailStorages.Remove(name);
|
||||
}
|
||||
|
||||
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_monorailStorages.ContainsKey(ind))
|
||||
return _monorailStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,52 +9,66 @@ namespace Monorail.Generics
|
||||
internal class SetGeneric<T>
|
||||
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)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
|
||||
public int Insert(T monorail)
|
||||
public bool Insert(T monorail)
|
||||
{
|
||||
if (_places[Count-1] != null)
|
||||
return -1;
|
||||
return Insert(monorail, 0);
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
Insert(monorail, 0);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public int Insert(T monorail, int position)
|
||||
public bool Insert(T monorail, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = monorail;
|
||||
return position;
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
return false;
|
||||
_places.Insert(position, monorail);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
get {
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set {
|
||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||
return;
|
||||
_places.Insert(position, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user