Laba4 PIbd-22 Kalyshev Y V #7
@ -29,6 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = 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.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
@ -38,14 +44,15 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBoxMap.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMap);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
@ -55,33 +62,91 @@
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddBoat);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(927, 0);
|
||||
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(690, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 739);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 587);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.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.textBoxNewMapName);
|
||||
this.groupBoxMap.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMap.Location = new System.Drawing.Point(17, 22);
|
||||
this.groupBoxMap.Name = "groupBoxMap";
|
||||
this.groupBoxMap.Size = new System.Drawing.Size(175, 236);
|
||||
this.groupBoxMap.TabIndex = 11;
|
||||
this.groupBoxMap.TabStop = false;
|
||||
this.groupBoxMap.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 196);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(163, 31);
|
||||
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.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(6, 111);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(163, 79);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(6, 78);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(163, 27);
|
||||
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(6, 20);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(163, 23);
|
||||
this.textBoxNewMapName.TabIndex = 1;
|
||||
//
|
||||
// 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(6, 49);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(163, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 221);
|
||||
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 335);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(19, 260);
|
||||
this.buttonRemoveBoat.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(17, 364);
|
||||
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
this.buttonRemoveBoat.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonRemoveBoat.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveBoat.TabIndex = 3;
|
||||
this.buttonRemoveBoat.Text = "Удалить лодку";
|
||||
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
|
||||
@ -89,10 +154,9 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 383);
|
||||
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 405);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть гавань";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
@ -103,10 +167,9 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(104, 672);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 537);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -116,10 +179,9 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(145, 672);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 537);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -129,10 +191,9 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 672);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 537);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -142,20 +203,18 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(104, 624);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 501);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 521);
|
||||
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 446);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
@ -163,51 +222,36 @@
|
||||
//
|
||||
// buttonAddBoat
|
||||
//
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(19, 141);
|
||||
this.buttonAddBoat.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(17, 294);
|
||||
this.buttonAddBoat.Name = "buttonAddBoat";
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(200, 47);
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddBoat.TabIndex = 1;
|
||||
this.buttonAddBoat.Text = "Добавить лодку";
|
||||
this.buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBoat.Click += new System.EventHandler(this.ButtonAddBoat_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(19, 43);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
|
||||
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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(927, 739);
|
||||
this.pictureBox.Size = new System.Drawing.Size(690, 587);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetBoats
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1160, 739);
|
||||
this.ClientSize = new System.Drawing.Size(894, 587);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMapWithSetBoats";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
this.groupBoxMap.ResumeLayout(false);
|
||||
this.groupBoxMap.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -227,5 +271,10 @@
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveBoat;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private GroupBox groupBoxMap;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -1,63 +1,119 @@
|
||||
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
using static System.Windows.Forms.DataFormats;
|
||||
|
||||
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
{
|
||||
public partial class FormMapWithSetBoats : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap> _mapBoatsCollectionGeneric;
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Собственная карта", new MySecondMap() }
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetBoats()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.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>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
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)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Собственная карта":
|
||||
map = new MySecondMap();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (map != null)
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapBoatsCollectionGeneric = null;
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormBoat form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectBoat boat = new(form.SelectedBoat);
|
||||
if (_mapBoatsCollectionGeneric + boat != -1)
|
||||
DrawningObjectBoat car = new(form.SelectedBoat);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -72,6 +128,10 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
@ -81,10 +141,10 @@
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapBoatsCollectionGeneric - pos != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,11 +158,11 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -111,11 +171,11 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -124,7 +184,7 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -146,7 +206,8 @@
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
|
||||
string.Empty].MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
@ -89,13 +89,9 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setBoats.Count; i++)
|
||||
foreach (var boat in _setBoats.GetBoats())
|
||||
{
|
||||
var boat = _setBoats.Get(i);
|
||||
if (boat != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, boat);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, boat);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -120,11 +116,11 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
int j = _setBoats.Count - 1;
|
||||
for (int i = 0; i < _setBoats.Count; i++)
|
||||
{
|
||||
if (_setBoats.Get(i) == null)
|
||||
if (_setBoats[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var boat = _setBoats.Get(j);
|
||||
var boat = _setBoats[j];
|
||||
if (boat != null)
|
||||
{
|
||||
_setBoats.Insert(boat, i);
|
||||
@ -164,10 +160,10 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
{
|
||||
int x = 5;
|
||||
int y = 5;
|
||||
for (int i = 0; i < _setBoats.Count; i++)
|
||||
foreach (var boat in _setBoats.GetBoats())
|
||||
{
|
||||
_setBoats.Get(i)?.SetObject(x, y, _pictureWidth, _pictureHeight);
|
||||
_setBoats.Get(i)?.DrawningObject(g);
|
||||
boat?.SetObject(x, y, _pictureWidth, _pictureHeight);
|
||||
boat?.DrawningObject(g);
|
||||
x += _placeSizeWidth;
|
||||
if (x + _placeSizeWidth > _pictureWidth)
|
||||
{
|
||||
|
87
PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs
Normal file
87
PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetBoatsGeneric<DrawningObjectBoat, 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, MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var key in Keys)
|
||||
|
||||
{
|
||||
if (key.Equals(name))
|
||||
{
|
||||
MessageBox.Show("Объект с таким именем существует!");
|
||||
eegov
commented
В классе с логикой не выводят сообщения В классе с логикой не выводят сообщения
|
||||
return;
|
||||
}
|
||||
}
|
||||
_mapStorages.Add(name, new MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.TryGetValue(ind, out var map))
|
||||
{
|
||||
return map;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,20 +11,23 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
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 SetBoatsGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -33,12 +36,15 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
/// <returns></returns>
|
||||
public int Insert(T boat)
|
||||
{
|
||||
for (int i = 0; i < _places.Length; i++)
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
_places.Add(boat);
|
||||
for (int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
_places[i] = boat;
|
||||
return i;
|
||||
if (_places[i] == boat)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -51,33 +57,12 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat, int position)
|
||||
{
|
||||
if (position < 0 || position > _places.Length)
|
||||
if (position < 0 || position > _places.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int pos = -1;
|
||||
for (int i = position+1; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
if (pos != -1)
|
||||
{
|
||||
for (int i = pos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_places[position] = boat;
|
||||
return false;
|
||||
_places.Insert(position, boat);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -86,12 +71,16 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > _places.Length)
|
||||
if (position < 0 || position > _places.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T removed = _places[position];
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return removed;
|
||||
}
|
||||
/// <summary>
|
||||
@ -99,13 +88,42 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position < 0 || position > _places.Length)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
if (position < 0 || position > _places.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > _places.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetBoats()
|
||||
{
|
||||
foreach (var boat in _places)
|
||||
{
|
||||
if (boat != null)
|
||||
{
|
||||
yield return boat;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
У словаря есть метод проверки, есть ли запись с таким ключом