Merge pull request 'FourthLabWork' (#4) from FourthLabWork into ThirdLabWork
Reviewed-on: http://student.git.athene.tech/DozorovaA.A/PIbd-22_DozorovaAA_ArmoredVehicle_Simple/pulls/4
This commit is contained in:
commit
aeb3e0cfb0
133
ArmoredVehicle/FormMapWithSetMachine.Designer.cs
generated
133
ArmoredVehicle/FormMapWithSetMachine.Designer.cs
generated
@ -30,6 +30,12 @@
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMapWithSetMachine));
|
||||
this.groupBoxInstruments = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxMap = 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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.ButtonDown = new System.Windows.Forms.Button();
|
||||
this.ButtonRight = new System.Windows.Forms.Button();
|
||||
@ -39,14 +45,15 @@
|
||||
this.buttonStore = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.comboBoxMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBoxImage = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxInstruments.SuspendLayout();
|
||||
this.groupBoxMap.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxImage)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxInstruments
|
||||
//
|
||||
this.groupBoxInstruments.Controls.Add(this.groupBoxMap);
|
||||
this.groupBoxInstruments.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxInstruments.Controls.Add(this.ButtonDown);
|
||||
this.groupBoxInstruments.Controls.Add(this.ButtonRight);
|
||||
@ -56,18 +63,84 @@
|
||||
this.groupBoxInstruments.Controls.Add(this.buttonStore);
|
||||
this.groupBoxInstruments.Controls.Add(this.buttonDelete);
|
||||
this.groupBoxInstruments.Controls.Add(this.buttonAdd);
|
||||
this.groupBoxInstruments.Controls.Add(this.comboBoxMap);
|
||||
this.groupBoxInstruments.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxInstruments.Location = new System.Drawing.Point(728, 0);
|
||||
this.groupBoxInstruments.Location = new System.Drawing.Point(964, 0);
|
||||
this.groupBoxInstruments.Name = "groupBoxInstruments";
|
||||
this.groupBoxInstruments.Size = new System.Drawing.Size(300, 644);
|
||||
this.groupBoxInstruments.Size = new System.Drawing.Size(300, 910);
|
||||
this.groupBoxInstruments.TabIndex = 0;
|
||||
this.groupBoxInstruments.TabStop = false;
|
||||
this.groupBoxInstruments.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxMap
|
||||
//
|
||||
this.groupBoxMap.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBoxMap.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMap.Controls.Add(this.buttonAddMap);
|
||||
this.groupBoxMap.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMap.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBoxMap.Location = new System.Drawing.Point(13, 30);
|
||||
this.groupBoxMap.Name = "groupBoxMap";
|
||||
this.groupBoxMap.Size = new System.Drawing.Size(267, 408);
|
||||
this.groupBoxMap.TabIndex = 19;
|
||||
this.groupBoxMap.TabStop = false;
|
||||
this.groupBoxMap.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(5, 330);
|
||||
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(250, 58);
|
||||
this.buttonDeleteMap.TabIndex = 6;
|
||||
this.buttonDeleteMap.Text = "Удалить карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 25;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(5, 189);
|
||||
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(248, 129);
|
||||
this.listBoxMaps.TabIndex = 5;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(5, 121);
|
||||
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(250, 58);
|
||||
this.buttonAddMap.TabIndex = 4;
|
||||
this.buttonAddMap.Text = "Добавить карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
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(5, 73);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(248, 33);
|
||||
this.comboBoxSelectorMap.TabIndex = 3;
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(5, 32);
|
||||
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(248, 31);
|
||||
this.textBoxNewMapName.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(18, 179);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 506);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(270, 31);
|
||||
@ -78,7 +151,7 @@
|
||||
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonDown.BackgroundImage")));
|
||||
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonDown.Location = new System.Drawing.Point(139, 555);
|
||||
this.ButtonDown.Location = new System.Drawing.Point(129, 823);
|
||||
this.ButtonDown.Name = "ButtonDown";
|
||||
this.ButtonDown.Size = new System.Drawing.Size(40, 36);
|
||||
this.ButtonDown.TabIndex = 17;
|
||||
@ -90,7 +163,7 @@
|
||||
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonRight.BackgroundImage")));
|
||||
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonRight.Location = new System.Drawing.Point(182, 508);
|
||||
this.ButtonRight.Location = new System.Drawing.Point(172, 776);
|
||||
this.ButtonRight.Name = "ButtonRight";
|
||||
this.ButtonRight.Size = new System.Drawing.Size(40, 36);
|
||||
this.ButtonRight.TabIndex = 16;
|
||||
@ -102,7 +175,7 @@
|
||||
this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonLeft.BackgroundImage")));
|
||||
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonLeft.Location = new System.Drawing.Point(99, 510);
|
||||
this.ButtonLeft.Location = new System.Drawing.Point(89, 778);
|
||||
this.ButtonLeft.Name = "ButtonLeft";
|
||||
this.ButtonLeft.Size = new System.Drawing.Size(40, 36);
|
||||
this.ButtonLeft.TabIndex = 15;
|
||||
@ -114,7 +187,7 @@
|
||||
this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonUp.BackgroundImage")));
|
||||
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonUp.Location = new System.Drawing.Point(139, 460);
|
||||
this.ButtonUp.Location = new System.Drawing.Point(129, 728);
|
||||
this.ButtonUp.Name = "ButtonUp";
|
||||
this.ButtonUp.Size = new System.Drawing.Size(40, 36);
|
||||
this.ButtonUp.TabIndex = 14;
|
||||
@ -123,63 +196,50 @@
|
||||
//
|
||||
// buttonMap
|
||||
//
|
||||
this.buttonMap.Location = new System.Drawing.Point(26, 373);
|
||||
this.buttonMap.Location = new System.Drawing.Point(18, 680);
|
||||
this.buttonMap.Name = "buttonMap";
|
||||
this.buttonMap.Size = new System.Drawing.Size(262, 34);
|
||||
this.buttonMap.TabIndex = 5;
|
||||
this.buttonMap.Text = "Посмотреть карту";
|
||||
this.buttonMap.UseVisualStyleBackColor = true;
|
||||
this.buttonMap.Click += new System.EventHandler(this.buttonMap_Click);
|
||||
this.buttonMap.Click += new System.EventHandler(this.ButtonMap_Click);
|
||||
//
|
||||
// buttonStore
|
||||
//
|
||||
this.buttonStore.Location = new System.Drawing.Point(24, 307);
|
||||
this.buttonStore.Location = new System.Drawing.Point(16, 614);
|
||||
this.buttonStore.Name = "buttonStore";
|
||||
this.buttonStore.Size = new System.Drawing.Size(264, 34);
|
||||
this.buttonStore.TabIndex = 4;
|
||||
this.buttonStore.Text = "Посмотреть хранилище";
|
||||
this.buttonStore.UseVisualStyleBackColor = true;
|
||||
this.buttonStore.Click += new System.EventHandler(this.buttonStore_Click);
|
||||
this.buttonStore.Click += new System.EventHandler(this.ButtonStore_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(20, 234);
|
||||
this.buttonDelete.Location = new System.Drawing.Point(12, 561);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(268, 34);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить машину";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(13, 117);
|
||||
this.buttonAdd.Location = new System.Drawing.Point(5, 444);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(275, 34);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить машину";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// comboBoxMap
|
||||
//
|
||||
this.comboBoxMap.FormattingEnabled = true;
|
||||
this.comboBoxMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Горизонтальная карта",
|
||||
"Вертикальная карта"});
|
||||
this.comboBoxMap.Location = new System.Drawing.Point(9, 41);
|
||||
this.comboBoxMap.Name = "comboBoxMap";
|
||||
this.comboBoxMap.Size = new System.Drawing.Size(279, 33);
|
||||
this.comboBoxMap.TabIndex = 0;
|
||||
this.comboBoxMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxMap_SelectedIndexChanged);
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// pictureBoxImage
|
||||
//
|
||||
this.pictureBoxImage.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxImage.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxImage.Name = "pictureBoxImage";
|
||||
this.pictureBoxImage.Size = new System.Drawing.Size(728, 644);
|
||||
this.pictureBoxImage.Size = new System.Drawing.Size(964, 910);
|
||||
this.pictureBoxImage.TabIndex = 1;
|
||||
this.pictureBoxImage.TabStop = false;
|
||||
//
|
||||
@ -187,13 +247,15 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1028, 644);
|
||||
this.ClientSize = new System.Drawing.Size(1264, 910);
|
||||
this.Controls.Add(this.pictureBoxImage);
|
||||
this.Controls.Add(this.groupBoxInstruments);
|
||||
this.Name = "FormMapWithSetMachine";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxInstruments.ResumeLayout(false);
|
||||
this.groupBoxInstruments.PerformLayout();
|
||||
this.groupBoxMap.ResumeLayout(false);
|
||||
this.groupBoxMap.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxImage)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -206,12 +268,17 @@
|
||||
private Button buttonStore;
|
||||
private Button buttonDelete;
|
||||
private Button buttonAdd;
|
||||
private ComboBox comboBoxMap;
|
||||
private PictureBox pictureBoxImage;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button ButtonDown;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonUp;
|
||||
private GroupBox groupBoxMap;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -11,17 +11,76 @@ using System.Windows.Forms;
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
public partial class FormMapWithSetMachine : Form
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetMachineGeneric<DrawningObject, AbstractMap> _mapCarsCollectionGeneric;
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Вертикальная карта", new VerticalMap() },
|
||||
{ "Горизонтальная карта", new HorizontalMap() }
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetMachine()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBoxImage.Width, pictureBoxImage.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Заполнение listBoxMaps
|
||||
/// </summary>
|
||||
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]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@ -29,39 +88,39 @@ namespace ArmoredVehicle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void comboBoxMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxMap.Text)
|
||||
pictureBoxImage.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)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Горизонтальная карта":
|
||||
map = new HorizontalMap();
|
||||
break;
|
||||
case "Вертикальная карта":
|
||||
map = new VerticalMap();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (map != null)
|
||||
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapCarsCollectionGeneric = new MapWithSetMachineGeneric<DrawningObject, AbstractMap>(
|
||||
pictureBoxImage.Width, pictureBoxImage.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapCarsCollectionGeneric = null;
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -74,10 +133,10 @@ namespace ArmoredVehicle
|
||||
return;
|
||||
}
|
||||
DrawningObject machine = new(form.SelectedMachine);
|
||||
if (_mapCarsCollectionGeneric + machine != -1)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + machine != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -86,15 +145,12 @@ namespace ArmoredVehicle
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///<summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
@ -105,10 +161,10 @@ namespace ArmoredVehicle
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapCarsCollectionGeneric - pos != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -121,13 +177,13 @@ namespace ArmoredVehicle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStore_Click(object sender, EventArgs e)
|
||||
private void ButtonStore_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -135,13 +191,13 @@ namespace ArmoredVehicle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonMap_Click(object sender, EventArgs e)
|
||||
private void ButtonMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowOnMap();
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -151,7 +207,7 @@ namespace ArmoredVehicle
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -173,7 +229,7 @@ namespace ArmoredVehicle
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBoxImage.Image = _mapCarsCollectionGeneric.MoveObject(dir);
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,6 @@
|
||||
_map = map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
@ -92,13 +88,9 @@
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setMachines.Count; i++)
|
||||
foreach (var machine in _setMachines.GetMachine())
|
||||
{
|
||||
var car = _setMachines.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, machine);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -123,11 +115,11 @@
|
||||
int j = _setMachines.Count - 1;
|
||||
for (int i = 0; i < _setMachines.Count; i++)
|
||||
{
|
||||
if (_setMachines.Get(i) == null)
|
||||
if (_setMachines[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setMachines.Get(j);
|
||||
var car = _setMachines[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setMachines.Insert(car, i);
|
||||
@ -174,18 +166,18 @@
|
||||
int currentWidth = 0;
|
||||
int currentHeight = 0;
|
||||
|
||||
for (int i = 0; i < _setMachines.Count; i++)
|
||||
foreach (var machine in _setMachines.GetMachine())
|
||||
{
|
||||
int dop = 0;
|
||||
if(currentWidth > 0 && currentHeight > 0)
|
||||
if (currentWidth > 0 && currentHeight > 0)
|
||||
{
|
||||
dop = 30;
|
||||
}
|
||||
_setMachines.Get(i)?.SetObject(currentWidth * _placeSizeWidth + dop,
|
||||
|
||||
machine.SetObject(currentWidth * _placeSizeWidth + dop,
|
||||
currentHeight * _placeSizeHeight + dop,
|
||||
_pictureWidth, _pictureHeight);
|
||||
_setMachines.Get(i)?.DrawningObject(g);
|
||||
|
||||
machine?.DrawningObject(g);
|
||||
if (currentWidth < width - 1)
|
||||
{
|
||||
currentWidth++;
|
||||
@ -197,7 +189,7 @@
|
||||
}
|
||||
if (currentHeight > height) return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
97
ArmoredVehicle/MapsCollection.cs
Normal file
97
ArmoredVehicle/MapsCollection.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetMachineGeneric<DrawningObject,
|
||||
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,
|
||||
MapWithSetMachineGeneric<DrawningObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (Keys.Contains(name))
|
||||
{
|
||||
MessageBox.Show("Такая карта уже есть");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var NewElem = new MapWithSetMachineGeneric<DrawningObject, AbstractMap>(
|
||||
_pictureWidth, _pictureHeight, map);
|
||||
_mapStorages.Add(name, NewElem);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (Keys.Contains(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Такой карты нет");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetMachineGeneric<DrawningObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Keys.Contains(ind))
|
||||
{
|
||||
return _mapStorages[ind];
|
||||
}
|
||||
MessageBox.Show("Такой карты нет");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -8,13 +8,14 @@
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
private readonly List<T> _places;
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
private int BusyPlaces = 0;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -22,7 +23,9 @@
|
||||
/// <param name="count"></param>
|
||||
public SetMachineGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -31,7 +34,8 @@
|
||||
/// <returns></returns>
|
||||
public int Insert(T machine)
|
||||
{
|
||||
return Insert(machine, 0);
|
||||
if (Count + 1 <= _maxCount) return Insert(machine, 0);
|
||||
else return -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -41,21 +45,13 @@
|
||||
/// <returns></returns>
|
||||
public int Insert(T machine, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return -1;
|
||||
|
||||
BusyPlaces++;
|
||||
while (_places[position] != null)
|
||||
if (position >= _maxCount && position < 0)
|
||||
{
|
||||
for (int i = _places.Length - 1; i > 0; --i)
|
||||
{
|
||||
if (_places[i] == null && _places[i - 1] != null)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = null;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
_places[position] = machine;
|
||||
|
||||
_places.Insert(position, machine);
|
||||
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
@ -65,21 +61,63 @@
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length) return null;
|
||||
T deletemashine = _places[position];
|
||||
_places[position] = null;
|
||||
return deletemashine;
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
if (_places.ElementAt(position) != null)
|
||||
{
|
||||
T result = _places.ElementAt(position);
|
||||
|
||||
_places.RemoveAt(position);
|
||||
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position < 0 || position >= _places.Length) return null;
|
||||
else if (_places[position] == null) return null;
|
||||
return _places[position];
|
||||
get
|
||||
{
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
return _places.ElementAt(position);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
Insert(this[position], position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetMachine()
|
||||
{
|
||||
foreach (var machine in _places)
|
||||
{
|
||||
if (machine != null)
|
||||
{
|
||||
yield return machine;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user