8 Commits

Author SHA1 Message Date
evasina2312@gmail.com
474573214e Лабораторная 5 2022-11-24 12:19:32 +04:00
evasina2312@gmail.com
5de55d7ef9 Сделаны ТODO 2022-11-24 01:54:30 +04:00
evasina2312@gmail.com
25b16cfdf9 Изменения 2022-11-24 01:00:55 +04:00
evasina2312@gmail.com
4276aa834e Event work 2022-11-24 00:23:39 +04:00
evasina2312@gmail.com
5cc6f9c611 Add config form 2022-11-24 00:02:28 +04:00
evasina2312@gmail.com
79e9924e04 Лабораторная 4 2022-11-10 14:48:47 +04:00
evasina2312@gmail.com
45cb2513f3 Этап 2. Класс MapsCollection 2022-11-10 08:00:22 +04:00
evasina2312@gmail.com
ec5c587297 Этап 1. Замена массива на список 2022-11-10 07:54:26 +04:00
14 changed files with 985 additions and 138 deletions

View File

@@ -177,5 +177,19 @@ namespace ProjectMachine
{
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);
}
}
}

View File

@@ -17,10 +17,10 @@ namespace ProjectMachine
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="turret">Признак наличия башни с орудием</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)
{
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)
{
@@ -50,5 +50,14 @@ namespace ProjectMachine
_startPosX -= 10;
_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);
}
}
}
}

View File

@@ -34,14 +34,12 @@ namespace ProjectMachine
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// /// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="turret">Признак наличия башни с орудием</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)
{
DopColor = dopColor;
BodyKit = bodyKit;
Turret = turret;
Gun = gun;
}

View File

@@ -107,7 +107,7 @@ namespace ProjectMachine
dopColor = dialogDop.Color;
}
_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();
Draw();
}

View File

@@ -77,7 +77,7 @@ namespace ProjectMachine
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
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);
}
/// <summary>

View File

@@ -29,11 +29,16 @@
private void InitializeComponent()
{
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.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = 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.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveTank = new System.Windows.Forms.Button();
@@ -41,35 +46,104 @@
this.buttonAddTank = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveTank);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddTank);
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, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(233, 546);
this.groupBoxTools.Size = new System.Drawing.Size(233, 766);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
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
//
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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(69, 491);
this.buttonLeft.Location = new System.Drawing.Point(69, 711);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 30);
this.buttonLeft.TabIndex = 13;
@@ -82,7 +156,7 @@
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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(105, 455);
this.buttonUp.Location = new System.Drawing.Point(105, 675);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 30);
this.buttonUp.TabIndex = 12;
@@ -95,7 +169,7 @@
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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(141, 491);
this.buttonRight.Location = new System.Drawing.Point(141, 711);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 30);
this.buttonRight.TabIndex = 11;
@@ -108,7 +182,7 @@
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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(105, 491);
this.buttonDown.Location = new System.Drawing.Point(105, 711);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 30);
this.buttonDown.TabIndex = 10;
@@ -116,22 +190,9 @@
this.buttonDown.UseVisualStyleBackColor = true;
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
//
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.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
@@ -142,7 +203,7 @@
//
// 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.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
@@ -153,7 +214,7 @@
//
// 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.Name = "buttonRemoveTank";
this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
@@ -164,7 +225,7 @@
//
// 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.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
@@ -174,7 +235,7 @@
//
// 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.Name = "buttonAddTank";
this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
@@ -188,7 +249,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(807, 546);
this.pictureBox.Size = new System.Drawing.Size(819, 766);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -196,13 +257,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
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.groupBoxTools);
this.Name = "FormMapWithSetTank";
this.Text = "FormMapWithSetTank";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -222,5 +285,10 @@
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
private GroupBox groupBoxMaps;
private Button buttonAddMap;
private Button buttonDeleteMap;
private TextBox textBoxNewMapName;
private ListBox listBoxMaps;
}
}

View File

@@ -13,15 +13,72 @@ namespace ProjectMachine
public partial class FormMapWithSetTank : Form
{
/// <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>
public FormMapWithSetTank()
{
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>
/// Выбор карты
@@ -30,24 +87,24 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Город":
map = new TownMap();
break;
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
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>(
pictureBox.Width, pictureBox.Height, map);
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
else
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapTankCollectionGeneric = null;
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
/// <summary>
@@ -57,25 +114,26 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ButtonAddTank_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
{
return;
var formTankConfig = new FormTankConfig();
formTankConfig.AddEvent(new(AddTank));
formTankConfig.Show();
}
FormMachine form = new();
if (form.ShowDialog() == DialogResult.OK)
private void AddTank(DrawningMachine tank)
{
DrawningObject tank = new(form.SelectedTank);
if ((_mapTankCollectionGeneric + tank) > -1)
if (listBoxMaps.SelectedIndex == -1)
{
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
}
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(tank) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
@@ -83,6 +141,10 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ButtonRemoveTank_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -92,10 +154,10 @@ namespace ProjectMachine
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapTankCollectionGeneric - pos) != null)
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos!=null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -109,11 +171,11 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Вывод карты
@@ -122,11 +184,11 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapTankCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
/// <summary>
/// Перемещение
@@ -135,7 +197,7 @@ namespace ProjectMachine
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -157,7 +219,7 @@ namespace ProjectMachine
dir = Direction.Right;
break;
}
pictureBox.Image = _mapTankCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
}
}

View 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;
}
}

View 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();
}
}
}

View 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>

View File

@@ -94,14 +94,10 @@ namespace ProjectMachine
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setTank.Count; i++)
{
var tank = _setTank.Get(i);
if (tank != null)
foreach (var tank in _setTank.GetTanks())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, tank);
}
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
@@ -125,11 +121,11 @@ namespace ProjectMachine
int j = _setTank.Count - 1;
for (int i = 0; i < _setTank.Count; i++)
{
if (_setTank.Get(i) == null)
if (_setTank[i] == null)
{
for (; j > i; j--)
{
var car = _setTank.Get(j);
var car = _setTank[j];
if (car != null)
{
_setTank.Insert(car, i);
@@ -170,21 +166,13 @@ namespace ProjectMachine
/// <param name="g"></param>
private void DrawTanks(Graphics g)
{
int i = 0;
int j = 0;
for (int k = 0; k < _setTank.Count; k++)
int width = _pictureWidth / _placeSizeWidth;
int k = 0;
foreach (var tank in _setTank.GetTanks())
{
_setTank.Get(k)?.SetObject(j + 10, i + 20, _pictureWidth, _pictureHeight);
_setTank.Get(k)?.DrawningObject(g);
if (j >= _pictureWidth - 2*_placeSizeWidth)
{
j = 0;
i += _placeSizeHeight;
}
else
{
j += _placeSizeWidth;
}
tank.SetObject(k % width * _placeSizeWidth + 10, k / width * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
tank.DrawningObject(g);
k++;
}
}
}

View File

@@ -0,0 +1,80 @@
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<DrawningObject,
AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string,
MapWithSetTankGeneric<DrawningObject, 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<DrawningObject, 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<DrawningObject, AbstractMap> this[string
ind]
{
get
{
if (Keys.Contains(ind))
return _mapStorages[ind];
return null;
}
}
}
}

View File

@@ -14,39 +14,34 @@ namespace ProjectMachine
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// Список объектов, которые храним
/// </summary>
private readonly T[] _places;
private readonly List<T> _places;
/// <summary>
/// Количество объектов в массиве
/// Количество объектов в списке
/// </summary>
public int Count => _places.Length;
public int Count => _places.Count;
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetTankGeneric(int count)
{
_places = new T[count];
_maxCount = count;
_places = new List<T>();
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый танк</param>
/// <param name="tank">Добавляемый танк</param>
/// <returns></returns>
public int Insert(T tank)
{
if (tank == null)
{
if (Count < _maxCount)
return Insert(tank, 0);
return -1;
}
for (int i = Count -1; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[0] = tank;
return 0;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
@@ -55,25 +50,10 @@ namespace ProjectMachine
/// <returns></returns>
public int Insert(T tank, int position)
{
if (position < 0 || position > Count)
{
if (position < 0 || position >= _maxCount)
return -1;
}
int firstNullElementIndex = 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;
_places.Insert(position, tank);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
@@ -82,12 +62,10 @@ namespace ProjectMachine
/// <returns></returns>
public T Remove(int position)
{
if (_places[position] == null)
{
if (position < 0 || position >= Count)
return null;
}
var result = _places[position];
_places[position] = null;
_places.RemoveAt(position);
return result;
}
/// <summary>
@@ -95,15 +73,39 @@ namespace ProjectMachine
/// </summary>
/// <param name="position"></param>
/// <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 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;
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
namespace ProjectMachine
{
/// <summary>
/// Делегат для передачи объекта-танка
/// </summary>
/// <param name="tank"></param>
public delegate void TankDelegate(DrawningMachine tank);
}