diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
index 8fbcbc4..75d6c35 100644
--- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
+++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs
@@ -7,12 +7,10 @@ namespace ProjectLocomotive
/// Βϋαπΰννϋι ξαϊεκς
///
public DrawningLocomotive SelectedLocomotive { get; private set; }
-
public FormLocomotive()
{
InitializeComponent();
}
-
///
/// Μεςξδ οπξπθρξβκθ ύλεκςπξλξκξμξςθβΰ
///
@@ -39,11 +37,9 @@ namespace ProjectLocomotive
///
///
///
-
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- //_elloc = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
@@ -113,19 +109,11 @@ namespace ProjectLocomotive
}
_elloc = new DrawningElectroLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
color,
- dopColor,
- //Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- //Color.FromArgb(rnd.Next(1, 100), rnd.Next(1, 100), rnd.Next(1, 100)),
+ dopColor,
Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
SetData();
Draw();
- }
-
- private void pictureBoxLocomotive_Click(object sender, EventArgs e)
- {
-
- }
-
+ }
private void buttonSelectLocomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _elloc;
diff --git a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs
index 09e40b0..dc30b2c 100644
--- a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs
+++ b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs
@@ -55,13 +55,9 @@ namespace ProjectLocomotive
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setLocomotives.Count; i++)
+ foreach (var locomotive in _setLocomotives.GetLocomotives())
{
- var locomotive = _setLocomotives.Get(i);
- if (locomotive != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -80,11 +76,11 @@ namespace ProjectLocomotive
int j = _setLocomotives.Count - 1;
for (int i = 0; i < _setLocomotives.Count; i++)
{
- if (_setLocomotives.Get(i) == null)
+ if (_setLocomotives[i] == null)
{
for (; j > i; j--)
{
- var locomotive = _setLocomotives.Get(j);
+ var locomotive = _setLocomotives[j];
if (locomotive != null)
{
_setLocomotives.Insert(locomotive, i);
@@ -101,43 +97,27 @@ namespace ProjectLocomotive
}
/// ΠΠ΅ΡΠΎΠ΄ ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠΈ ΡΠΎΠ½Π°
private void DrawBackground(Graphics g)
- {
- //Pen pen = new(Color.Black, 3);
- //for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
- //{
- // for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
- // { //Π»ΠΈΠ½ΠΈΡ ΡΠ°ΠΌΠ·Π΅ΡΠΊΠΈ ΠΌΠ΅ΡΡΠ°
- // g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
- // _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
- // }
- // g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
- // (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
- //}
+ {
Pen pen;
for (int j = _placeSizeHeight; j < _pictureHeight; j += _placeSizeHeight)
{
//Π½ΠΈΠΆΠ½ΡΡ Π»ΠΈΠ½ΠΈΡ ΡΠ΅Π»ΡΡ
pen = new(Color.Black, 5);
-
g.DrawLine(pen, 0, j, _pictureWidth, j);
for (int i = 0; i < _pictureWidth; i += 20)
{
g.DrawLine(pen, i, j, i, j + 10);
}
g.DrawLine(pen, 0, j + 10, _pictureWidth, j + 10);
-
//Π²Π΅ΡΡ
Π½ΡΡ Π»ΠΈΠ½ΠΈΡ ΡΠ΅Π»ΡΡ
-
pen = new(Color.DarkGray, 4);
-
g.DrawLine(pen, 0, j - 20, _pictureWidth, j - 20);
for (int i = 0; i < _pictureWidth; i += 20)
{
g.DrawLine(pen, i, j - 20, i, j - 10);
}
g.DrawLine(pen, 0, j - 10, _pictureWidth, j - 10);
-
//ΡΠΎΠ½Π°ΡΠΈ
for (int i = _placeSizeWidth; i < _pictureWidth; i += _placeSizeWidth)
{
@@ -157,12 +137,10 @@ namespace ProjectLocomotive
int curWidth = 0;
int curHeight = 0;
- for (int i = 0; i < _setLocomotives.Count; i++)
+ foreach (var locomotive in _setLocomotives.GetLocomotives())
{
- // ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΠΏΠΎΠ·ΠΈΡΠΈΠΈ
- //_setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth, curHeight * _placeSizeHeight, _pictureWidth, _pictureHeight);
- _setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 470, _pictureWidth, _pictureHeight);
- _setLocomotives.Get(i)?.DrawningObject(g);
+ locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
+ locomotive?.DrawningObject(g);
if (curWidth < width) curWidth++;
else
{
diff --git a/ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs b/ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs
index f15e904..dda3033 100644
--- a/ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs
+++ b/ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs
@@ -13,14 +13,17 @@ namespace ProjectLocomotive
internal class SetLocomotivesGeneric
where T : class
{
- private readonly T[] _places;
+ /// Π‘ΠΏΠΈΡΠΎΠΊ Ρ
ΡΠ°Π½ΠΈΠΌΡΡ
ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ²
+ private readonly List _places;
- /// ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² Π² ΠΌΠ°ΡΡΠΈΠ²Π΅
- public int Count => _places.Length;
+ /// ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² Π² ΡΠΏΠΈΡΠΊΠ΅
+ public int Count => _places.Count;
+ private readonly int _maxCount;
/// ΠΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ
public SetLocomotivesGeneric(int count)
{
- _places = new T[count];
+ _maxCount = count;
+ _places = new List();
}
/// ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° Π² Π½Π°Π±ΠΎΡ
public int Insert(T locomotive)
@@ -30,54 +33,46 @@ namespace ProjectLocomotive
/// ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° Π² Π½Π°Π±ΠΎΡ Π½Π° ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΡΡ ΠΏΠΎΠ·ΠΈΡΠΈΡ
public int Insert(T locomotive, int position)
{
- if (position >= _places.Length || position < 0) return -1;
-
- if (_places[position] == null)
- {
- _places[position] = locomotive;
- return position;
- }
-
- int emptyEl = -1;
-
- for (int i = position + 1; i < Count; i++)
- {
- if (_places[i] == null)
- {
- emptyEl = i;
- break;
- }
-
- }
-
- if (emptyEl == -1)
- {
- return -1;
- }
-
- for (int i = emptyEl; i > position; i--)
- {
- _places[i] = _places[i - 1];
- }
- _places[position] = locomotive;
+ if (position >= _maxCount || position < 0) return -1;
+ _places.Insert(position, locomotive);
return position;
}
/// Π£Π΄Π°Π»Π΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° ΠΈΠ· Π½Π°Π±ΠΎΡΠ° Ρ ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎΠΉ ΠΏΠΎΠ·ΠΈΡΠΈΠΈ
public T Remove(int position)
{
- if (position >= _places.Length || position < 0) return null;
- _places[position] = null;
+ if (position >= _maxCount || position < 0) return null;
T result = _places[position];
+ _places.RemoveAt(position);
return result;
}
- /// ΠΠΎΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° ΠΈΠ· Π½Π°Π±ΠΎΡΠ° ΠΏΠΎ ΠΏΠΎΠ·ΠΈΡΠΈΠΈ
- public T Get(int position)
+ // ΠΠ½Π΄Π΅ΠΊΡΠ°ΡΠΎΡ
+ public T this[int position]
{
- if (position >= _places.Length || position < 0)
+ get
{
- return null;
+ if (position >= _maxCount || position < 0) return null;
+ return _places[position];
+ }
+ set
+ {
+ if (position >= _maxCount || position < 0) return;
+ Insert(value, position);
+ }
+ }
+ /// ΠΡΠΎΡ
ΠΎΠ΄ ΠΏΠΎ Π½Π°Π±ΠΎΡΡ Π΄ΠΎ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΠΏΡΡΡΠΎΠ³ΠΎ
+ public IEnumerable GetLocomotives()
+ {
+ foreach (var locomotive in _places)
+ {
+ if (locomotive != null)
+ {
+ yield return locomotive;
+ }
+ else
+ {
+ yield break;
+ }
}
- return _places[position];
}
}
}