Compare commits
11 Commits
000c848d81
...
LabWork06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0105985c98 | ||
|
|
86430cf93c | ||
|
|
005be6f825 | ||
|
|
474573214e | ||
|
|
5de55d7ef9 | ||
|
|
25b16cfdf9 | ||
|
|
4276aa834e | ||
|
|
5cc6f9c611 | ||
|
|
79e9924e04 | ||
|
|
45cb2513f3 | ||
|
|
ec5c587297 |
@@ -177,5 +177,19 @@ namespace ProjectMachine
|
|||||||
{
|
{
|
||||||
return (_startPosX, _startPosX + _machineWidth, _startPosY, _startPosY + _machineHeight);
|
return (_startPosX, _startPosX + _machineWidth, _startPosY, _startPosY + _machineHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void SetBaseColor(Color color)
|
||||||
|
{
|
||||||
|
if (Machine is EntityTank)
|
||||||
|
{
|
||||||
|
Machine = (EntityTank)Machine;
|
||||||
|
if (Machine is not null)
|
||||||
|
{
|
||||||
|
Machine = new EntityTank(Machine.Speed, Machine.Weight, color, (Machine as EntityTank).DopColor, (Machine as EntityTank).Turret, (Machine as EntityTank).Gun);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Machine = new EntityMachine(Machine.Speed, Machine.Weight, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,5 +36,9 @@ namespace ProjectMachine
|
|||||||
{
|
{
|
||||||
_machine.DrawTransport(g);
|
_machine.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetInfo() => _machine?.GetDataForSave();
|
||||||
|
|
||||||
|
public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningMachine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ namespace ProjectMachine
|
|||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
/// <param name="turret">Признак наличия башни с орудием</param>
|
/// <param name="turret">Признак наличия башни с орудием</param>
|
||||||
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
||||||
public DrawningTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
|
public DrawningTank(int speed, float weight, Color bodyColor, Color dopColor, bool turret, bool gun) :
|
||||||
base(speed, weight, bodyColor, 90, 50)
|
base(speed, weight, bodyColor, 90, 50)
|
||||||
{
|
{
|
||||||
Machine = new EntityTank(speed, weight, bodyColor, dopColor, bodyKit, turret, gun);
|
Machine = new EntityTank(speed, weight, bodyColor, dopColor, turret, gun);
|
||||||
}
|
}
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
@@ -50,5 +50,14 @@ namespace ProjectMachine
|
|||||||
_startPosX -= 10;
|
_startPosX -= 10;
|
||||||
_startPosY -= 5;
|
_startPosY -= 5;
|
||||||
}
|
}
|
||||||
|
public void SetDopColor(Color color)
|
||||||
|
{
|
||||||
|
Machine = Machine as EntityTank;
|
||||||
|
if (Machine is not null)
|
||||||
|
{
|
||||||
|
Machine = new EntityTank(Machine.Speed, Machine.Weight, Machine.BodyColor,
|
||||||
|
color, (Machine as EntityTank).Turret, (Machine as EntityTank).Gun);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,12 @@ namespace ProjectMachine
|
|||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
/// /// <param name="bodyKit">Признак наличия обвеса</param>
|
|
||||||
/// <param name="turret">Признак наличия башни с орудием</param>
|
/// <param name="turret">Признак наличия башни с орудием</param>
|
||||||
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
||||||
public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
|
public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, bool turret, bool gun) :
|
||||||
base(speed, weight, bodyColor)
|
base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
DopColor = dopColor;
|
DopColor = dopColor;
|
||||||
BodyKit = bodyKit;
|
|
||||||
Turret = turret;
|
Turret = turret;
|
||||||
Gun = gun;
|
Gun = gun;
|
||||||
}
|
}
|
||||||
|
|||||||
57
ProjectMachine/ProjectMachine/ExtentionTank.cs
Normal file
57
ProjectMachine/ProjectMachine/ExtentionTank.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectMachine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса DrawningMachine
|
||||||
|
/// </summary>
|
||||||
|
internal static class ExtentionTank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawningMachine CreateDrawningMachine(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawningMachine(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawningTank(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="drawningMachine"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetDataForSave(this DrawningMachine drawningMachine)
|
||||||
|
{
|
||||||
|
var machine = drawningMachine.Machine;
|
||||||
|
var str = $"{machine.Speed}{_separatorForObject}{machine.Weight}{_separatorForObject}{machine.BodyColor.Name}";
|
||||||
|
if (machine is not EntityTank tank)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
$"{str}{_separatorForObject}{tank.DopColor.Name}{_separatorForObject}{tank.Turret}{_separatorForObject}{tank.Gun}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,7 +107,7 @@ namespace ProjectMachine
|
|||||||
dopColor = dialogDop.Color;
|
dopColor = dialogDop.Color;
|
||||||
}
|
}
|
||||||
_machine = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
_machine = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace ProjectMachine
|
|||||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
var machine = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
var machine = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
SetData(machine);
|
SetData(machine);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,47 +29,128 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
|
||||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
this.buttonRemoveTank = new System.Windows.Forms.Button();
|
this.buttonRemoveTank = new System.Windows.Forms.Button();
|
||||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
this.buttonAddTank = new System.Windows.Forms.Button();
|
this.buttonAddTank = new System.Windows.Forms.Button();
|
||||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
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.groupBoxTools.SuspendLayout();
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.groupBoxMaps.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
|
||||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRemoveTank);
|
this.groupBoxTools.Controls.Add(this.buttonRemoveTank);
|
||||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonAddTank);
|
this.groupBoxTools.Controls.Add(this.buttonAddTank);
|
||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(807, 0);
|
this.groupBoxTools.Location = new System.Drawing.Point(819, 28);
|
||||||
this.groupBoxTools.Name = "groupBoxTools";
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 546);
|
this.groupBoxTools.Size = new System.Drawing.Size(233, 738);
|
||||||
this.groupBoxTools.TabIndex = 0;
|
this.groupBoxTools.TabIndex = 0;
|
||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Инструменты";
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// groupBoxMaps
|
||||||
|
//
|
||||||
|
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBoxMaps.Location = new System.Drawing.Point(8, 27);
|
||||||
|
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||||
|
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxMaps.Size = new System.Drawing.Size(219, 331);
|
||||||
|
this.groupBoxMaps.TabIndex = 14;
|
||||||
|
this.groupBoxMaps.TabStop = false;
|
||||||
|
this.groupBoxMaps.Text = "Карты";
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 20;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(14, 165);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(198, 104);
|
||||||
|
this.listBoxMaps.TabIndex = 10;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(13, 107);
|
||||||
|
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(200, 47);
|
||||||
|
this.buttonAddMap.TabIndex = 2;
|
||||||
|
this.buttonAddMap.Text = "Добавить карту";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(13, 275);
|
||||||
|
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(200, 47);
|
||||||
|
this.buttonDeleteMap.TabIndex = 4;
|
||||||
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(13, 29);
|
||||||
|
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(199, 27);
|
||||||
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Простая карта",
|
||||||
|
"Город"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 63);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 9;
|
||||||
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
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::ProjectMachine.Properties.Resources.лево;
|
this.buttonLeft.BackgroundImage = global::ProjectMachine.Properties.Resources.лево;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(69, 491);
|
this.buttonLeft.Location = new System.Drawing.Point(69, 683);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(34, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(34, 30);
|
||||||
this.buttonLeft.TabIndex = 13;
|
this.buttonLeft.TabIndex = 13;
|
||||||
@@ -82,7 +163,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::ProjectMachine.Properties.Resources.вверх;
|
this.buttonUp.BackgroundImage = global::ProjectMachine.Properties.Resources.вверх;
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonUp.Location = new System.Drawing.Point(105, 455);
|
this.buttonUp.Location = new System.Drawing.Point(105, 647);
|
||||||
this.buttonUp.Name = "buttonUp";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.Size = new System.Drawing.Size(34, 30);
|
this.buttonUp.Size = new System.Drawing.Size(34, 30);
|
||||||
this.buttonUp.TabIndex = 12;
|
this.buttonUp.TabIndex = 12;
|
||||||
@@ -95,7 +176,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::ProjectMachine.Properties.Resources.право;
|
this.buttonRight.BackgroundImage = global::ProjectMachine.Properties.Resources.право;
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonRight.Location = new System.Drawing.Point(141, 491);
|
this.buttonRight.Location = new System.Drawing.Point(141, 683);
|
||||||
this.buttonRight.Name = "buttonRight";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.Size = new System.Drawing.Size(34, 30);
|
this.buttonRight.Size = new System.Drawing.Size(34, 30);
|
||||||
this.buttonRight.TabIndex = 11;
|
this.buttonRight.TabIndex = 11;
|
||||||
@@ -108,7 +189,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::ProjectMachine.Properties.Resources.вниз;
|
this.buttonDown.BackgroundImage = global::ProjectMachine.Properties.Resources.вниз;
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonDown.Location = new System.Drawing.Point(105, 491);
|
this.buttonDown.Location = new System.Drawing.Point(105, 683);
|
||||||
this.buttonDown.Name = "buttonDown";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.Size = new System.Drawing.Size(34, 30);
|
this.buttonDown.Size = new System.Drawing.Size(34, 30);
|
||||||
this.buttonDown.TabIndex = 10;
|
this.buttonDown.TabIndex = 10;
|
||||||
@@ -116,22 +197,9 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// comboBoxSelectorMap
|
|
||||||
//
|
|
||||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
|
||||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
|
||||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
|
||||||
"Простая карта",
|
|
||||||
"Город"});
|
|
||||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(26, 35);
|
|
||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
|
|
||||||
this.comboBoxSelectorMap.TabIndex = 9;
|
|
||||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
|
||||||
//
|
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(25, 379);
|
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 611);
|
||||||
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
||||||
@@ -142,7 +210,7 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(25, 291);
|
this.buttonShowStorage.Location = new System.Drawing.Point(21, 556);
|
||||||
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
||||||
@@ -153,7 +221,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveTank
|
// buttonRemoveTank
|
||||||
//
|
//
|
||||||
this.buttonRemoveTank.Location = new System.Drawing.Point(25, 205);
|
this.buttonRemoveTank.Location = new System.Drawing.Point(21, 501);
|
||||||
this.buttonRemoveTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonRemoveTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonRemoveTank.Name = "buttonRemoveTank";
|
this.buttonRemoveTank.Name = "buttonRemoveTank";
|
||||||
this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
|
this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
|
||||||
@@ -164,7 +232,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(26, 170);
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 466);
|
||||||
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
@@ -174,7 +242,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddTank
|
// buttonAddTank
|
||||||
//
|
//
|
||||||
this.buttonAddTank.Location = new System.Drawing.Point(25, 82);
|
this.buttonAddTank.Location = new System.Drawing.Point(21, 411);
|
||||||
this.buttonAddTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.buttonAddTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonAddTank.Name = "buttonAddTank";
|
this.buttonAddTank.Name = "buttonAddTank";
|
||||||
this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
|
this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
|
||||||
@@ -186,25 +254,74 @@
|
|||||||
// 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, 0);
|
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||||
this.pictureBox.Name = "pictureBox";
|
this.pictureBox.Name = "pictureBox";
|
||||||
this.pictureBox.Size = new System.Drawing.Size(807, 546);
|
this.pictureBox.Size = new System.Drawing.Size(819, 738);
|
||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// 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(1052, 28);
|
||||||
|
this.menuStrip.TabIndex = 2;
|
||||||
|
this.menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файл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";
|
||||||
|
//
|
||||||
// FormMapWithSetTank
|
// FormMapWithSetTank
|
||||||
//
|
//
|
||||||
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(1040, 546);
|
this.ClientSize = new System.Drawing.Size(1052, 766);
|
||||||
this.Controls.Add(this.pictureBox);
|
this.Controls.Add(this.pictureBox);
|
||||||
this.Controls.Add(this.groupBoxTools);
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Controls.Add(this.menuStrip);
|
||||||
|
this.MainMenuStrip = this.menuStrip;
|
||||||
this.Name = "FormMapWithSetTank";
|
this.Name = "FormMapWithSetTank";
|
||||||
this.Text = "FormMapWithSetTank";
|
this.Text = "FormMapWithSetTank";
|
||||||
this.groupBoxTools.ResumeLayout(false);
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
this.groupBoxTools.PerformLayout();
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.groupBoxMaps.ResumeLayout(false);
|
||||||
|
this.groupBoxMaps.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.menuStrip.ResumeLayout(false);
|
||||||
|
this.menuStrip.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,5 +339,16 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private GroupBox groupBoxMaps;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,15 +13,72 @@ namespace ProjectMachine
|
|||||||
public partial class FormMapWithSetTank : Form
|
public partial class FormMapWithSetTank : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объект от класса карты с набором объектов
|
/// Словарь для выпадающего списка
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MapWithSetTankGeneric<DrawningObject, AbstractMap> _mapTankCollectionGeneric;
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Простая карта", new SimpleMap() },
|
||||||
|
{ "Город", new TownMap() }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormMapWithSetTank()
|
public FormMapWithSetTank()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxMaps
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Выбор карты
|
/// Выбор карты
|
||||||
@@ -30,24 +87,24 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
AbstractMap map = null;
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
switch (comboBoxSelectorMap.Text)
|
|
||||||
{
|
|
||||||
case "Простая карта":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Город":
|
|
||||||
map = new TownMap();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (map != null)
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_mapTankCollectionGeneric = new MapWithSetTankGeneric<DrawningObject, AbstractMap>(
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
pictureBox.Width, pictureBox.Height, map);
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_mapTankCollectionGeneric = null;
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,25 +114,26 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddTank_Click(object sender, EventArgs e)
|
private void ButtonAddTank_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapTankCollectionGeneric == null)
|
var formTankConfig = new FormTankConfig();
|
||||||
{
|
formTankConfig.AddEvent(new(AddTank));
|
||||||
return;
|
formTankConfig.Show();
|
||||||
}
|
}
|
||||||
FormMachine form = new();
|
private void AddTank(DrawningMachine tank)
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
{
|
||||||
DrawningObject tank = new(form.SelectedTank);
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
if ((_mapTankCollectionGeneric + tank) > -1)
|
{
|
||||||
|
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
|
||||||
|
}
|
||||||
|
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(tank) != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта
|
/// Удаление объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -83,6 +141,10 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveTank_Click(object sender, EventArgs e)
|
private void ButtonRemoveTank_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -92,10 +154,10 @@ namespace ProjectMachine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if ((_mapTankCollectionGeneric - pos) != null)
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -109,11 +171,11 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapTankCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод карты
|
/// Вывод карты
|
||||||
@@ -122,11 +184,11 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapTankCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapTankCollectionGeneric.ShowOnMap();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение
|
/// Перемещение
|
||||||
@@ -135,7 +197,7 @@ namespace ProjectMachine
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapTankCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -157,7 +219,46 @@ namespace ProjectMachine
|
|||||||
dir = Direction.Right;
|
dir = Direction.Right;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapTankCollectionGeneric.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,13 @@
|
|||||||
<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>
|
||||||
</root>
|
</root>
|
||||||
385
ProjectMachine/ProjectMachine/FormTankConfig.Designer.cs
generated
Normal file
385
ProjectMachine/ProjectMachine/FormTankConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,385 @@
|
|||||||
|
namespace ProjectMachine
|
||||||
|
{
|
||||||
|
partial class FormTankConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||||
|
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||||
|
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panelPurple = new System.Windows.Forms.Panel();
|
||||||
|
this.panelYellow = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlack = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlue = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGray = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGreen = new System.Windows.Forms.Panel();
|
||||||
|
this.panelWhite = new System.Windows.Forms.Panel();
|
||||||
|
this.panelRed = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBoxGun = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBoxTurret = new System.Windows.Forms.CheckBox();
|
||||||
|
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
|
this.panelObject = new System.Windows.Forms.Panel();
|
||||||
|
this.labelDopColor = new System.Windows.Forms.Label();
|
||||||
|
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||||
|
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonOk = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.groupBoxConfig.SuspendLayout();
|
||||||
|
this.groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||||
|
this.panelObject.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxGun);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxTurret);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||||
|
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
this.groupBoxConfig.Size = new System.Drawing.Size(596, 285);
|
||||||
|
this.groupBoxConfig.TabIndex = 0;
|
||||||
|
this.groupBoxConfig.TabStop = false;
|
||||||
|
this.groupBoxConfig.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelModifiedObject.Location = new System.Drawing.Point(471, 223);
|
||||||
|
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
this.labelModifiedObject.Size = new System.Drawing.Size(111, 50);
|
||||||
|
this.labelModifiedObject.TabIndex = 17;
|
||||||
|
this.labelModifiedObject.Text = "Продвинутый";
|
||||||
|
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelSimpleObject.Location = new System.Drawing.Point(343, 223);
|
||||||
|
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
this.labelSimpleObject.Size = new System.Drawing.Size(111, 50);
|
||||||
|
this.labelSimpleObject.TabIndex = 16;
|
||||||
|
this.labelSimpleObject.Text = "Простой";
|
||||||
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||||
|
this.groupBoxColors.Location = new System.Drawing.Point(326, 27);
|
||||||
|
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxColors.Name = "groupBoxColors";
|
||||||
|
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxColors.Size = new System.Drawing.Size(275, 169);
|
||||||
|
this.groupBoxColors.TabIndex = 15;
|
||||||
|
this.groupBoxColors.TabStop = false;
|
||||||
|
this.groupBoxColors.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||||
|
this.panelPurple.Location = new System.Drawing.Point(210, 97);
|
||||||
|
this.panelPurple.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelPurple.Name = "panelPurple";
|
||||||
|
this.panelPurple.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelPurple.TabIndex = 3;
|
||||||
|
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||||
|
this.panelYellow.Location = new System.Drawing.Point(210, 29);
|
||||||
|
this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelYellow.Name = "panelYellow";
|
||||||
|
this.panelYellow.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelYellow.TabIndex = 1;
|
||||||
|
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.panelBlack.Location = new System.Drawing.Point(145, 97);
|
||||||
|
this.panelBlack.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelBlack.Name = "panelBlack";
|
||||||
|
this.panelBlack.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelBlack.TabIndex = 4;
|
||||||
|
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||||
|
this.panelBlue.Location = new System.Drawing.Point(145, 29);
|
||||||
|
this.panelBlue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelBlue.Name = "panelBlue";
|
||||||
|
this.panelBlue.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelBlue.TabIndex = 1;
|
||||||
|
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||||
|
this.panelGray.Location = new System.Drawing.Point(82, 97);
|
||||||
|
this.panelGray.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelGray.Name = "panelGray";
|
||||||
|
this.panelGray.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelGray.TabIndex = 5;
|
||||||
|
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||||
|
this.panelGreen.Location = new System.Drawing.Point(82, 29);
|
||||||
|
this.panelGreen.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelGreen.Name = "panelGreen";
|
||||||
|
this.panelGreen.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelGreen.TabIndex = 1;
|
||||||
|
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||||
|
this.panelWhite.Location = new System.Drawing.Point(17, 97);
|
||||||
|
this.panelWhite.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelWhite.Name = "panelWhite";
|
||||||
|
this.panelWhite.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelWhite.TabIndex = 2;
|
||||||
|
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||||
|
this.panelRed.Location = new System.Drawing.Point(17, 29);
|
||||||
|
this.panelRed.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelRed.Name = "panelRed";
|
||||||
|
this.panelRed.Size = new System.Drawing.Size(46, 53);
|
||||||
|
this.panelRed.TabIndex = 0;
|
||||||
|
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// checkBoxGun
|
||||||
|
//
|
||||||
|
this.checkBoxGun.AutoSize = true;
|
||||||
|
this.checkBoxGun.Location = new System.Drawing.Point(10, 172);
|
||||||
|
this.checkBoxGun.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.checkBoxGun.Name = "checkBoxGun";
|
||||||
|
this.checkBoxGun.Size = new System.Drawing.Size(299, 24);
|
||||||
|
this.checkBoxGun.TabIndex = 14;
|
||||||
|
this.checkBoxGun.Text = "Признак наличия зенитного пулемета\r\n";
|
||||||
|
this.checkBoxGun.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxTurret
|
||||||
|
//
|
||||||
|
this.checkBoxTurret.AutoSize = true;
|
||||||
|
this.checkBoxTurret.Location = new System.Drawing.Point(10, 124);
|
||||||
|
this.checkBoxTurret.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.checkBoxTurret.Name = "checkBoxTurret";
|
||||||
|
this.checkBoxTurret.Size = new System.Drawing.Size(281, 24);
|
||||||
|
this.checkBoxTurret.TabIndex = 12;
|
||||||
|
this.checkBoxTurret.Text = "Признак наличия башни с орудием\r\n";
|
||||||
|
this.checkBoxTurret.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
this.numericUpDownWeight.Location = new System.Drawing.Point(105, 71);
|
||||||
|
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
this.numericUpDownWeight.Size = new System.Drawing.Size(86, 27);
|
||||||
|
this.numericUpDownWeight.TabIndex = 3;
|
||||||
|
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
this.numericUpDownSpeed.Location = new System.Drawing.Point(105, 27);
|
||||||
|
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
this.numericUpDownSpeed.Size = new System.Drawing.Size(86, 27);
|
||||||
|
this.numericUpDownSpeed.TabIndex = 2;
|
||||||
|
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
this.labelWeight.AutoSize = true;
|
||||||
|
this.labelWeight.Location = new System.Drawing.Point(10, 73);
|
||||||
|
this.labelWeight.Name = "labelWeight";
|
||||||
|
this.labelWeight.Size = new System.Drawing.Size(36, 20);
|
||||||
|
this.labelWeight.TabIndex = 1;
|
||||||
|
this.labelWeight.Text = "Вес:";
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
this.labelSpeed.AutoSize = true;
|
||||||
|
this.labelSpeed.Location = new System.Drawing.Point(10, 30);
|
||||||
|
this.labelSpeed.Name = "labelSpeed";
|
||||||
|
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||||
|
this.labelSpeed.TabIndex = 0;
|
||||||
|
this.labelSpeed.Text = "Скорость:";
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
this.panelObject.AllowDrop = true;
|
||||||
|
this.panelObject.Controls.Add(this.labelDopColor);
|
||||||
|
this.panelObject.Controls.Add(this.labelBaseColor);
|
||||||
|
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||||
|
this.panelObject.Location = new System.Drawing.Point(629, 24);
|
||||||
|
this.panelObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panelObject.Name = "panelObject";
|
||||||
|
this.panelObject.Size = new System.Drawing.Size(299, 245);
|
||||||
|
this.panelObject.TabIndex = 3;
|
||||||
|
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||||
|
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||||
|
//
|
||||||
|
// labelDopColor
|
||||||
|
//
|
||||||
|
this.labelDopColor.AllowDrop = true;
|
||||||
|
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelDopColor.Location = new System.Drawing.Point(161, 12);
|
||||||
|
this.labelDopColor.Name = "labelDopColor";
|
||||||
|
this.labelDopColor.Size = new System.Drawing.Size(119, 42);
|
||||||
|
this.labelDopColor.TabIndex = 2;
|
||||||
|
this.labelDopColor.Text = "Доп. цвет";
|
||||||
|
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||||
|
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// labelBaseColor
|
||||||
|
//
|
||||||
|
this.labelBaseColor.AllowDrop = true;
|
||||||
|
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelBaseColor.Location = new System.Drawing.Point(23, 12);
|
||||||
|
this.labelBaseColor.Name = "labelBaseColor";
|
||||||
|
this.labelBaseColor.Size = new System.Drawing.Size(119, 42);
|
||||||
|
this.labelBaseColor.TabIndex = 1;
|
||||||
|
this.labelBaseColor.Text = "Цвет";
|
||||||
|
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||||
|
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
this.pictureBoxObject.Location = new System.Drawing.Point(23, 59);
|
||||||
|
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
this.pictureBoxObject.Size = new System.Drawing.Size(257, 167);
|
||||||
|
this.pictureBoxObject.TabIndex = 0;
|
||||||
|
this.pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonOk
|
||||||
|
//
|
||||||
|
this.buttonOk.Location = new System.Drawing.Point(652, 277);
|
||||||
|
this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.buttonOk.Name = "buttonOk";
|
||||||
|
this.buttonOk.Size = new System.Drawing.Size(119, 40);
|
||||||
|
this.buttonOk.TabIndex = 5;
|
||||||
|
this.buttonOk.Text = "Добавить";
|
||||||
|
this.buttonOk.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(790, 277);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(119, 40);
|
||||||
|
this.buttonCancel.TabIndex = 6;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormTankConfig
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(937, 329);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonOk);
|
||||||
|
this.Controls.Add(this.panelObject);
|
||||||
|
this.Controls.Add(this.groupBoxConfig);
|
||||||
|
this.Name = "FormTankConfig";
|
||||||
|
this.Text = "Создание объекта";
|
||||||
|
this.groupBoxConfig.ResumeLayout(false);
|
||||||
|
this.groupBoxConfig.PerformLayout();
|
||||||
|
this.groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||||
|
this.panelObject.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxConfig;
|
||||||
|
private CheckBox checkBoxGun;
|
||||||
|
private CheckBox checkBoxTurret;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelWeight;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Panel panelObject;
|
||||||
|
private Label labelDopColor;
|
||||||
|
private Label labelBaseColor;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Button buttonOk;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
||||||
173
ProjectMachine/ProjectMachine/FormTankConfig.cs
Normal file
173
ProjectMachine/ProjectMachine/FormTankConfig.cs
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectMachine
|
||||||
|
{
|
||||||
|
public partial class FormTankConfig : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Переменная-выбранная машина
|
||||||
|
/// </summary>
|
||||||
|
DrawningMachine _tank = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
private event TankDelegate EventAddTank;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormTankConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||||
|
buttonCancel.Click += (s, e) => Close();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовать машину
|
||||||
|
/// </summary>
|
||||||
|
private void DrawTank()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_tank?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
_tank?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление события
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ev"></param>
|
||||||
|
public void AddEvent(TankDelegate ev)
|
||||||
|
{
|
||||||
|
if (EventAddTank == null)
|
||||||
|
{
|
||||||
|
EventAddTank = new TankDelegate(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddTank += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Передаем информацию при нажатии на Label
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Действия при приеме перетаскиваемой информации
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_tank = new DrawningMachine((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_tank = new DrawningTank((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||||
|
checkBoxTurret.Checked, checkBoxGun.Checked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawTank();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отправляем цвет с панели
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Принимаем основной цвет
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_tank != null)
|
||||||
|
{
|
||||||
|
_tank.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
DrawTank();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Принимаем дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_tank is DrawningTank)
|
||||||
|
{
|
||||||
|
var tank = _tank as DrawningTank;
|
||||||
|
tank.SetDopColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
}
|
||||||
|
DrawTank();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление машины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonOk_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddTank?.Invoke(_tank);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
ProjectMachine/ProjectMachine/FormTankConfig.resx
Normal file
60
ProjectMachine/ProjectMachine/FormTankConfig.resx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
@@ -39,5 +39,10 @@ namespace ProjectMachine
|
|||||||
/// </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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,14 +94,10 @@ namespace ProjectMachine
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setTank.Count; i++)
|
foreach (var tank in _setTank.GetTanks())
|
||||||
{
|
|
||||||
var tank = _setTank.Get(i);
|
|
||||||
if (tank != null)
|
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, tank);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, tank);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -118,6 +114,31 @@ namespace ProjectMachine
|
|||||||
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 tank in _setTank.GetTanks())
|
||||||
|
{
|
||||||
|
data += $"{tank.GetInfo()}{separatorData}";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка списка из массива строк
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="records"></param>
|
||||||
|
public void LoadData(string[] records)
|
||||||
|
{
|
||||||
|
foreach (var rec in records)
|
||||||
|
{
|
||||||
|
_setTank.Insert(DrawningObject.Create(rec) as T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Shaking()
|
private void Shaking()
|
||||||
@@ -125,11 +146,11 @@ namespace ProjectMachine
|
|||||||
int j = _setTank.Count - 1;
|
int j = _setTank.Count - 1;
|
||||||
for (int i = 0; i < _setTank.Count; i++)
|
for (int i = 0; i < _setTank.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setTank.Get(i) == null)
|
if (_setTank[i] == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var car = _setTank.Get(j);
|
var car = _setTank[j];
|
||||||
if (car != null)
|
if (car != null)
|
||||||
{
|
{
|
||||||
_setTank.Insert(car, i);
|
_setTank.Insert(car, i);
|
||||||
@@ -170,21 +191,13 @@ namespace ProjectMachine
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawTanks(Graphics g)
|
private void DrawTanks(Graphics g)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int j = 0;
|
int k = 0;
|
||||||
for (int k = 0; k < _setTank.Count; k++)
|
foreach (var tank in _setTank.GetTanks())
|
||||||
{
|
{
|
||||||
_setTank.Get(k)?.SetObject(j + 10, i + 20, _pictureWidth, _pictureHeight);
|
tank.SetObject(k % width * _placeSizeWidth + 10, k / width * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||||
_setTank.Get(k)?.DrawningObject(g);
|
tank.DrawningObject(g);
|
||||||
if (j >= _pictureWidth - 2*_placeSizeWidth)
|
k++;
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
i += _placeSizeHeight;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
j += _placeSizeWidth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
154
ProjectMachine/ProjectMachine/MapsCollection.cs
Normal file
154
ProjectMachine/ProjectMachine/MapsCollection.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectMachine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с картами
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, MapWithSetTankGeneric<IDrawningObject, 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>
|
||||||
|
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,MapWithSetTankGeneric<IDrawningObject, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
/// <param name="map">Карта</param>
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
if (!Keys.Contains(name))
|
||||||
|
_mapStorages.Add(name, new MapWithSetTankGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
if (Keys.Contains(name))
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к парковке
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public MapWithSetTankGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Keys.Contains(ind))
|
||||||
|
return _mapStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод записи информации в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">Строка, которую следует записать</param>
|
||||||
|
/// <param name="stream">Поток для записи</param>
|
||||||
|
private static void WriteToFile(string text, FileStream stream)
|
||||||
|
{
|
||||||
|
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
||||||
|
stream.Write(info, 0, info.Length);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
using (StreamWriter f = new(filename))
|
||||||
|
{
|
||||||
|
f.Write($"MapsCollection{Environment.NewLine}");
|
||||||
|
foreach (var storage in _mapStorages)
|
||||||
|
{
|
||||||
|
f.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка нформации по автомобилям на парковках из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamReader f = new(filename))
|
||||||
|
{
|
||||||
|
if (!f.ReadLine().Contains("MapsCollection"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//очищаем записи
|
||||||
|
_mapStorages.Clear();
|
||||||
|
while (!f.EndOfStream)
|
||||||
|
{
|
||||||
|
var elem = f.ReadLine().Split(separatorDict);
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (elem[1])
|
||||||
|
{
|
||||||
|
case "SimpleMap":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "TownMap":
|
||||||
|
map = new TownMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_mapStorages.Add(elem[0], new MapWithSetTankGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -14,39 +14,34 @@ namespace ProjectMachine
|
|||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly T[] _places;
|
private readonly List<T> _places;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в списке
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetTankGeneric(int count)
|
public SetTankGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="car">Добавляемый танк</param>
|
/// <param name="tank">Добавляемый танк</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T tank)
|
public int Insert(T tank)
|
||||||
{
|
{
|
||||||
if (tank == null)
|
if (Count < _maxCount)
|
||||||
{
|
return Insert(tank, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (int i = Count -1; i > 0; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[0] = tank;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -55,25 +50,10 @@ namespace ProjectMachine
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T tank, int position)
|
public int Insert(T tank, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
_places.Insert(position, tank);
|
||||||
int firstNullElementIndex = position; //индекс первого нулевого элемента
|
return position;
|
||||||
while(_places[firstNullElementIndex] != null)
|
|
||||||
{
|
|
||||||
if (firstNullElementIndex >= Count)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
firstNullElementIndex++;
|
|
||||||
}
|
|
||||||
for (int i = firstNullElementIndex; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = tank;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@@ -82,12 +62,10 @@ namespace ProjectMachine
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (_places[position] == null)
|
if (position < 0 || position >= Count)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
var result = _places[position];
|
var result = _places[position];
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -95,15 +73,39 @@ namespace ProjectMachine
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T this[int position]
|
||||||
{
|
{
|
||||||
if (_places[position] != null)
|
get
|
||||||
{
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
return null;
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
return;
|
||||||
|
_places.Add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T> GetTanks()
|
||||||
|
{
|
||||||
|
foreach (var tank in _places)
|
||||||
|
{
|
||||||
|
if (tank != null)
|
||||||
|
{
|
||||||
|
yield return tank;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
8
ProjectMachine/ProjectMachine/TankDelegate.cs
Normal file
8
ProjectMachine/ProjectMachine/TankDelegate.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace ProjectMachine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Делегат для передачи объекта-танка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tank"></param>
|
||||||
|
public delegate void TankDelegate(DrawningMachine tank);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user