I think it's done

This commit is contained in:
gg12 darfren 2023-10-15 20:12:28 +04:00
parent daa6d8c91f
commit 489f116e75
6 changed files with 289 additions and 72 deletions

View File

@ -29,38 +29,96 @@
private void InitializeComponent() private void InitializeComponent()
{ {
toolGroupBox = new System.Windows.Forms.GroupBox(); 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(); maskedTextBox = new System.Windows.Forms.MaskedTextBox();
updateCollectionButton = new System.Windows.Forms.Button(); updateCollectionButton = new System.Windows.Forms.Button();
deleteMonorailButton = new System.Windows.Forms.Button(); deleteMonorailButton = new System.Windows.Forms.Button();
addMonorailButton = new System.Windows.Forms.Button(); addMonorailButton = new System.Windows.Forms.Button();
pictureBoxCollection = new System.Windows.Forms.PictureBox(); pictureBoxCollection = new System.Windows.Forms.PictureBox();
toolGroupBox.SuspendLayout(); toolGroupBox.SuspendLayout();
storageGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// toolGroupBox // toolGroupBox
// //
toolGroupBox.Anchor = System.Windows.Forms.AnchorStyles.Right;
toolGroupBox.Controls.Add(storageGroupBox);
toolGroupBox.Controls.Add(maskedTextBox); toolGroupBox.Controls.Add(maskedTextBox);
toolGroupBox.Controls.Add(updateCollectionButton); toolGroupBox.Controls.Add(updateCollectionButton);
toolGroupBox.Controls.Add(deleteMonorailButton); toolGroupBox.Controls.Add(deleteMonorailButton);
toolGroupBox.Controls.Add(addMonorailButton); toolGroupBox.Controls.Add(addMonorailButton);
toolGroupBox.Location = new System.Drawing.Point(623, 12); toolGroupBox.Location = new System.Drawing.Point(743, 12);
toolGroupBox.Name = "toolGroupBox"; toolGroupBox.Name = "toolGroupBox";
toolGroupBox.Size = new System.Drawing.Size(227, 426); toolGroupBox.Size = new System.Drawing.Size(227, 529);
toolGroupBox.TabIndex = 0; toolGroupBox.TabIndex = 0;
toolGroupBox.TabStop = false; toolGroupBox.TabStop = false;
toolGroupBox.Text = "Инструменты"; 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
// //
maskedTextBox.Location = new System.Drawing.Point(6, 72); maskedTextBox.Location = new System.Drawing.Point(6, 404);
maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new System.Drawing.Size(125, 27); maskedTextBox.Size = new System.Drawing.Size(125, 27);
maskedTextBox.TabIndex = 4; maskedTextBox.TabIndex = 4;
// //
// updateCollectionButton // updateCollectionButton
// //
updateCollectionButton.Location = new System.Drawing.Point(6, 151); updateCollectionButton.Location = new System.Drawing.Point(6, 483);
updateCollectionButton.Name = "updateCollectionButton"; updateCollectionButton.Name = "updateCollectionButton";
updateCollectionButton.Size = new System.Drawing.Size(215, 40); updateCollectionButton.Size = new System.Drawing.Size(215, 40);
updateCollectionButton.TabIndex = 3; updateCollectionButton.TabIndex = 3;
@ -70,7 +128,7 @@
// //
// deleteMonorailButton // deleteMonorailButton
// //
deleteMonorailButton.Location = new System.Drawing.Point(6, 105); deleteMonorailButton.Location = new System.Drawing.Point(6, 437);
deleteMonorailButton.Name = "deleteMonorailButton"; deleteMonorailButton.Name = "deleteMonorailButton";
deleteMonorailButton.Size = new System.Drawing.Size(215, 40); deleteMonorailButton.Size = new System.Drawing.Size(215, 40);
deleteMonorailButton.TabIndex = 2; deleteMonorailButton.TabIndex = 2;
@ -80,7 +138,7 @@
// //
// addMonorailButton // addMonorailButton
// //
addMonorailButton.Location = new System.Drawing.Point(6, 26); addMonorailButton.Location = new System.Drawing.Point(6, 358);
addMonorailButton.Name = "addMonorailButton"; addMonorailButton.Name = "addMonorailButton";
addMonorailButton.Size = new System.Drawing.Size(215, 40); addMonorailButton.Size = new System.Drawing.Size(215, 40);
addMonorailButton.TabIndex = 0; addMonorailButton.TabIndex = 0;
@ -92,7 +150,7 @@
// //
pictureBoxCollection.Location = new System.Drawing.Point(12, 12); pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
pictureBoxCollection.Name = "pictureBoxCollection"; pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new System.Drawing.Size(605, 426); pictureBoxCollection.Size = new System.Drawing.Size(725, 529);
pictureBoxCollection.TabIndex = 1; pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false; pictureBoxCollection.TabStop = false;
// //
@ -100,13 +158,15 @@
// //
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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(pictureBoxCollection);
Controls.Add(toolGroupBox); Controls.Add(toolGroupBox);
Name = "FormMonorailCollection"; Name = "FormMonorailCollection";
Text = "FormMonorailCollection"; Text = "FormMonorailCollection";
toolGroupBox.ResumeLayout(false); toolGroupBox.ResumeLayout(false);
toolGroupBox.PerformLayout(); toolGroupBox.PerformLayout();
storageGroupBox.ResumeLayout(false);
storageGroupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
@ -119,5 +179,11 @@
private System.Windows.Forms.Button addMonorailButton; private System.Windows.Forms.Button addMonorailButton;
private System.Windows.Forms.PictureBox pictureBoxCollection; private System.Windows.Forms.PictureBox pictureBoxCollection;
private System.Windows.Forms.MaskedTextBox maskedTextBox; 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;
} }
} }

View File

@ -15,24 +15,56 @@ namespace Monorail
{ {
public partial class FormMonorailCollection : Form public partial class FormMonorailCollection : Form
{ {
private readonly MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails; private readonly MonorailGenericStorage _storage;
public FormMonorailCollection() public FormMonorailCollection()
{ {
InitializeComponent(); InitializeComponent();
_monorails = new MonorailGenericCollection<DrawningMonorail, _storage = new MonorailGenericStorage(pictureBoxCollection.Width,
DrawningObjectMonorail>(pictureBoxCollection.Width, pictureBoxCollection.Height); 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) 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(); MonorailForm form = new();
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (_monorails + form.SelectedMonorail != null) if (obj + form.SelectedMonorail)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _monorails.ShowMonorails(); pictureBoxCollection.Image = obj.ShowMonorails();
} }
else else
{ {
@ -44,16 +76,26 @@ DrawningObjectMonorail>(pictureBoxCollection.Width, pictureBoxCollection.Height)
private void deleteMonorailButton_Click(object sender, EventArgs e) 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("Удалить объект?", "Удаление", if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{ {
return; return;
} }
int pos = Convert.ToInt32(maskedTextBox.Text); int pos = Convert.ToInt32(maskedTextBox.Text);
if (_monorails - pos != null) if (obj - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _monorails.ShowMonorails(); pictureBoxCollection.Image = obj.ShowMonorails();
} }
else else
{ {
@ -63,8 +105,52 @@ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
private void updateCollectionButton_Click(object sender, EventArgs e) 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();
}
} }
} }

View File

@ -48,7 +48,7 @@ namespace Monorail
pictureBoxMonorail.Dock = System.Windows.Forms.DockStyle.Fill; pictureBoxMonorail.Dock = System.Windows.Forms.DockStyle.Fill;
pictureBoxMonorail.Location = new System.Drawing.Point(0, 0); pictureBoxMonorail.Location = new System.Drawing.Point(0, 0);
pictureBoxMonorail.Name = "pictureBoxMonorail"; 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.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
pictureBoxMonorail.TabIndex = 0; pictureBoxMonorail.TabIndex = 0;
pictureBoxMonorail.TabStop = false; pictureBoxMonorail.TabStop = false;
@ -56,7 +56,7 @@ namespace Monorail
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; 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.Name = "buttonCreate";
buttonCreate.Size = new System.Drawing.Size(180, 40); buttonCreate.Size = new System.Drawing.Size(180, 40);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
@ -69,7 +69,7 @@ namespace Monorail
buttonLeft.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; buttonLeft.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
buttonLeft.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonLeft.BackgroundImage"); buttonLeft.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonLeft";
buttonLeft.Size = new System.Drawing.Size(30, 30); buttonLeft.Size = new System.Drawing.Size(30, 30);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
@ -81,7 +81,7 @@ namespace Monorail
buttonRight.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; buttonRight.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
buttonRight.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonRight.BackgroundImage"); buttonRight.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonRight";
buttonRight.Size = new System.Drawing.Size(30, 30); buttonRight.Size = new System.Drawing.Size(30, 30);
buttonRight.TabIndex = 3; buttonRight.TabIndex = 3;
@ -93,7 +93,7 @@ namespace Monorail
buttonUp.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; buttonUp.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
buttonUp.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonUp.BackgroundImage"); buttonUp.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonUp";
buttonUp.Size = new System.Drawing.Size(30, 30); buttonUp.Size = new System.Drawing.Size(30, 30);
buttonUp.TabIndex = 4; buttonUp.TabIndex = 4;
@ -105,7 +105,7 @@ namespace Monorail
buttonDown.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; buttonDown.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
buttonDown.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonDown.BackgroundImage"); buttonDown.BackgroundImage = (System.Drawing.Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonDown";
buttonDown.Size = new System.Drawing.Size(30, 30); buttonDown.Size = new System.Drawing.Size(30, 30);
buttonDown.TabIndex = 5; buttonDown.TabIndex = 5;
@ -134,7 +134,8 @@ namespace Monorail
// //
// buttonCreateAdvanced // 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.Name = "buttonCreateAdvanced";
buttonCreateAdvanced.Size = new System.Drawing.Size(180, 40); buttonCreateAdvanced.Size = new System.Drawing.Size(180, 40);
buttonCreateAdvanced.TabIndex = 8; buttonCreateAdvanced.TabIndex = 8;
@ -144,7 +145,8 @@ namespace Monorail
// //
// buttonSelectMonorail // 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.Name = "buttonSelectMonorail";
buttonSelectMonorail.Size = new System.Drawing.Size(180, 40); buttonSelectMonorail.Size = new System.Drawing.Size(180, 40);
buttonSelectMonorail.TabIndex = 9; buttonSelectMonorail.TabIndex = 9;
@ -156,7 +158,7 @@ namespace Monorail
// //
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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(buttonSelectMonorail);
Controls.Add(buttonCreateAdvanced); Controls.Add(buttonCreateAdvanced);
Controls.Add(buttonStep); Controls.Add(buttonStep);

View File

@ -32,25 +32,26 @@ namespace Monorail.Generics
_collection = new SetGeneric<T>(width * height); _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) if (obj == null)
return -1; return false;
return collect?._collection.Insert(obj) ?? -1;
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) 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()
@ -81,18 +82,15 @@ pos)
private void DrawObjects(Graphics g) 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); int inRow = _pictureWidth / _placeSizeWidth;
if (monorail != null) monorail.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow +1) *_placeSizeHeight );
{ monorail.DrawTransport(g);
int inRow = _pictureWidth / _placeSizeWidth; i++;
monorail.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight );
monorail.DrawTransport(g);
}
} }
} }
} }
} }

View 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;
}
}
}
}

View File

@ -9,52 +9,66 @@ 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 bool Insert(T monorail)
{ {
if (_places[Count-1] != null) if (_places.Count == _maxCount)
return -1; return false;
return Insert(monorail, 0); Insert(monorail, 0);
return true;
} }
public int Insert(T monorail, int position) public bool Insert(T monorail, int position)
{ {
if (!(position >= 0 && position < Count)) if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return -1; return false;
if (_places[position] != null) _places.Insert(position, monorail);
{ return true;
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;
} }
public bool Remove(int position) public bool Remove(int position)
{ {
if (!(position >= 0 && position < Count) || _places[position] == null) if (!(position >= 0 && position < Count))
return false; return false;
_places[position] = null; _places.RemoveAt(position);
return true; return true;
} }
public T? this[int position]
public T? Get(int position)
{ {
if (!(position >= 0 && position < Count)) get {
return null; if (!(position >= 0 && position < Count))
return _places[position]; 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;
}
}
}
} }
} }