Presnyakova V.V Lab_4 #9
@ -66,6 +66,7 @@
|
||||
<DependentUpon>FormMapWithSetBoats.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IDrawingObject.cs" />
|
||||
<Compile Include="MapsCollection.cs" />
|
||||
<Compile Include="MapWithSetBoatsGeneric.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
94
Catamaran/FormMapWithSetBoats.Designer.cs
generated
94
Catamaran/FormMapWithSetBoats.Designer.cs
generated
@ -40,18 +40,24 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddBoat);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
@ -59,14 +65,14 @@
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(653, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(303, 557);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(303, 647);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Tools";
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(24, 402);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(24, 490);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(191, 31);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -76,7 +82,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(24, 344);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(24, 451);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(191, 33);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -86,7 +92,7 @@
|
||||
//
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(24, 271);
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(24, 415);
|
||||
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
this.buttonRemoveBoat.Size = new System.Drawing.Size(191, 30);
|
||||
this.buttonRemoveBoat.TabIndex = 3;
|
||||
@ -96,7 +102,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 201);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 383);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(191, 26);
|
||||
@ -104,7 +110,7 @@
|
||||
//
|
||||
// buttonAddBoat
|
||||
//
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(24, 123);
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(24, 345);
|
||||
this.buttonAddBoat.Name = "buttonAddBoat";
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(191, 32);
|
||||
this.buttonAddBoat.TabIndex = 1;
|
||||
@ -118,18 +124,18 @@
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"SimpleMap",
|
||||
"SecondMap"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(24, 51);
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 77);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(10, 472);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(10, 562);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
@ -141,7 +147,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(70, 472);
|
||||
this.buttonRight.Location = new System.Drawing.Point(70, 562);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
@ -153,7 +159,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(40, 450);
|
||||
this.buttonUp.Location = new System.Drawing.Point(40, 540);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
@ -165,7 +171,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(40, 480);
|
||||
this.buttonDown.Location = new System.Drawing.Point(40, 570);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
@ -177,15 +183,66 @@
|
||||
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(653, 557);
|
||||
this.pictureBox.Size = new System.Drawing.Size(653, 647);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
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(10, 25);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(213, 314);
|
||||
this.groupBoxMaps.TabIndex = 2;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Maps";
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(14, 45);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(191, 26);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(14, 112);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(191, 27);
|
||||
this.buttonAddMap.TabIndex = 1;
|
||||
this.buttonAddMap.Text = "AddMap";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(14, 233);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(191, 25);
|
||||
this.buttonDeleteMap.TabIndex = 2;
|
||||
this.buttonDeleteMap.Text = "DeleteMap";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 20;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(14, 146);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(191, 84);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// FormMapWithSetBoats
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(956, 557);
|
||||
this.ClientSize = new System.Drawing.Size(956, 647);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetBoats";
|
||||
@ -193,6 +250,8 @@
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@ -211,5 +270,10 @@
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.GroupBox groupBoxMaps;
|
||||
private System.Windows.Forms.ListBox listBoxMaps;
|
||||
private System.Windows.Forms.Button buttonDeleteMap;
|
||||
private System.Windows.Forms.Button buttonAddMap;
|
||||
private System.Windows.Forms.TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -12,13 +12,77 @@ namespace Catamaran
|
||||
{
|
||||
public partial class FormMapWithSetBoats : Form
|
||||
{
|
||||
private MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap> _mapBoatsCollectionGeneric;
|
||||
|
||||
/// <summary>
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new Dictionary<string, AbstractMap>()
|
||||
{
|
||||
{ "SimpleMap", new SimpleMap() },
|
||||
{"SecondMap", new SecondMap() }
|
||||
};
|
||||
/// <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>
|
||||
@ -26,33 +90,29 @@ namespace Catamaran
|
||||
/// </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)
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SecondMap":
|
||||
map = new SecondMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapBoatsCollectionGeneric = null;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
@ -61,6 +121,10 @@ namespace Catamaran
|
||||
/// <param name="e"></param>
|
||||
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
@ -71,10 +135,10 @@ namespace Catamaran
|
||||
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
|
||||
{
|
||||
@ -88,11 +152,12 @@ namespace Catamaran
|
||||
/// <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>
|
||||
/// Вывод карты
|
||||
@ -101,13 +166,13 @@ namespace Catamaran
|
||||
/// <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>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
@ -115,7 +180,7 @@ namespace Catamaran
|
||||
/// <param name="e"></param>
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -137,12 +202,17 @@ namespace Catamaran
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddBoat_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -150,15 +220,17 @@ namespace Catamaran
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectBoat boat = new DrawingObjectBoat(form.SelectedBoat);
|
||||
if (_mapBoatsCollectionGeneric + boat != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image =
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +61,6 @@ namespace Catamaran
|
||||
/// <param name="map"></param>
|
||||
/// <param name="Boat"></param>
|
||||
/// <returns></returns>
|
||||
///
|
||||
|
||||
public static int operator +(MapWithSetBoatsGeneric<T, U> map, T Boat)
|
||||
{
|
||||
return map._setBoats.Insert(Boat);
|
||||
@ -96,13 +94,9 @@ namespace Catamaran
|
||||
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 Bitmap(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -127,11 +121,11 @@ namespace Catamaran
|
||||
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);
|
||||
@ -184,10 +178,9 @@ namespace Catamaran
|
||||
for (int i = 0; i < _setBoats.Count; i++)
|
||||
{
|
||||
// TODO установка позиции
|
||||
_setBoats.Get(i)?.SetObject(i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setBoats.Get(i)?.DrawingObject(g);
|
||||
_setBoats[i]?.SetObject(i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setBoats[i]?.DrawingObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
74
Catamaran/MapsCollection.cs
Normal file
74
Catamaran/MapsCollection.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetBoatsGeneric<DrawingObjectBoat, 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<DrawingObjectBoat, 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 MapWithSetBoatsGeneric<DrawingObjectBoat, 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<DrawingObjectBoat, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
_mapStorages.TryGetValue(ind, out var map);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -16,18 +16,21 @@ namespace Catamaran
|
||||
/// <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>
|
||||
/// Добавление объекта в набор
|
||||
@ -36,11 +39,12 @@ namespace Catamaran
|
||||
/// <returns></returns>
|
||||
public int Insert(T boat)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
|
||||
for (int i = 0; i < _maxCount; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
if (i == Count)
|
||||
{
|
||||
_places[i] = boat;
|
||||
_places.Insert(i, boat);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -55,26 +59,26 @@ namespace Catamaran
|
||||
public int Insert(T boat, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count) return -1;
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
// TODO проверка, что элемент массива по этой позиции пустой,если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
if (_places[position] == null)
|
||||
if (position == Count)
|
||||
{
|
||||
_places[position] = boat;
|
||||
_places.Insert(position, boat);
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
for (int i = position + 1; i < _maxCount; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
if (i == Count)
|
||||
{
|
||||
for (int j = i - 1; j >= position; j--)
|
||||
{
|
||||
_places[j + 1] = _places[j];
|
||||
}
|
||||
_places[position] = boat;
|
||||
_places.Insert(position, boat);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
@ -92,22 +96,55 @@ namespace Catamaran
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count) return null;
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
T removed = _places[position];
|
||||
_places[position] = null;
|
||||
return removed;
|
||||
var result = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _places[position];
|
||||
get
|
||||
{
|
||||
if (position >= 0 && position < _maxCount && position < Count)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position > 0 || position < Count)
|
||||
{
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetBoats()
|
||||
{
|
||||
foreach (var boat in _places)
|
||||
{
|
||||
if (boat != null)
|
||||
{
|
||||
yield return boat;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user