Yahontov O.U. LabWork4 #5
@ -136,8 +136,9 @@ namespace Trolleybus
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
Brush dBlue = new SolidBrush(Color.DarkBlue);
|
||||
Brush bWhite = new SolidBrush(Color.White);
|
||||
Brush br = new SolidBrush(Trolleybus?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, _startPosX, _startPosY, 200, 50);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY, 200, 50);
|
||||
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 20, 40);
|
||||
Pen WinBlue = new Pen(Color.Blue);
|
||||
|
@ -29,6 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
@ -38,14 +44,15 @@
|
||||
this.buttonRemoveTrolleybus = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddTrolleybus = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
@ -55,20 +62,80 @@
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveTrolleybus);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox1.Controls.Add(this.buttonAddTrolleybus);
|
||||
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(600, 0);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(200, 450);
|
||||
this.groupBox1.Size = new System.Drawing.Size(200, 648);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBox2.Controls.Add(this.listBoxMaps);
|
||||
this.groupBox2.Controls.Add(this.buttonAddMap);
|
||||
this.groupBox2.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBox2.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox2.Location = new System.Drawing.Point(6, 19);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(181, 287);
|
||||
this.groupBox2.TabIndex = 2;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(7, 204);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonDeleteMap.TabIndex = 4;
|
||||
this.buttonDeleteMap.Text = "Удалить Карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(7, 102);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(168, 95);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(7, 72);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonAddMap.TabIndex = 2;
|
||||
this.buttonAddMap.Text = "Добавить Карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(7, 18);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(168, 20);
|
||||
this.textBoxNewMapName.TabIndex = 1;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Сложная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 44);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 21);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(59, 402);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(80, 605);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
@ -79,7 +146,7 @@
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(135, 402);
|
||||
this.buttonRight.Location = new System.Drawing.Point(156, 605);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
@ -90,7 +157,7 @@
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(97, 402);
|
||||
this.buttonDown.Location = new System.Drawing.Point(118, 605);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonDown.TabIndex = 7;
|
||||
@ -101,7 +168,7 @@
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(97, 365);
|
||||
this.buttonUp.Location = new System.Drawing.Point(118, 568);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
@ -110,7 +177,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 256);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 511);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -120,7 +187,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(7, 216);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(7, 471);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -130,7 +197,7 @@
|
||||
//
|
||||
// buttonRemoveTrolleybus
|
||||
//
|
||||
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 170);
|
||||
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 425);
|
||||
this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus";
|
||||
this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(182, 23);
|
||||
this.buttonRemoveTrolleybus.TabIndex = 3;
|
||||
@ -140,14 +207,14 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 128);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 383);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(181, 20);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonAddTrolleybus
|
||||
//
|
||||
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 85);
|
||||
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 340);
|
||||
this.buttonAddTrolleybus.Name = "buttonAddTrolleybus";
|
||||
this.buttonAddTrolleybus.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonAddTrolleybus.TabIndex = 1;
|
||||
@ -155,24 +222,12 @@
|
||||
this.buttonAddTrolleybus.UseVisualStyleBackColor = true;
|
||||
this.buttonAddTrolleybus.Click += new System.EventHandler(this.ButtonAddTrolleybus_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Сложная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 42);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 21);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(600, 450);
|
||||
this.pictureBox.Size = new System.Drawing.Size(600, 648);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -180,13 +235,15 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(800, 648);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormMapWithSetTrolleybus";
|
||||
this.Text = "FormMapWithSetTrolleybus";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -206,5 +263,10 @@
|
||||
private System.Windows.Forms.Button buttonShowStorage;
|
||||
private System.Windows.Forms.Button buttonRemoveTrolleybus;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Button buttonDeleteMap;
|
||||
private System.Windows.Forms.ListBox listBoxMaps;
|
||||
private System.Windows.Forms.Button buttonAddMap;
|
||||
private System.Windows.Forms.TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -12,9 +12,77 @@ namespace Trolleybus
|
||||
{
|
||||
public partial class FormMapWithSetTrolleybus : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Сложная карта", new AutoStopMap() },
|
||||
};
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
public FormMapWithSetTrolleybus()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
|
||||
listBoxMaps.Items.Clear();
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
|
||||
foreach (string map in _mapsCollection.Keys)
|
||||
{
|
||||
listBoxMaps.Items.Add(map);
|
||||
}
|
||||
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
}
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
private MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> _mapTrolleybusCollectionGeneric;
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
@ -41,18 +109,18 @@ namespace Trolleybus
|
||||
}
|
||||
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Form1 form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectTrolleybus trolleybus = new(form.SelectedTrolleybus);
|
||||
if (_mapTrolleybusCollectionGeneric + trolleybus !=-1)
|
||||
DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -67,19 +135,16 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
|
||||
MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapTrolleybusCollectionGeneric - pos !=null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -93,11 +158,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -106,11 +171,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -119,7 +184,7 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -141,7 +206,7 @@ namespace Trolleybus
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace Trolleybus
|
||||
Shaking();
|
||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
||||
{
|
||||
var car = _setTrolleybus.Get(i);
|
||||
var car = _setTrolleybus[i];
|
||||
if (car != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
@ -120,11 +120,11 @@ namespace Trolleybus
|
||||
int j = _setTrolleybus.Count - 1;
|
||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
||||
{
|
||||
if (_setTrolleybus.Get(i) == null)
|
||||
if (_setTrolleybus[j] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setTrolleybus.Get(j);
|
||||
var car = _setTrolleybus[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setTrolleybus.Insert(car, i);
|
||||
@ -169,13 +169,13 @@ namespace Trolleybus
|
||||
{
|
||||
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
||||
{
|
||||
xForLocomotive = _pictureWidth - _placeSizeWidth + 40;
|
||||
xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
|
||||
yForLocomotive += _placeSizeHeight;
|
||||
countInRow = 0;
|
||||
}
|
||||
if (_setTrolleybus.Get(i) != null)
|
||||
if (_setTrolleybus[i] != null)
|
||||
{
|
||||
T locomotive = _setTrolleybus.Get(i);
|
||||
T locomotive = _setTrolleybus[i];
|
||||
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
|
||||
locomotive.DrawningObject(g);
|
||||
}
|
||||
|
57
Trolleybus/Trolleybus/MapsCollection.cs
Normal file
57
Trolleybus/Trolleybus/MapsCollection.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Trolleybus
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// Словарь (хранилище) с картами
|
||||
readonly Dictionary<string, MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus,
|
||||
AbstractMap>> _mapStorages;
|
||||
/// Возвращение списка названий карт
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// Ширина окна отрисовки
|
||||
private readonly int _pictureWidth;
|
||||
/// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
/// Конструктор
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string,
|
||||
MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// Добавление карты
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (Keys.Contains(name))
|
||||
|
||||
return;
|
||||
_mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
/// Удаление карты
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
/// Доступ к депо
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
_mapStorages.TryGetValue(ind, out var mapWithSetTractorsGeneric);
|
||||
return mapWithSetTractorsGeneric;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,13 +11,20 @@ namespace Trolleybus
|
||||
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 SetTrolleybusGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
private bool CorrectPos(int pos)
|
||||
{
|
||||
return 0 <= pos && pos < _maxCount;
|
||||
}
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T trolleybus)
|
||||
@ -29,53 +36,51 @@ namespace Trolleybus
|
||||
public int Insert(T trolleybus, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
if (!CorrectPos(position))
|
||||
{
|
||||
return -1;
|
||||
//проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = trolleybus;
|
||||
return position;
|
||||
}
|
||||
//проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int findEmptyPos = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
findEmptyPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findEmptyPos < 0) return -1;
|
||||
|
||||
//сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
for (int i = findEmptyPos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
// вставка по позиции
|
||||
_places[position] = trolleybus;
|
||||
_places.Insert(position, trolleybus);
|
||||
return position;
|
||||
}
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0) return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
return temp;
|
||||
}
|
||||
{
|
||||
// проверка позиции
|
||||
if (!CorrectPos(position))
|
||||
return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return temp;
|
||||
}
|
||||
// Получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return null;
|
||||
return _places[position];
|
||||
get
|
||||
{
|
||||
return CorrectPos(position) && position < Count ? _places[position] : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
public IEnumerable<T> GetTractors()
|
||||
{
|
||||
foreach (var tractor in _places)
|
||||
{
|
||||
if (tractor != null)
|
||||
{
|
||||
yield return tractor;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -73,8 +73,9 @@
|
||||
<Compile Include="FormMapWithSetTrolleybus.Designer.cs">
|
||||
<DependentUpon>FormMapWithSetTrolleybus.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HardMap.cs" />
|
||||
<Compile Include="AutoStopMap.cs" />
|
||||
<Compile Include="IDrawingObject.cs" />
|
||||
<Compile Include="MapsCollection.cs" />
|
||||
<Compile Include="MapWithSetTrolleybusGeneric.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user
У словаря есть метод проверки, есть ли запись с таким ключом