This commit is contained in:
Daniya_Youdakova 2022-12-25 17:48:39 +04:00
parent 0f259f5cfe
commit 0c62307525
5 changed files with 73 additions and 49 deletions

View File

@ -30,6 +30,8 @@
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.buttonSortByType = new System.Windows.Forms.Button();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
@ -60,6 +62,8 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonSortByColor);
this.groupBox1.Controls.Add(this.buttonSortByType);
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.button4);
@ -73,11 +77,31 @@
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(593, 28);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(250, 491);
this.groupBox1.Size = new System.Drawing.Size(250, 635);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(25, 324);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(184, 29);
this.buttonSortByColor.TabIndex = 14;
this.buttonSortByColor.Text = "Сортировать по цвету";
this.buttonSortByColor.UseVisualStyleBackColor = true;
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
//
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(25, 279);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(184, 29);
this.buttonSortByType.TabIndex = 13;
this.buttonSortByType.Text = "Сортировать по типу";
this.buttonSortByType.UseVisualStyleBackColor = true;
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
@ -141,12 +165,12 @@
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(184, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
this.comboBoxSelectorMap.Click += new System.EventHandler(this.ButtonMove_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(71, 483);
this.button1.Location = new System.Drawing.Point(68, 578);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(30, 30);
this.button1.TabIndex = 11;
@ -155,7 +179,7 @@
//
// button4
//
this.button4.Location = new System.Drawing.Point(107, 483);
this.button4.Location = new System.Drawing.Point(104, 578);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(30, 30);
this.button4.TabIndex = 10;
@ -164,7 +188,7 @@
//
// button3
//
this.button3.Location = new System.Drawing.Point(107, 447);
this.button3.Location = new System.Drawing.Point(104, 542);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(30, 30);
this.button3.TabIndex = 9;
@ -173,7 +197,7 @@
//
// button2
//
this.button2.Location = new System.Drawing.Point(143, 483);
this.button2.Location = new System.Drawing.Point(140, 578);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(30, 30);
this.button2.TabIndex = 8;
@ -182,7 +206,7 @@
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(25, 412);
this.buttonShowOnMap.Location = new System.Drawing.Point(25, 507);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(184, 29);
this.buttonShowOnMap.TabIndex = 6;
@ -192,7 +216,7 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(25, 377);
this.buttonShowStorage.Location = new System.Drawing.Point(25, 463);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(184, 29);
this.buttonShowStorage.TabIndex = 5;
@ -202,7 +226,7 @@
//
// buttonRemoveAircraftCarrier
//
this.buttonRemoveAircraftCarrier.Location = new System.Drawing.Point(25, 342);
this.buttonRemoveAircraftCarrier.Location = new System.Drawing.Point(25, 428);
this.buttonRemoveAircraftCarrier.Name = "buttonRemoveAircraftCarrier";
this.buttonRemoveAircraftCarrier.Size = new System.Drawing.Size(184, 29);
this.buttonRemoveAircraftCarrier.TabIndex = 4;
@ -212,7 +236,7 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(25, 309);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(25, 395);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 27);
@ -220,7 +244,7 @@
//
// buttonAddAircraftCarrier
//
this.buttonAddAircraftCarrier.Location = new System.Drawing.Point(25, 274);
this.buttonAddAircraftCarrier.Location = new System.Drawing.Point(25, 360);
this.buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
this.buttonAddAircraftCarrier.Size = new System.Drawing.Size(184, 29);
this.buttonAddAircraftCarrier.TabIndex = 2;
@ -233,7 +257,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(593, 491);
this.pictureBox.Size = new System.Drawing.Size(593, 635);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//this.pictureBox.Click += new System.EventHandler(this.pictureBox1_Click);
@ -284,7 +308,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(843, 519);
this.ClientSize = new System.Drawing.Size(843, 663);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.menuStrip);
@ -328,5 +352,7 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -5,6 +5,7 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -14,8 +15,6 @@ namespace AircraftCarrier
{
public partial class FormMapWithSetAircraftCarriers : Form
{
private MapWithSetAircraftCarriersGeneric<DrawningObjectAircraftCarrier, AbstractMap>
_mapAircraftCarriersCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
@ -106,29 +105,6 @@ pictureBox.Height);
_logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Сложная карта":
map = new ComplexMap();
break;
}
if (map != null)
{
_mapAircraftCarriersCollectionGeneric = new
MapWithSetAircraftCarriersGeneric<DrawningObjectAircraftCarrier, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAircraftCarriersCollectionGeneric = null;
}
}
private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e)
{
var formAircraftCarrierConfig = new FormAircraftCarrierConfig();
@ -198,7 +174,6 @@ pictureBox.Height);
{
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
}
}
private void buttonShowStorage_Click(object sender, EventArgs e)
{
@ -206,7 +181,7 @@ pictureBox.Height);
{
return;
}
pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
@ -214,8 +189,7 @@ pictureBox.Height);
{
return;
}
pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
@ -241,7 +215,7 @@ pictureBox.Height);
dir = Direction.Right;
break;
}
pictureBox.Image = _mapAircraftCarriersCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -251,18 +225,19 @@ pictureBox.Height);
{
_mapsCollection.SaveData(saveFileDialog.FileName);
_logger.LogInformation($"Успешное сохранение в файл {saveFileDialog.FileName}");
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Сохранение прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogWarning($"Данные не сохранились: {ex.Message}");
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
// TODO продумать логику
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
@ -279,5 +254,26 @@ pictureBox.Height);
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
string.Empty].Sort(new AircraftCarrierCompareByType());
pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
// TODO прописать логику
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AircraftCarrierCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -66,4 +66,7 @@
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>311, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
internal interface IDrawningObject
internal interface IDrawningObject : IEquatable<IDrawningObject>
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);

View File

@ -34,7 +34,7 @@ namespace AircraftCarrier
private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetAircraftCarriersGeneric<IDrawningObject, AbstractMap>>();
_mapStorages = new Dictionary<string,MapWithSetAircraftCarriersGeneric<IDrawningObject, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@ -108,7 +108,6 @@ namespace AircraftCarrier
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
}
/// <summary>
/// Загрузка нформации по автомобилям на парковках из файла