:(
This commit is contained in:
parent
f0138b67c1
commit
5f2bc387d9
@ -57,19 +57,22 @@
|
|||||||
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
|
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
|
||||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(600, 0);
|
this.groupBoxTools.Location = new System.Drawing.Point(685, 0);
|
||||||
|
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.groupBoxTools.Name = "groupBoxTools";
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
this.groupBoxTools.Size = new System.Drawing.Size(200, 450);
|
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(229, 664);
|
||||||
this.groupBoxTools.TabIndex = 0;
|
this.groupBoxTools.TabIndex = 0;
|
||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Tools";
|
this.groupBoxTools.Text = "Tools";
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 113);
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 151);
|
||||||
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23);
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
|
||||||
this.maskedTextBoxPosition.TabIndex = 11;
|
this.maskedTextBoxPosition.TabIndex = 11;
|
||||||
//
|
//
|
||||||
// keyRight
|
// keyRight
|
||||||
@ -77,9 +80,10 @@
|
|||||||
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
|
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
|
||||||
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.keyRight.Location = new System.Drawing.Point(122, 408);
|
this.keyRight.Location = new System.Drawing.Point(139, 608);
|
||||||
|
this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.keyRight.Name = "keyRight";
|
this.keyRight.Name = "keyRight";
|
||||||
this.keyRight.Size = new System.Drawing.Size(30, 30);
|
this.keyRight.Size = new System.Drawing.Size(34, 40);
|
||||||
this.keyRight.TabIndex = 10;
|
this.keyRight.TabIndex = 10;
|
||||||
this.keyRight.UseVisualStyleBackColor = true;
|
this.keyRight.UseVisualStyleBackColor = true;
|
||||||
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -89,9 +93,10 @@
|
|||||||
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
|
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
|
||||||
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.keyLeft.Location = new System.Drawing.Point(50, 408);
|
this.keyLeft.Location = new System.Drawing.Point(57, 608);
|
||||||
|
this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.keyLeft.Name = "keyLeft";
|
this.keyLeft.Name = "keyLeft";
|
||||||
this.keyLeft.Size = new System.Drawing.Size(30, 30);
|
this.keyLeft.Size = new System.Drawing.Size(34, 40);
|
||||||
this.keyLeft.TabIndex = 9;
|
this.keyLeft.TabIndex = 9;
|
||||||
this.keyLeft.UseVisualStyleBackColor = true;
|
this.keyLeft.UseVisualStyleBackColor = true;
|
||||||
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -101,9 +106,10 @@
|
|||||||
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
|
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
|
||||||
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.keyUp.Location = new System.Drawing.Point(86, 372);
|
this.keyUp.Location = new System.Drawing.Point(98, 560);
|
||||||
|
this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.keyUp.Name = "keyUp";
|
this.keyUp.Name = "keyUp";
|
||||||
this.keyUp.Size = new System.Drawing.Size(30, 30);
|
this.keyUp.Size = new System.Drawing.Size(34, 40);
|
||||||
this.keyUp.TabIndex = 8;
|
this.keyUp.TabIndex = 8;
|
||||||
this.keyUp.UseVisualStyleBackColor = true;
|
this.keyUp.UseVisualStyleBackColor = true;
|
||||||
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -113,18 +119,20 @@
|
|||||||
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
|
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
|
||||||
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.keyDown.Location = new System.Drawing.Point(86, 408);
|
this.keyDown.Location = new System.Drawing.Point(98, 608);
|
||||||
|
this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.keyDown.Name = "keyDown";
|
this.keyDown.Name = "keyDown";
|
||||||
this.keyDown.Size = new System.Drawing.Size(30, 30);
|
this.keyDown.Size = new System.Drawing.Size(34, 40);
|
||||||
this.keyDown.TabIndex = 7;
|
this.keyDown.TabIndex = 7;
|
||||||
this.keyDown.UseVisualStyleBackColor = true;
|
this.keyDown.UseVisualStyleBackColor = true;
|
||||||
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(8, 326);
|
this.buttonShowOnMap.Location = new System.Drawing.Point(9, 435);
|
||||||
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34);
|
this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45);
|
||||||
this.buttonShowOnMap.TabIndex = 4;
|
this.buttonShowOnMap.TabIndex = 4;
|
||||||
this.buttonShowOnMap.Text = "Show on map";
|
this.buttonShowOnMap.Text = "Show on map";
|
||||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
@ -132,9 +140,10 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(8, 241);
|
this.buttonShowStorage.Location = new System.Drawing.Point(9, 321);
|
||||||
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(186, 34);
|
this.buttonShowStorage.Size = new System.Drawing.Size(213, 45);
|
||||||
this.buttonShowStorage.TabIndex = 3;
|
this.buttonShowStorage.TabIndex = 3;
|
||||||
this.buttonShowStorage.Text = "Show storage";
|
this.buttonShowStorage.Text = "Show storage";
|
||||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
@ -142,9 +151,10 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveGasolineTanker
|
// buttonRemoveGasolineTanker
|
||||||
//
|
//
|
||||||
this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(10, 142);
|
this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(11, 189);
|
||||||
|
this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker";
|
this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker";
|
||||||
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34);
|
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45);
|
||||||
this.buttonRemoveGasolineTanker.TabIndex = 2;
|
this.buttonRemoveGasolineTanker.TabIndex = 2;
|
||||||
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
|
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
|
||||||
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
|
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
|
||||||
@ -152,9 +162,10 @@
|
|||||||
//
|
//
|
||||||
// buttonAddGasolineTanker
|
// buttonAddGasolineTanker
|
||||||
//
|
//
|
||||||
this.buttonAddGasolineTanker.Location = new System.Drawing.Point(8, 73);
|
this.buttonAddGasolineTanker.Location = new System.Drawing.Point(9, 97);
|
||||||
|
this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
|
this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
|
||||||
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34);
|
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45);
|
||||||
this.buttonAddGasolineTanker.TabIndex = 1;
|
this.buttonAddGasolineTanker.TabIndex = 1;
|
||||||
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
|
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
|
||||||
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
|
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
|
||||||
@ -165,9 +176,10 @@
|
|||||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
"Simple map",
|
"Simple map",
|
||||||
"Long map"});
|
"Long map"});
|
||||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 29);
|
||||||
|
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28);
|
||||||
this.comboBoxSelectorMap.TabIndex = 12;
|
this.comboBoxSelectorMap.TabIndex = 12;
|
||||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
@ -175,18 +187,20 @@
|
|||||||
//
|
//
|
||||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.pictureBox.Name = "pictureBox";
|
this.pictureBox.Name = "pictureBox";
|
||||||
this.pictureBox.Size = new System.Drawing.Size(600, 450);
|
this.pictureBox.Size = new System.Drawing.Size(685, 664);
|
||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormMapWithSetGasolineTanker
|
// FormMapWithSetGasolineTanker
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(914, 664);
|
||||||
this.Controls.Add(this.pictureBox);
|
this.Controls.Add(this.pictureBox);
|
||||||
this.Controls.Add(this.groupBoxTools);
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.Name = "FormMapWithSetGasolineTanker";
|
this.Name = "FormMapWithSetGasolineTanker";
|
||||||
this.Text = "FormMapWithSetGasolineTanker";
|
this.Text = "FormMapWithSetGasolineTanker";
|
||||||
this.groupBoxTools.ResumeLayout(false);
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
@ -49,13 +49,11 @@ namespace GasolineTanker
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
|
||||||
{
|
{
|
||||||
var gasolineTanker = _setGasolineTanker.Get(i);
|
|
||||||
if (gasolineTanker != null)
|
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
@ -74,11 +72,11 @@ namespace GasolineTanker
|
|||||||
int j = _setGasolineTanker.Count - 1;
|
int j = _setGasolineTanker.Count - 1;
|
||||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setGasolineTanker.Get(i) == null)
|
if (_setGasolineTanker[i] == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var gasolineTanker = _setGasolineTanker.Get(j);
|
var gasolineTanker = _setGasolineTanker[j];
|
||||||
if (gasolineTanker != null)
|
if (gasolineTanker != null)
|
||||||
{
|
{
|
||||||
_setGasolineTanker.Insert(gasolineTanker, i);
|
_setGasolineTanker.Insert(gasolineTanker, i);
|
||||||
@ -110,15 +108,17 @@ namespace GasolineTanker
|
|||||||
|
|
||||||
private void DrawGasolineTanker(Graphics g)
|
private void DrawGasolineTanker(Graphics g)
|
||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
|
||||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
|
||||||
{
|
{
|
||||||
if (_setGasolineTanker.Get(i) != null)
|
gasolineTanker.SetObject(width, height, _pictureWidth, _pictureHeight);
|
||||||
|
gasolineTanker.DrawningObject(g);
|
||||||
|
width += _placeSizeWidth;
|
||||||
|
if (width > _pictureWidth - _placeSizeWidth)
|
||||||
{
|
{
|
||||||
_setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
width = _placeSizeWidth / 10;
|
||||||
_setGasolineTanker.Get(i)?.DrawningObject(g);
|
height += _placeSizeHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
GasolineTanker/GasolineTanker/MapsCollection.cs
Normal file
45
GasolineTanker/GasolineTanker/MapsCollection.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GasolineTanker
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap>> _mapStorages;
|
||||||
|
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string, MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_mapStorages.TryGetValue(ind, out var map)) return map;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,72 +9,66 @@ namespace GasolineTanker
|
|||||||
internal class SetGasolineTankerGeneric<T>
|
internal class SetGasolineTankerGeneric<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 SetGasolineTankerGeneric(int count)
|
public SetGasolineTankerGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
}
|
}
|
||||||
public int Insert(T gasolineTanker)
|
public int Insert(T gasolineTanker)
|
||||||
{
|
{
|
||||||
if (_places[Count - 1] == null)
|
if (_places.Count < _maxCount)
|
||||||
{
|
{
|
||||||
for (int i = Count - 1; i > 0; i--)
|
_places.Add(gasolineTanker);
|
||||||
{
|
for (int i = 0; i < _places.Count; i++)
|
||||||
_places[i] = _places[i - 1];
|
{
|
||||||
}
|
if (_places[i] == gasolineTanker) return i;
|
||||||
_places[0] = gasolineTanker;
|
}
|
||||||
return 0;
|
}
|
||||||
}
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
public int Insert(T gasolineTanker, int position)
|
public int Insert(T gasolineTanker, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count) return -1;
|
if (position < 0 || position >= _places.Count) return -1;
|
||||||
if (_places[position] == null)
|
_places.Insert(position, gasolineTanker);
|
||||||
{
|
return position;
|
||||||
_places[position] = gasolineTanker;
|
}
|
||||||
return position;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_places[Count - 1] == null)
|
|
||||||
{
|
|
||||||
for (int i = Count - 1; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = gasolineTanker;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= _places.Count) return null;
|
||||||
return null;
|
if (_places[position] == null) return null;
|
||||||
if (_places[position] != null)
|
T removed = _places[position];
|
||||||
{
|
_places.RemoveAt(position);
|
||||||
T removed = _places[position];
|
return removed;
|
||||||
_places[position] = null;
|
}
|
||||||
if (position < Count - 1)
|
public T this[int position]
|
||||||
{
|
{
|
||||||
for (int k = position; k < Count - 1; k++)
|
get
|
||||||
{
|
{
|
||||||
_places[k] = _places[k + 1];
|
if (position < 0 || position >= _places.Count) return null;
|
||||||
}
|
return _places[position];
|
||||||
}
|
}
|
||||||
return removed;
|
set
|
||||||
}
|
{
|
||||||
return null;
|
if (position < 0 || position >= _places.Count) return;
|
||||||
}
|
_places.Insert(position, value);
|
||||||
public T Get(int position)
|
}
|
||||||
{
|
}
|
||||||
if (position >= Count || position < 0)
|
public IEnumerable<T> GetGasolineTanker()
|
||||||
return null;
|
{
|
||||||
|
foreach (var gasolineTanker in _places)
|
||||||
return _places[position];
|
{
|
||||||
}
|
if (gasolineTanker != null)
|
||||||
}
|
{
|
||||||
|
yield return gasolineTanker;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user