Dolgov D.A. Lab Work 4 #4
@ -11,21 +11,20 @@ namespace ProjectPlane
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool isBomber, bool isFighter, bool superTurbine) :
|
||||
/// <param name="bodyKit">Признак наличия доп отсека</param>
|
||||
/// <param name="wing">Признак наличия супертурбины</param>
|
||||
public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool extraCell, bool superTurbine) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, isFighter, superTurbine);
|
||||
Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, extraCell, superTurbine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
|
||||
|
||||
if (Plane is not EntityWarPlane warplane)
|
||||
{
|
||||
|
@ -39,9 +39,15 @@
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddPlane = new System.Windows.Forms.Button();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
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.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -56,58 +62,66 @@
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddPlane);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(680, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 590);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Tools";
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(135, 495);
|
||||
this.buttonRight.Location = new System.Drawing.Point(133, 529);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
this.buttonRight.Size = new System.Drawing.Size(50, 49);
|
||||
this.buttonRight.TabIndex = 14;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(81, 495);
|
||||
this.buttonDown.Location = new System.Drawing.Point(77, 529);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonDown.TabIndex = 8;
|
||||
this.buttonDown.Size = new System.Drawing.Size(50, 49);
|
||||
this.buttonDown.TabIndex = 13;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(27, 495);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(21, 529);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonLeft.TabIndex = 7;
|
||||
this.buttonLeft.Size = new System.Drawing.Size(50, 49);
|
||||
this.buttonLeft.TabIndex = 12;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(81, 445);
|
||||
this.buttonUp.Location = new System.Drawing.Point(77, 472);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
this.buttonUp.Size = new System.Drawing.Size(50, 49);
|
||||
this.buttonUp.TabIndex = 11;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 320);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
@ -116,7 +130,7 @@
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
this.buttonRemovePlane.Location = new System.Drawing.Point(17, 195);
|
||||
this.buttonRemovePlane.Location = new System.Drawing.Point(17, 349);
|
||||
this.buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
this.buttonRemovePlane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemovePlane.TabIndex = 3;
|
||||
@ -126,7 +140,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 390);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -136,7 +150,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 431);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -146,7 +160,7 @@
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
this.buttonAddPlane.Location = new System.Drawing.Point(17, 106);
|
||||
this.buttonAddPlane.Location = new System.Drawing.Point(17, 279);
|
||||
this.buttonAddPlane.Name = "buttonAddPlane";
|
||||
this.buttonAddPlane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddPlane.TabIndex = 1;
|
||||
@ -154,6 +168,57 @@
|
||||
this.buttonAddPlane.UseVisualStyleBackColor = true;
|
||||
this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click);
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.ButtonAddMap);
|
||||
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(192, 251);
|
||||
this.groupBoxMaps.TabIndex = 10;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Maps";
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23);
|
||||
this.textBoxNewMapName.TabIndex = 12;
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonDeleteMap.TabIndex = 5;
|
||||
this.buttonDeleteMap.Text = "Delete map";
|
||||
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(11, 121);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(175, 79);
|
||||
this.listBoxMaps.TabIndex = 4;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonAddMap
|
||||
//
|
||||
this.ButtonAddMap.Location = new System.Drawing.Point(11, 80);
|
||||
this.ButtonAddMap.Name = "ButtonAddMap";
|
||||
this.ButtonAddMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.ButtonAddMap.TabIndex = 11;
|
||||
this.ButtonAddMap.Text = "Add map";
|
||||
this.ButtonAddMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
@ -161,18 +226,17 @@
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Simple map",
|
||||
"Sky map"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 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(811, 554);
|
||||
this.pictureBox.Size = new System.Drawing.Size(680, 590);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -180,13 +244,15 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1015, 554);
|
||||
this.ClientSize = new System.Drawing.Size(884, 590);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetPlanes";
|
||||
this.Text = "Map with object sets";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -202,9 +268,14 @@
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemovePlane;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonUp;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button ButtonAddMap;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private TextBox textBoxNewMapName;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
@ -12,16 +12,56 @@ namespace ProjectPlane
|
||||
{
|
||||
public partial class FormMapWithSetPlanes : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Simple Map", new SimpleMap() },
|
||||
{ "Sky Map", new SkyMap() }
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <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>
|
||||
private MapWithSetPlanesGeneric<DrawingObject, AbstractMap> _mapPlanesCollectionGeneric;
|
||||
//private MapWithSetPlanesGeneric<DrawingObject, AbstractMap> _mapPlanesCollectionGeneric = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetPlanes()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -29,29 +69,7 @@ namespace ProjectPlane
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Simple map":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Sky map":
|
||||
map = new SkyMap();
|
||||
break;
|
||||
}
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawingObject, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapPlanesCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
@ -59,7 +77,7 @@ namespace ProjectPlane
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapPlanesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -67,10 +85,10 @@ namespace ProjectPlane
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObject Plane = new(form.SelectedPlane);
|
||||
if (_mapPlanesCollectionGeneric + Plane != -1)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + Plane != -1)
|
||||
{
|
||||
MessageBox.Show("Object added");
|
||||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -85,6 +103,10 @@ namespace ProjectPlane
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
@ -94,10 +116,10 @@ namespace ProjectPlane
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapPlanesCollectionGeneric - pos is not null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object removed");
|
||||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -111,11 +133,11 @@ namespace ProjectPlane
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapPlanesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -124,11 +146,11 @@ namespace ProjectPlane
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapPlanesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -137,7 +159,7 @@ namespace ProjectPlane
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapPlanesCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -159,7 +181,51 @@ namespace ProjectPlane
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Data is not all completed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("This map doesn't exist", "Error", 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($"Delete {listBoxMaps.SelectedItem}?", "Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -89,14 +89,9 @@ namespace ProjectPlane
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
{
|
||||
var plane = _setPlanes.Get(i);
|
||||
if (plane != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||
}
|
||||
}
|
||||
foreach (var plane in _setPlanes.GetPlanes())
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
@ -120,11 +115,11 @@ namespace ProjectPlane
|
||||
int j = _setPlanes.Count - 1;
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
{
|
||||
if (_setPlanes.Get(i) == null)
|
||||
if (_setPlanes[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var plane = _setPlanes.Get(j);
|
||||
var plane = _setPlanes[j];
|
||||
if (plane != null)
|
||||
{
|
||||
_setPlanes.Insert(plane, i);
|
||||
@ -169,10 +164,10 @@ namespace ProjectPlane
|
||||
int width = _pictureWidth / _placeSizeWidth - 1;
|
||||
int height = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
foreach (var plane in _setPlanes.GetPlanes())
|
||||
{
|
||||
_setPlanes.Get(i)?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||
_setPlanes.Get(i)?.DrawingObject(g);
|
||||
plane?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||
plane?.DrawingObject(g);
|
||||
|
||||
if (width <= 0)
|
||||
{
|
||||
|
68
ProjectPlane/ProjectPlane/MapsCollection.cs
Normal file
68
ProjectPlane/ProjectPlane/MapsCollection.cs
Normal file
@ -0,0 +1,68 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetPlanesGeneric<DrawingObject, 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, MapWithSetPlanesGeneric<DrawingObject, 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 MapWithSetPlanesGeneric<DrawingObject, 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 MapWithSetPlanesGeneric<DrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,20 +9,22 @@ namespace ProjectPlane
|
||||
internal class SetPlanesGeneric<T> 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 SetPlanesGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -41,35 +43,8 @@ namespace ProjectPlane
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
bool isNull = false;
|
||||
int nullElem = 0;
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
for (int i = position + 1; i < Count; i ++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
isNull = true;
|
||||
nullElem = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isNull)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = nullElem; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = plane;
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
_places.Insert(position, plane);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
@ -79,12 +54,9 @@ namespace ProjectPlane
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (position < 0 || position >= _maxCount) return null;
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -92,13 +64,40 @@ namespace ProjectPlane
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return null;
|
||||
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return;
|
||||
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetPlanes()
|
||||
{
|
||||
foreach (var plane in _places)
|
||||
{
|
||||
if (plane != null)
|
||||
{
|
||||
yield return plane;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user