Compare commits

..

No commits in common. "f76229aecc504e42a12e857be9cbbeef9277321b" and "e853de9b51432061170a994af4e9853042827883" have entirely different histories.

12 changed files with 40 additions and 326 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
/// <summary>
/// Делегат для передачи объекта-орудия
/// </summary>
/// <param name="antiAircraftGun"></param>
public delegate void AntiAircraftGunDelegate(DrawingAntiAircraftGun antiAircraftGun);
}

View File

@ -18,7 +18,6 @@ namespace AntiAircraftGun
{ {
return _antiAircraftGun?.GetCurrentPosition() ?? default; return _antiAircraftGun?.GetCurrentPosition() ?? default;
} }
public void MoveObject(Direction direction) public void MoveObject(Direction direction)
{ {
_antiAircraftGun?.MoveTransport(direction); _antiAircraftGun?.MoveTransport(direction);
@ -32,8 +31,5 @@ namespace AntiAircraftGun
{ {
_antiAircraftGun?.DrawTransport(g); _antiAircraftGun?.DrawTransport(g);
} }
public string GetInfo() => _antiAircraftGun?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectAntiAircraftGun(data.CreateDrawingAntiAircraftGun());
} }
} }

View File

@ -19,7 +19,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Цвет зенитнго орудия /// Цвет зенитнго орудия
/// </summary> /// </summary>
public Color BodyColor { get; set; } public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Шаг перемещения зенитного орудия /// Шаг перемещения зенитного орудия
/// </summary> /// </summary>

View File

@ -11,7 +11,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет
/// </summary> /// </summary>
public Color DopColor { get; set; } public Color DopColor { get; private set; }
/// <summary> /// <summary>
/// Признак наличия башни с орудием /// Признак наличия башни с орудием
/// </summary> /// </summary>

View File

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
/// <summary>
/// Расширение для класса DrawingAntiAircraftGun
/// </summary>
internal static class ExtentionAntiAircraftGun
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawingAntiAircraftGun CreateDrawingAntiAircraftGun(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new DrawingAntiAircraftGun(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new DrawingUpdateAntiAircraftGun(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]));
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingAntiAircraftGun"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawingAntiAircraftGun drawingAntiAircraftGun)
{
var antiAircraftGun = drawingAntiAircraftGun.AntiAircraftGun;
var str = $"{antiAircraftGun.Speed}{_separatorForObject}{antiAircraftGun.Weight}{_separatorForObject}{antiAircraftGun.BodyColor.Name}";
if (antiAircraftGun is not EntityUpdateAntiAircraftGun updateAntiAircraftGun)
{
return str;
}
return $"{str}{_separatorForObject}{updateAntiAircraftGun.DopColor.Name}{_separatorForObject}{updateAntiAircraftGun.Gun}{_separatorForObject}{updateAntiAircraftGun.Radar}";
}
}
}

View File

@ -7,7 +7,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
namespace AntiAircraftGun namespace AntiAircraftGun
{ {
@ -20,7 +19,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Событие /// Событие
/// </summary> /// </summary>
private event Action<DrawingAntiAircraftGun> EventAddAntiAircraftGun; private event AntiAircraftGunDelegate EventAddAntiAircraftGun;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -35,12 +34,12 @@ namespace AntiAircraftGun
panelWhite.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (sender, e) => { Close(); }; // TODO buttonCancel.Click with lambda
} }
/// <summary> /// <summary>
/// Отрисовать орудие /// Отрисовать орудие
/// </summary> /// </summary>
private void DrawAntiAircraftGun() private void DrawCar()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
@ -52,11 +51,11 @@ namespace AntiAircraftGun
/// Добавление события /// Добавление события
/// </summary> /// </summary>
/// <param name="ev"></param> /// <param name="ev"></param>
public void AddEvent(Action<DrawingAntiAircraftGun> ev) public void AddEvent(AntiAircraftGunDelegate ev)
{ {
if (EventAddAntiAircraftGun == null) if (EventAddAntiAircraftGun == null)
{ {
EventAddAntiAircraftGun = ev; EventAddAntiAircraftGun = new AntiAircraftGunDelegate(ev);
} }
else else
{ {
@ -106,7 +105,7 @@ namespace AntiAircraftGun
checkBoxGun.Checked, checkBoxRadar.Checked); checkBoxGun.Checked, checkBoxRadar.Checked);
break; break;
} }
DrawAntiAircraftGun(); DrawCar();
} }
/// <summary> /// <summary>
/// Отправляем цвет с панели /// Отправляем цвет с панели
@ -133,19 +132,14 @@ namespace AntiAircraftGun
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
/// <summary>labelModifiedObject /// <summary>
/// Принимаем основной цвет /// Принимаем основной цвет
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void LableBaseColor_DragDrop(object sender, DragEventArgs e) private void LableBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
if (_antiAircraftGun == null || !e.Data.GetDataPresent(typeof(Color))) // TODO Call method from object _antiAircraftGun and set color
{
return;
}
_antiAircraftGun.AntiAircraftGun.BodyColor = (Color)e.Data.GetData(typeof(Color));
DrawAntiAircraftGun();
} }
/// <summary> /// <summary>
/// Принимаем дополнительный цвет /// Принимаем дополнительный цвет
@ -154,15 +148,7 @@ namespace AntiAircraftGun
/// <param name="e"></param> /// <param name="e"></param>
private void LableDopColor_DragDrop(object sender, DragEventArgs e) private void LableDopColor_DragDrop(object sender, DragEventArgs e)
{ {
if (_antiAircraftGun == null || _antiAircraftGun.GetType() != typeof(DrawingUpdateAntiAircraftGun) || !e.Data.GetDataPresent(typeof(Color))) // TODO Call method from object _car if _antiAircraftGun is DrawningSportCar and set dop color
{
return;
}
if (_antiAircraftGun.AntiAircraftGun is EntityUpdateAntiAircraftGun upGun)
{
upGun.DopColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAntiAircraftGun();
} }
/// <summary> /// <summary>
/// Добавление орудия /// Добавление орудия

View File

@ -45,16 +45,9 @@
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox.SuspendLayout(); this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBox // groupBox
@ -69,9 +62,9 @@
this.groupBox.Controls.Add(this.buttonLeft); this.groupBox.Controls.Add(this.buttonLeft);
this.groupBox.Controls.Add(this.buttonUp); this.groupBox.Controls.Add(this.buttonUp);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox.Location = new System.Drawing.Point(574, 28); this.groupBox.Location = new System.Drawing.Point(574, 0);
this.groupBox.Name = "groupBox"; this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(238, 579); this.groupBox.Size = new System.Drawing.Size(238, 589);
this.groupBox.TabIndex = 0; this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false; this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты"; this.groupBox.Text = "Инструменты";
@ -129,7 +122,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown; this.buttonDown.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(108, 537); this.buttonDown.Location = new System.Drawing.Point(108, 547);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 29); this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 10; this.buttonDown.TabIndex = 10;
@ -141,7 +134,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowRight; this.buttonRight.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(143, 537); this.buttonRight.Location = new System.Drawing.Point(143, 547);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 29); this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 9; this.buttonRight.TabIndex = 9;
@ -153,7 +146,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(71, 537); this.buttonLeft.Location = new System.Drawing.Point(71, 547);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 29); this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 8; this.buttonLeft.TabIndex = 8;
@ -165,7 +158,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowUp; this.buttonUp.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(108, 499); this.buttonUp.Location = new System.Drawing.Point(108, 509);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 29); this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
@ -187,15 +180,14 @@
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(574, 579); this.pictureBox.Size = new System.Drawing.Size(574, 589);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// groupBoxMaps // groupBoxMaps
// //
this.groupBoxMaps.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxMaps.Controls.Add(this.listBoxMaps); this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
@ -203,7 +195,7 @@
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(580, 26); this.groupBoxMaps.Location = new System.Drawing.Point(580, 26);
this.groupBoxMaps.Name = "groupBoxMaps"; this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(220, 277); this.groupBoxMaps.Size = new System.Drawing.Size(226, 277);
this.groupBoxMaps.TabIndex = 17; this.groupBoxMaps.TabIndex = 17;
this.groupBoxMaps.TabStop = false; this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты"; this.groupBoxMaps.Text = "Карты";
@ -245,57 +237,14 @@
this.textBoxNewMapName.Size = new System.Drawing.Size(194, 27); this.textBoxNewMapName.Size = new System.Drawing.Size(194, 27);
this.textBoxNewMapName.TabIndex = 0; this.textBoxNewMapName.TabIndex = 0;
// //
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.файлToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(812, 28);
this.menuStrip.TabIndex = 18;
//
// файлToolStripMenuItem
//
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.файлToolStripMenuItem.Name = айлToolStripMenuItem";
this.файлToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
this.файлToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// FormMapWithSetAntiAircraftGuns // FormMapWithSetAntiAircraftGuns
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(812, 607); this.ClientSize = new System.Drawing.Size(812, 589);
this.Controls.Add(this.groupBoxMaps); this.Controls.Add(this.groupBoxMaps);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox); this.Controls.Add(this.groupBox);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetAntiAircraftGuns"; this.Name = "FormMapWithSetAntiAircraftGuns";
this.Text = "FormMapWithSetAntiAircraftGuns"; this.Text = "FormMapWithSetAntiAircraftGuns";
this.groupBox.ResumeLayout(false); this.groupBox.ResumeLayout(false);
@ -303,10 +252,7 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.groupBoxMaps.ResumeLayout(false); this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout(); this.groupBoxMaps.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -329,11 +275,5 @@
private Button buttonDeleteMap; private Button buttonDeleteMap;
private Button buttonAddMap; private Button buttonAddMap;
private TextBox textBoxNewMapName; private TextBox textBoxNewMapName;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
} }
} }

View File

@ -110,26 +110,9 @@ namespace AntiAircraftGun
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
{ {
var formAntiAircraftGunConfig = new FormAntiAircraftGunConfig(); var formAntiAircraftGunConfig = new FormAntiAircraftGunConfig();
formAntiAircraftGunConfig.AddEvent(AddAntiAircraftGun); // TODO Call method AddEvent from formAntiAircraftGunConfig
formAntiAircraftGunConfig.Show(); formAntiAircraftGunConfig.Show();
} }
private void AddAntiAircraftGun(DrawingAntiAircraftGun drawingAntiAircraftGuns)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Cant add object");
}
}
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта
/// </summary> /// </summary>
@ -217,44 +200,5 @@ namespace AntiAircraftGun
} }
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
} }
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
else
{
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
} }

View File

@ -57,16 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>144, 17</value>
</metadata>
<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> </root>

View File

@ -38,10 +38,5 @@ namespace AntiAircraftGun
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition(); (float Left, float Right, float Top, float Bottom) GetCurrentPosition();
/// <summary>
/// Получение информации по объекту
/// </summary>
/// <returns></returns>
string GetInfo();
} }
} }

View File

@ -113,31 +113,6 @@ namespace AntiAircraftGun
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
} }
/// <summary> /// <summary>
/// Получение данных в виде строки
/// </summary>
/// <param name="sep"></param>
/// <returns></returns>
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var antiAircraftGun in _setAntiAircraftGuns.GetAntiAircraftGuns())
{
data += $"{antiAircraftGun.GetInfo()}{separatorData}";
}
return data;
}
/// <summary>
/// Загрузка списка из массива строк
/// </summary>
/// <param name="records"></param>
public void LoadData(string[] records)
{
foreach (var rec in records)
{
_setAntiAircraftGuns.Insert(DrawingObjectAntiAircraftGun.Create(rec) as T);
}
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале /// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary> /// </summary>
private void Shaking() private void Shaking()

View File

@ -11,7 +11,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Словарь (хранилище) с картами /// Словарь (хранилище) с картами
/// </summary> /// </summary>
readonly Dictionary<string, MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>> _mapStorages; readonly Dictionary<string, MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>> _mapStorages;
/// <summary> /// <summary>
/// Возвращение списка названий карт /// Возвращение списка названий карт
/// </summary> /// </summary>
@ -25,21 +25,13 @@ namespace AntiAircraftGun
/// </summary> /// </summary>
private readonly int _pictureHeight; private readonly int _pictureHeight;
/// <summary> /// <summary>
/// Разделитель для записи по элементу словаря в файл
/// </summary>
private readonly char separatorDict = '|';
/// <summary>
/// Разделитель для записи колекции данных в файл
/// </summary>
private readonly char separatorData = ';';
/// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="pictureWidth"></param> /// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param> /// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight) public MapsCollection(int pictureWidth, int pictureHeight)
{ {
_mapStorages = new Dictionary<string, MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>>(); _mapStorages = new Dictionary<string, MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
@ -50,7 +42,7 @@ namespace AntiAircraftGun
/// <param name="map">Карта</param> /// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map) public void AddMap(string name, AbstractMap map)
{ {
if(!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map)); if(!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>(_pictureWidth, _pictureHeight, map));
} }
/// <summary> /// <summary>
/// Удаление карты /// Удаление карты
@ -65,7 +57,7 @@ namespace AntiAircraftGun
/// </summary> /// </summary>
/// <param name="ind"></param> /// <param name="ind"></param>
/// <returns></returns> /// <returns></returns>
public MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap> this[string ind] public MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap> this[string ind]
{ {
get get
{ {
@ -73,65 +65,5 @@ namespace AntiAircraftGun
return null; return null;
} }
} }
/// <summary>
/// Сохранение информации по орудиям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns></returns>
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter sw = new StreamWriter(filename))
{
sw.WriteLine($"MapsCollection");
foreach (var storage in _mapStorages)
{
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
}
}
return true;
}
/// <summary>
/// Загрузка нформации по орудиям на парковках из файла
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new StreamReader(filename))
{
string str;
_mapStorages.Clear();
str = sr.ReadLine();
if (!str.Contains("MapsCollection"))
{
return false;
}
while ((str = sr.ReadLine()) != null)
{
var elem = str.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "SimpleMap2":
map = new SimpleMap2();
break;
}
_mapStorages.Add(elem[0], new MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
return true;
}
}
} }
} }