Merge pull request 'Malin D.V. Lab work 4' (#4) from LabWork_04 into LabWork_03
Reviewed-on: http://student.git.athene.tech/Danil_Malin/PIbd-21_Malin_D.V._WarmlyLocomotive_Base/pulls/4
This commit is contained in:
commit
c69647a842
@ -29,6 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxMaps = 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.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
@ -38,14 +44,15 @@
|
||||
this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddLocomotive = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBox.Controls.Add(this.buttonDown);
|
||||
this.groupBox.Controls.Add(this.buttonRight);
|
||||
this.groupBox.Controls.Add(this.buttonLeft);
|
||||
@ -55,21 +62,85 @@
|
||||
this.groupBox.Controls.Add(this.buttonRemoveLocomotive);
|
||||
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox.Controls.Add(this.buttonAddLocomotive);
|
||||
this.groupBox.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox.Location = new System.Drawing.Point(600, 0);
|
||||
this.groupBox.Location = new System.Drawing.Point(668, 0);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(200, 450);
|
||||
this.groupBox.Size = new System.Drawing.Size(200, 629);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(188, 261);
|
||||
this.groupBoxMaps.TabIndex = 10;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(13, 220);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(169, 34);
|
||||
this.buttonDeleteMap.TabIndex = 3;
|
||||
this.buttonDeleteMap.Text = "Удалить карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(13, 120);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(169, 94);
|
||||
this.listBoxMaps.TabIndex = 2;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(13, 80);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(169, 34);
|
||||
this.buttonAddMap.TabIndex = 1;
|
||||
this.buttonAddMap.Text = "Добавить карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(13, 22);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(169, 23);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Карта с большими барьерами",
|
||||
"Карта с круглыми барьерами"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 46);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(87, 403);
|
||||
this.buttonDown.Location = new System.Drawing.Point(87, 582);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
@ -81,7 +152,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(123, 403);
|
||||
this.buttonRight.Location = new System.Drawing.Point(123, 582);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
@ -93,7 +164,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(51, 403);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(51, 582);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 7;
|
||||
@ -105,7 +176,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(87, 367);
|
||||
this.buttonUp.Location = new System.Drawing.Point(87, 546);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
@ -115,7 +186,7 @@
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 312);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 491);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -126,7 +197,7 @@
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 233);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 443);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -137,7 +208,7 @@
|
||||
// buttonRemoveLocomotive
|
||||
//
|
||||
this.buttonRemoveLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(19, 171);
|
||||
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(19, 397);
|
||||
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonRemoveLocomotive.TabIndex = 3;
|
||||
@ -148,7 +219,7 @@
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 142);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 368);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
|
||||
@ -157,7 +228,7 @@
|
||||
// buttonAddLocomotive
|
||||
//
|
||||
this.buttonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddLocomotive.Location = new System.Drawing.Point(19, 90);
|
||||
this.buttonAddLocomotive.Location = new System.Drawing.Point(19, 332);
|
||||
this.buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||
this.buttonAddLocomotive.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonAddLocomotive.TabIndex = 1;
|
||||
@ -165,27 +236,12 @@
|
||||
this.buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Карта с большими барьерами",
|
||||
"Карта с круглыми барьерами"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 33);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 23);
|
||||
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(668, 629);
|
||||
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
@ -194,13 +250,15 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(868, 629);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Name = "FormMapWithSetLocomotives";
|
||||
this.Text = "FormMapWithSetLocomotives";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBox.ResumeLayout(false);
|
||||
this.groupBox.PerformLayout();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@ -221,5 +279,10 @@
|
||||
private Button buttonAddLocomotive;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private PictureBox pictureBox;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -14,41 +14,49 @@ namespace WarmlyLocomotive
|
||||
public partial class FormMapWithSetLocomotives : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{"Простая карта", new SimpleMap()},
|
||||
{"Карта с большими барьерами", new BigBarriersMap()},
|
||||
{"Карта с круглыми барьерами", new CirclesMap()}
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
private MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
||||
public FormMapWithSetLocomotives()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// Заполнение listBoxMaps
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
private void ReloadMaps()
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
listBoxMaps.Items.Clear();
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Карта с большими барьерами":
|
||||
map = new BigBarriersMap();
|
||||
break;
|
||||
case "Карта с круглыми барьерами":
|
||||
map = new CirclesMap();
|
||||
break;
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
if (map != null)
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
_mapLocomotivesCollectionGeneric = null;
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -58,7 +66,7 @@ namespace WarmlyLocomotive
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -66,10 +74,10 @@ namespace WarmlyLocomotive
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
|
||||
if (_mapLocomotivesCollectionGeneric + locomotive != -1)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -84,6 +92,10 @@ namespace WarmlyLocomotive
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
@ -93,10 +105,10 @@ namespace WarmlyLocomotive
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapLocomotivesCollectionGeneric - pos != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -110,11 +122,11 @@ namespace WarmlyLocomotive
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -123,11 +135,11 @@ namespace WarmlyLocomotive
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -136,7 +148,7 @@ namespace WarmlyLocomotive
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -158,7 +170,54 @@ namespace WarmlyLocomotive
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace WarmlyLocomotive
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int width = picWidth / (_placeSizeWidth + 30);
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setLocomotives = new SetLocomotivesGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
@ -88,13 +88,9 @@ namespace WarmlyLocomotive
|
||||
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);
|
||||
}
|
||||
@ -119,11 +115,11 @@ namespace WarmlyLocomotive
|
||||
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);
|
||||
@ -179,7 +175,7 @@ namespace WarmlyLocomotive
|
||||
int xForLocomotive = 2;
|
||||
int yForLocomotive = 10;
|
||||
int countInRow = 0;
|
||||
for (int i = 0; i < _setLocomotives.Count; i++)
|
||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||
{
|
||||
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
||||
{
|
||||
@ -187,9 +183,8 @@ namespace WarmlyLocomotive
|
||||
yForLocomotive += _placeSizeHeight;
|
||||
countInRow = 0;
|
||||
}
|
||||
if (_setLocomotives.Get(i) != null)
|
||||
if (locomotive != null)
|
||||
{
|
||||
T locomotive = _setLocomotives.Get(i);
|
||||
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
|
||||
locomotive.DrawningObject(g);
|
||||
}
|
||||
|
85
WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs
Normal file
85
WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (!_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ind != String.Empty)
|
||||
{
|
||||
MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> value;
|
||||
if (_mapStorages.TryGetValue(ind, out value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,20 +10,22 @@ namespace WarmlyLocomotive
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetLocomotivesGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -32,30 +34,7 @@ namespace WarmlyLocomotive
|
||||
/// <returns></returns>
|
||||
public int Insert(T locomotive)
|
||||
{
|
||||
bool hasEmptySpace = false;
|
||||
int indexOfEmptyPlace = 0;
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
if (_places[i] == null || _places[i] == default(T))
|
||||
{
|
||||
hasEmptySpace = true;
|
||||
indexOfEmptyPlace = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasEmptySpace)
|
||||
{
|
||||
for (int i = indexOfEmptyPlace; i > 0; --i)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = locomotive;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return Insert(locomotive, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -65,42 +44,12 @@ namespace WarmlyLocomotive
|
||||
/// <returns></returns>
|
||||
public int Insert(T locomotive, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
if (position < 0 || position > Count || _maxCount == Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] == null || _places[position] == default(T))
|
||||
{
|
||||
_places[position] = locomotive;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasEmptySpace = false;
|
||||
int indexOfEmptyPlace = 0;
|
||||
for (int i = position + 1; i < Count; ++i)
|
||||
{
|
||||
if (_places[i] == null || _places[i] == default(T))
|
||||
{
|
||||
hasEmptySpace = true;
|
||||
indexOfEmptyPlace = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasEmptySpace)
|
||||
{
|
||||
for (int i = indexOfEmptyPlace; i > position; --i)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = locomotive;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
_places.Insert(position, locomotive);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -114,21 +63,49 @@ namespace WarmlyLocomotive
|
||||
return null;
|
||||
}
|
||||
T memoryObj = _places[position];
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return memoryObj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
get
|
||||
{
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
set
|
||||
{
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetLocomotives()
|
||||
{
|
||||
foreach (var locomotive in _places)
|
||||
{
|
||||
if (locomotive != null)
|
||||
{
|
||||
yield return locomotive;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user