Compare commits
No commits in common. "f76229aecc504e42a12e857be9cbbeef9277321b" and "e853de9b51432061170a994af4e9853042827883" have entirely different histories.
f76229aecc
...
e853de9b51
14
AntiAircraftGun/AntiAircraftGun/AntiAircraftGunDelegate.cs
Normal file
14
AntiAircraftGun/AntiAircraftGun/AntiAircraftGunDelegate.cs
Normal 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);
|
||||
}
|
@ -18,7 +18,6 @@ namespace AntiAircraftGun
|
||||
{
|
||||
return _antiAircraftGun?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_antiAircraftGun?.MoveTransport(direction);
|
||||
@ -32,8 +31,5 @@ namespace AntiAircraftGun
|
||||
{
|
||||
_antiAircraftGun?.DrawTransport(g);
|
||||
}
|
||||
|
||||
public string GetInfo() => _antiAircraftGun?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectAntiAircraftGun(data.CreateDrawingAntiAircraftGun());
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace AntiAircraftGun
|
||||
/// <summary>
|
||||
/// Цвет зенитнго орудия
|
||||
/// </summary>
|
||||
public Color BodyColor { get; set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения зенитного орудия
|
||||
/// </summary>
|
||||
|
@ -11,7 +11,7 @@ namespace AntiAircraftGun
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; set; }
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия башни с орудием
|
||||
/// </summary>
|
||||
|
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
@ -20,7 +19,7 @@ namespace AntiAircraftGun
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawingAntiAircraftGun> EventAddAntiAircraftGun;
|
||||
private event AntiAircraftGunDelegate EventAddAntiAircraftGun;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -35,12 +34,12 @@ namespace AntiAircraftGun
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (sender, e) => { Close(); };
|
||||
// TODO buttonCancel.Click with lambda
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать орудие
|
||||
/// </summary>
|
||||
private void DrawAntiAircraftGun()
|
||||
private void DrawCar()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
@ -52,11 +51,11 @@ namespace AntiAircraftGun
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev"></param>
|
||||
public void AddEvent(Action<DrawingAntiAircraftGun> ev)
|
||||
public void AddEvent(AntiAircraftGunDelegate ev)
|
||||
{
|
||||
if (EventAddAntiAircraftGun == null)
|
||||
{
|
||||
EventAddAntiAircraftGun = ev;
|
||||
EventAddAntiAircraftGun = new AntiAircraftGunDelegate(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -106,7 +105,7 @@ namespace AntiAircraftGun
|
||||
checkBoxGun.Checked, checkBoxRadar.Checked);
|
||||
break;
|
||||
}
|
||||
DrawAntiAircraftGun();
|
||||
DrawCar();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отправляем цвет с панели
|
||||
@ -133,19 +132,14 @@ namespace AntiAircraftGun
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>labelModifiedObject
|
||||
/// <summary>
|
||||
/// Принимаем основной цвет
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LableBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_antiAircraftGun == null || !e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_antiAircraftGun.AntiAircraftGun.BodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||
DrawAntiAircraftGun();
|
||||
// TODO Call method from object _antiAircraftGun and set color
|
||||
}
|
||||
/// <summary>
|
||||
/// Принимаем дополнительный цвет
|
||||
@ -154,15 +148,7 @@ namespace AntiAircraftGun
|
||||
/// <param name="e"></param>
|
||||
private void LableDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_antiAircraftGun == null || _antiAircraftGun.GetType() != typeof(DrawingUpdateAntiAircraftGun) || !e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_antiAircraftGun.AntiAircraftGun is EntityUpdateAntiAircraftGun upGun)
|
||||
{
|
||||
upGun.DopColor = (Color)e.Data.GetData(typeof(Color));
|
||||
}
|
||||
DrawAntiAircraftGun();
|
||||
// TODO Call method from object _car if _antiAircraftGun is DrawningSportCar and set dop color
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление орудия
|
||||
|
@ -45,16 +45,9 @@
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox
|
||||
@ -69,9 +62,9 @@
|
||||
this.groupBox.Controls.Add(this.buttonLeft);
|
||||
this.groupBox.Controls.Add(this.buttonUp);
|
||||
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.Size = new System.Drawing.Size(238, 579);
|
||||
this.groupBox.Size = new System.Drawing.Size(238, 589);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
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.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown;
|
||||
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.Size = new System.Drawing.Size(30, 29);
|
||||
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.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowRight;
|
||||
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.Size = new System.Drawing.Size(30, 29);
|
||||
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.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowLeft;
|
||||
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.Size = new System.Drawing.Size(30, 29);
|
||||
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.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowUp;
|
||||
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.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
@ -187,15 +180,14 @@
|
||||
// pictureBox
|
||||
//
|
||||
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.Size = new System.Drawing.Size(574, 579);
|
||||
this.pictureBox.Size = new System.Drawing.Size(574, 589);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// 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.buttonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||
@ -203,7 +195,7 @@
|
||||
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMaps.Location = new System.Drawing.Point(580, 26);
|
||||
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.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
@ -245,57 +237,14 @@
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(194, 27);
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
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.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetAntiAircraftGuns";
|
||||
this.Text = "FormMapWithSetAntiAircraftGuns";
|
||||
this.groupBox.ResumeLayout(false);
|
||||
@ -303,10 +252,7 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@ -329,11 +275,5 @@
|
||||
private Button buttonDeleteMap;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
@ -110,26 +110,9 @@ namespace AntiAircraftGun
|
||||
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formAntiAircraftGunConfig = new FormAntiAircraftGunConfig();
|
||||
formAntiAircraftGunConfig.AddEvent(AddAntiAircraftGun);
|
||||
// TODO Call method AddEvent from formAntiAircraftGunConfig
|
||||
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>
|
||||
@ -217,44 +200,5 @@ namespace AntiAircraftGun
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,16 +57,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</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>
|
@ -38,10 +38,5 @@ namespace AntiAircraftGun
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
/// <summary>
|
||||
/// Получение информации по объекту
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
||||
|
@ -113,31 +113,6 @@ namespace AntiAircraftGun
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <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>
|
||||
private void Shaking()
|
||||
|
@ -11,7 +11,7 @@ namespace AntiAircraftGun
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
readonly Dictionary<string, MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
@ -25,21 +25,13 @@ namespace AntiAircraftGun
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Разделитель для записи по элементу словаря в файл
|
||||
/// </summary>
|
||||
private readonly char separatorDict = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записи колекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char separatorData = ';';
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>>();
|
||||
_mapStorages = new Dictionary<string, MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -50,7 +42,7 @@ namespace AntiAircraftGun
|
||||
/// <param name="map">Карта</param>
|
||||
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>
|
||||
/// Удаление карты
|
||||
@ -65,7 +57,7 @@ namespace AntiAircraftGun
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
public MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -73,65 +65,5 @@ namespace AntiAircraftGun
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user