:(
This commit is contained in:
parent
f0138b67c1
commit
5f2bc387d9
@ -57,19 +57,22 @@
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
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.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.TabStop = false;
|
||||
this.groupBoxTools.Text = "Tools";
|
||||
//
|
||||
// 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.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23);
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 11;
|
||||
//
|
||||
// keyRight
|
||||
@ -77,9 +80,10 @@
|
||||
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.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.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyRight.Size = new System.Drawing.Size(34, 40);
|
||||
this.keyRight.TabIndex = 10;
|
||||
this.keyRight.UseVisualStyleBackColor = true;
|
||||
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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
|
||||
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.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyLeft.Size = new System.Drawing.Size(34, 40);
|
||||
this.keyLeft.TabIndex = 9;
|
||||
this.keyLeft.UseVisualStyleBackColor = true;
|
||||
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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
|
||||
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.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyUp.Size = new System.Drawing.Size(34, 40);
|
||||
this.keyUp.TabIndex = 8;
|
||||
this.keyUp.UseVisualStyleBackColor = true;
|
||||
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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
|
||||
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.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyDown.Size = new System.Drawing.Size(34, 40);
|
||||
this.keyDown.TabIndex = 7;
|
||||
this.keyDown.UseVisualStyleBackColor = true;
|
||||
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(186, 34);
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45);
|
||||
this.buttonShowOnMap.TabIndex = 4;
|
||||
this.buttonShowOnMap.Text = "Show on map";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
@ -132,9 +140,10 @@
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(186, 34);
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(213, 45);
|
||||
this.buttonShowStorage.TabIndex = 3;
|
||||
this.buttonShowStorage.Text = "Show storage";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
@ -142,9 +151,10 @@
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(186, 34);
|
||||
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45);
|
||||
this.buttonRemoveGasolineTanker.TabIndex = 2;
|
||||
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
|
||||
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
|
||||
@ -152,9 +162,10 @@
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(186, 34);
|
||||
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45);
|
||||
this.buttonAddGasolineTanker.TabIndex = 1;
|
||||
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
|
||||
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
|
||||
@ -165,9 +176,10 @@
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Simple 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.Size = new System.Drawing.Size(188, 23);
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 12;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
@ -175,18 +187,20 @@
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
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.Size = new System.Drawing.Size(600, 450);
|
||||
this.pictureBox.Size = new System.Drawing.Size(685, 664);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// 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.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(914, 664);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMapWithSetGasolineTanker";
|
||||
this.Text = "FormMapWithSetGasolineTanker";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
|
@ -49,13 +49,11 @@ namespace GasolineTanker
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
||||
{
|
||||
var gasolineTanker = _setGasolineTanker.Get(i);
|
||||
if (gasolineTanker != null)
|
||||
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
|
||||
{
|
||||
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
|
||||
}
|
||||
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -74,11 +72,11 @@ namespace GasolineTanker
|
||||
int j = _setGasolineTanker.Count - 1;
|
||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
||||
{
|
||||
if (_setGasolineTanker.Get(i) == null)
|
||||
if (_setGasolineTanker[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var gasolineTanker = _setGasolineTanker.Get(j);
|
||||
var gasolineTanker = _setGasolineTanker[j];
|
||||
if (gasolineTanker != null)
|
||||
{
|
||||
_setGasolineTanker.Insert(gasolineTanker, i);
|
||||
@ -112,13 +110,15 @@ namespace GasolineTanker
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
||||
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
|
||||
{
|
||||
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);
|
||||
_setGasolineTanker.Get(i)?.DrawningObject(g);
|
||||
width = _placeSizeWidth / 10;
|
||||
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>
|
||||
where T : class
|
||||
{
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
public SetGasolineTankerGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
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;
|
||||
}
|
||||
public int Insert(T gasolineTanker, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return -1;
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = gasolineTanker;
|
||||
if (position < 0 || position >= _places.Count) return -1;
|
||||
_places.Insert(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)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
if (position < 0 || position >= _places.Count) return null;
|
||||
if (_places[position] == null) return null;
|
||||
T removed = _places[position];
|
||||
_places[position] = null;
|
||||
if (position < Count - 1)
|
||||
{
|
||||
for (int k = position; k < Count - 1; k++)
|
||||
{
|
||||
_places[k] = _places[k + 1];
|
||||
}
|
||||
}
|
||||
_places.RemoveAt(position);
|
||||
return removed;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _places.Count) return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= _places.Count) return;
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
public IEnumerable<T> GetGasolineTanker()
|
||||
{
|
||||
foreach (var gasolineTanker in _places)
|
||||
{
|
||||
if (gasolineTanker != null)
|
||||
{
|
||||
yield return gasolineTanker;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user