PIbd-21 Belianin N.N. LabWork05 #5

Closed
Belnik wants to merge 7 commits from LabWork05 into LabWork04
17 changed files with 739 additions and 56 deletions
Showing only changes of commit 02559b8c72 - Show all commits

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{5C602C58-ECEC-4FAB-BA10-FB671582D227}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.Build.0 = Release|Any CPU
{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73BF3262-E499-401F-BDBD-BD2BC7D3C324}
SolutionGuid = {73628EAF-BF42-4CF6-87BF-26523028F0DD}
EndGlobalSection
EndGlobal

View File

@ -1,6 +1,6 @@
namespace Tank
{
partial class FormTanksCollections
partial class CollectionsFrame
{
/// <summary>
/// Required designer variable.

View File

@ -13,12 +13,12 @@ using System.Windows.Forms;
namespace Tank
{
public partial class FormTanksCollections : Form
public partial class CollectionsFrame : Form
{
private readonly TanksGenericStorage _storage;
// Конструктор
public FormTanksCollections()
public CollectionsFrame()
{
InitializeComponent();
_storage = new TanksGenericStorage(DrawTank.Width, DrawTank.Height);
@ -77,7 +77,7 @@ namespace Tank
}
}
private void ButtonAddTank_Click(object sender, EventArgs e)
private void AddTank(DrawArmoVehicle tank)
{
if (CollectionListBox.SelectedIndex == -1)
{
@ -88,20 +88,34 @@ namespace Tank
{
return;
}
FormTank form = new();
if (form.ShowDialog() == DialogResult.OK)
if ((obj + tank) != false)
{
if (obj + form.SelectedTank)
{
MessageBox.Show("Объект добавлен");
DrawTank.Image = obj.ShowTanks();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
MessageBox.Show("Объект добавлен");
DrawTank.Image = obj.ShowTanks();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void ButtonAddTank_Click(object sender, EventArgs e)
{
// Проверка на вызов формочки
if (CollectionListBox.SelectedIndex == -1)
{
return;
}
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormTankConfig form = new FormTankConfig();
form.Show();
form.AddEvent(AddTank);
}
private void ButtonRemoveTank_Click(object sender, EventArgs e)
{
if (CollectionListBox.SelectedIndex == -1)

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Security.Cryptography.Pkcs;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Tank.Entities;
using Tank.MovementStrategy;
@ -12,8 +13,8 @@ namespace Tank
public class DrawArmoVehicle
{
public EntityArmoVehicle? Tank { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
public int _pictureWidth;
public int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _Width = 160;
@ -55,6 +56,7 @@ namespace Tank
Direction.Right => _startPosX + _Width + Tank.Step < _pictureWidth,
Direction.Down => _startPosY + _Height + Tank.Step < _pictureHeight,
_ => false
};
}

View File

@ -38,7 +38,7 @@ namespace Tank.DrawningObjects
if (ArmoVehicle.Caterpillar)
{
// Гусеница. Отрисовка танковых катков
Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black);
Brush BrushRandom = new SolidBrush(ArmoVehicle?.AdditionalColor ?? Color.Black);
g.FillRectangle(BrushRandom, 28 + _startPosX, 50 + _startPosY, 10, 3);
g.FillRectangle(BrushRandom, 53 + _startPosX, 50 + _startPosY, 10, 3);
g.FillRectangle(BrushRandom, 78 + _startPosX, 50 + _startPosY, 10, 3);

View File

@ -4,13 +4,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank.Entities
namespace Tank
{
public class EntityArmoVehicle
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
public void setBodyColor(Color color) { BodyColor = color; }
public double Step => (double)Speed * 100 / Weight;
public EntityArmoVehicle(int speed, double weight, Color bodyColor)
{

View File

@ -9,6 +9,7 @@ namespace Tank.Entities
public class EntityTank : EntityArmoVehicle
{
public Color AdditionalColor { get; private set; }
public void setAdditionalColor(Color color) { AdditionalColor = color; }
public bool BodyKit { get; private set; }
public bool Caterpillar { get; private set; }
public bool Tower { get; private set; }

View File

@ -173,6 +173,7 @@
Margin = new Padding(3, 4, 3, 4);
Name = "FormTank";
Text = "FormTank";
Load += FormTank_Load;
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
ResumeLayout(false);
}

View File

@ -128,5 +128,10 @@ namespace Tank
SelectedTank = _Tank;
DialogResult = DialogResult.OK;
}
private void FormTank_Load(object sender, EventArgs e)
{
}
}
}

405
Tank/Tank/FormTankConfig.Designer.cs generated Normal file
View File

@ -0,0 +1,405 @@
namespace Tank
{
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()
{
ParamsGroup = new GroupBox();
labelTank = new Label();
labelArmoVehicle = new Label();
groupBoxColors = new GroupBox();
panelPink = new Panel();
panelYellow = new Panel();
panelCyan = new Panel();
panelRed = new Panel();
panelBlue = new Panel();
panelOrange = new Panel();
panelGreen = new Panel();
panelSilver = new Panel();
checkBoxCaterpillar = new CheckBox();
checkBoxBodyKit = new CheckBox();
checkBoxTower = new CheckBox();
numericWeight = new NumericUpDown();
numericSpeed = new NumericUpDown();
weightLabel = new Label();
speedLabel = new Label();
panelPictureTank = new Panel();
pictureBox = new PictureBox();
buttonAdd = new Button();
buttonCancel = new Button();
labelColor = new Label();
labelAdditionalColor = new Label();
ParamsGroup.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericSpeed).BeginInit();
panelPictureTank.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// ParamsGroup
//
ParamsGroup.Controls.Add(labelTank);
ParamsGroup.Controls.Add(labelArmoVehicle);
ParamsGroup.Controls.Add(groupBoxColors);
ParamsGroup.Controls.Add(checkBoxCaterpillar);
ParamsGroup.Controls.Add(checkBoxBodyKit);
ParamsGroup.Controls.Add(checkBoxTower);
ParamsGroup.Controls.Add(numericWeight);
ParamsGroup.Controls.Add(numericSpeed);
ParamsGroup.Controls.Add(weightLabel);
ParamsGroup.Controls.Add(speedLabel);
ParamsGroup.Location = new Point(5, 3);
ParamsGroup.Margin = new Padding(5, 4, 5, 4);
ParamsGroup.Name = "ParamsGroup";
ParamsGroup.Padding = new Padding(5, 4, 5, 4);
ParamsGroup.Size = new Size(240, 740);
ParamsGroup.TabIndex = 0;
ParamsGroup.TabStop = false;
ParamsGroup.Text = "Params Group Box";
//
// labelTank
//
labelTank.BorderStyle = BorderStyle.FixedSingle;
labelTank.Location = new Point(120, 644);
labelTank.Margin = new Padding(5, 0, 5, 0);
labelTank.Name = "labelTank";
labelTank.Size = new Size(87, 55);
labelTank.TabIndex = 10;
labelTank.Text = "Tank";
labelTank.TextAlign = ContentAlignment.MiddleCenter;
labelTank.MouseDown += LabelObject_MouseDown;
//
// labelArmoVehicle
//
labelArmoVehicle.BorderStyle = BorderStyle.FixedSingle;
labelArmoVehicle.Location = new Point(9, 644);
labelArmoVehicle.Margin = new Padding(5, 0, 5, 0);
labelArmoVehicle.Name = "labelArmoVehicle";
labelArmoVehicle.Size = new Size(96, 55);
labelArmoVehicle.TabIndex = 9;
labelArmoVehicle.Text = "ArmoVehicle";
labelArmoVehicle.TextAlign = ContentAlignment.MiddleCenter;
labelArmoVehicle.MouseDown += LabelObject_MouseDown;
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelPink);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelCyan);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelOrange);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelSilver);
groupBoxColors.Location = new Point(16, 268);
groupBoxColors.Margin = new Padding(5, 4, 5, 4);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Padding = new Padding(5, 4, 5, 4);
groupBoxColors.Size = new Size(210, 348);
groupBoxColors.TabIndex = 8;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Colors";
//
// panelPink
//
panelPink.BackColor = Color.Fuchsia;
panelPink.Location = new Point(107, 276);
panelPink.Margin = new Padding(5, 4, 5, 4);
panelPink.Name = "panelPink";
panelPink.Size = new Size(56, 61);
panelPink.TabIndex = 3;
panelPink.MouseDown += panelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(107, 108);
panelYellow.Margin = new Padding(5, 4, 5, 4);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(56, 61);
panelYellow.TabIndex = 1;
panelYellow.MouseDown += panelColor_MouseDown;
//
// panelCyan
//
panelCyan.BackColor = Color.Cyan;
panelCyan.Location = new Point(107, 192);
panelCyan.Margin = new Padding(5, 4, 5, 4);
panelCyan.Name = "panelCyan";
panelCyan.Size = new Size(56, 61);
panelCyan.TabIndex = 4;
panelCyan.MouseDown += panelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(107, 24);
panelRed.Margin = new Padding(5, 4, 5, 4);
panelRed.Name = "panelRed";
panelRed.Size = new Size(56, 61);
panelRed.TabIndex = 1;
panelRed.MouseDown += panelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(33, 276);
panelBlue.Margin = new Padding(5, 4, 5, 4);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(56, 61);
panelBlue.TabIndex = 5;
panelBlue.MouseDown += panelColor_MouseDown;
//
// panelOrange
//
panelOrange.BackColor = Color.FromArgb(255, 128, 0);
panelOrange.Location = new Point(33, 108);
panelOrange.Margin = new Padding(5, 4, 5, 4);
panelOrange.Name = "panelOrange";
panelOrange.Size = new Size(56, 61);
panelOrange.TabIndex = 1;
panelOrange.MouseDown += panelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.Lime;
panelGreen.Location = new Point(33, 192);
panelGreen.Margin = new Padding(5, 4, 5, 4);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(56, 61);
panelGreen.TabIndex = 2;
panelGreen.MouseDown += panelColor_MouseDown;
//
// panelSilver
//
panelSilver.BackColor = Color.Silver;
panelSilver.Location = new Point(33, 24);
panelSilver.Margin = new Padding(5, 4, 5, 4);
panelSilver.Name = "panelSilver";
panelSilver.Size = new Size(56, 61);
panelSilver.TabIndex = 0;
panelSilver.MouseDown += panelColor_MouseDown;
//
// checkBoxCaterpillarTank
//
checkBoxCaterpillar.AutoSize = true;
checkBoxCaterpillar.Location = new Point(18, 180);
checkBoxCaterpillar.Margin = new Padding(5, 4, 5, 4);
checkBoxCaterpillar.Name = "checkBoxCaterpillarTank";
checkBoxCaterpillar.Size = new Size(100, 24);
checkBoxCaterpillar.TabIndex = 7;
checkBoxCaterpillar.Text = "Caterpillar";
checkBoxCaterpillar.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
checkBoxBodyKit.AutoSize = true;
checkBoxBodyKit.Location = new Point(18, 149);
checkBoxBodyKit.Margin = new Padding(5, 4, 5, 4);
checkBoxBodyKit.Name = "checkBoxBodyKit";
checkBoxBodyKit.Size = new Size(83, 24);
checkBoxBodyKit.TabIndex = 6;
checkBoxBodyKit.Text = "BodyKit";
checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// checkBoxTower
//
checkBoxTower.AutoSize = true;
checkBoxTower.Location = new Point(18, 216);
checkBoxTower.Margin = new Padding(5, 4, 5, 4);
checkBoxTower.Name = "checkBoxTower";
checkBoxTower.Size = new Size(71, 24);
checkBoxTower.TabIndex = 5;
checkBoxTower.Text = "Tower";
checkBoxTower.UseVisualStyleBackColor = true;
//
// numericWeight
//
numericWeight.Location = new Point(66, 79);
numericWeight.Margin = new Padding(5, 4, 5, 4);
numericWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericWeight.Name = "numericWeight";
numericWeight.Size = new Size(160, 27);
numericWeight.TabIndex = 4;
numericWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericSpeed
//
numericSpeed.Location = new Point(66, 36);
numericSpeed.Margin = new Padding(5, 4, 5, 4);
numericSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericSpeed.Name = "numericSpeed";
numericSpeed.Size = new Size(160, 27);
numericSpeed.TabIndex = 3;
numericSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// weightLabel
//
weightLabel.AutoSize = true;
weightLabel.Location = new Point(11, 79);
weightLabel.Margin = new Padding(5, 0, 5, 0);
weightLabel.Name = "weightLabel";
weightLabel.Size = new Size(49, 20);
weightLabel.TabIndex = 2;
weightLabel.Text = "weigh";
//
// speedLabel
//
speedLabel.AutoSize = true;
speedLabel.Location = new Point(11, 39);
speedLabel.Margin = new Padding(5, 0, 5, 0);
speedLabel.Name = "speedLabel";
speedLabel.Size = new Size(49, 20);
speedLabel.TabIndex = 1;
speedLabel.Text = "speed";
//
// panel9
//
panelPictureTank.AllowDrop = true;
panelPictureTank.Controls.Add(pictureBox);
panelPictureTank.Location = new Point(266, 116);
panelPictureTank.Margin = new Padding(5, 4, 5, 4);
panelPictureTank.Name = "panel9";
panelPictureTank.Size = new Size(784, 520);
panelPictureTank.TabIndex = 11;
panelPictureTank.DragDrop += PanelObject_DragDrop;
panelPictureTank.DragEnter += PanelObject_DragEnter;
//
// pictureBox
//
pictureBox.Location = new Point(18, 8);
pictureBox.Margin = new Padding(5, 4, 5, 4);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(741, 508);
pictureBox.TabIndex = 0;
pictureBox.TabStop = false;
//
// buttonAdd
//
buttonAdd.Location = new Point(306, 660);
buttonAdd.Margin = new Padding(5, 4, 5, 4);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(200, 62);
buttonAdd.TabIndex = 12;
buttonAdd.Text = "Add";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonOk_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(793, 662);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(210, 60);
buttonCancel.TabIndex = 13;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
//
// labelColor
//
labelColor.AllowDrop = true;
labelColor.BorderStyle = BorderStyle.FixedSingle;
labelColor.Location = new Point(349, 37);
labelColor.Margin = new Padding(5, 0, 5, 0);
labelColor.Name = "labelColor";
labelColor.Size = new Size(139, 42);
labelColor.TabIndex = 14;
labelColor.Text = "Color";
labelColor.TextAlign = ContentAlignment.MiddleCenter;
labelColor.DragDrop += labelColor_DragDrop;
labelColor.DragEnter += labelColor_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(815, 32);
labelAdditionalColor.Margin = new Padding(5, 0, 5, 0);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(136, 39);
labelAdditionalColor.TabIndex = 15;
labelAdditionalColor.Text = "Additional color";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += labelColor_DragDrop;
labelAdditionalColor.DragEnter += labelColor_DragEnter;
//
// FormTankConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1066, 744);
Controls.Add(labelAdditionalColor);
Controls.Add(labelColor);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(panelPictureTank);
Controls.Add(ParamsGroup);
Margin = new Padding(5, 4, 5, 4);
Name = "FormTankConfig";
Text = "FormTankConfig";
ParamsGroup.ResumeLayout(false);
ParamsGroup.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericSpeed).EndInit();
panelPictureTank.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox ParamsGroup;
private CheckBox checkBoxCaterpillar;
private CheckBox checkBoxBodyKit;
private CheckBox checkBoxTower;
private NumericUpDown numericWeight;
private NumericUpDown numericSpeed;
private Label weightLabel;
private Label speedLabel;
private GroupBox groupBoxColors;
private Panel panelPink;
private Panel panelYellow;
private Panel panelCyan;
private Panel panelRed;
private Panel panelBlue;
private Panel panelOrange;
private Panel panelGreen;
private Panel panelSilver;
private Label labelTank;
private Label labelArmoVehicle;
private Panel panelPictureTank;
private PictureBox pictureBox;
private Button buttonAdd;
private Button buttonCancel;
private Label labelColor;
private Label labelAdditionalColor;
}
}

148
Tank/Tank/FormTankConfig.cs Normal file
View File

@ -0,0 +1,148 @@
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;
using Tank.DrawningObjects;
using Tank.Entities;
namespace Tank
{
public partial class FormTankConfig : Form
{
Color defaultColor;
// Переменная-выбранный танк
DrawArmoVehicle _tank = null;
// Событие
private event Action<DrawArmoVehicle> EventAddTank;
// Конструктор
public FormTankConfig()
{
InitializeComponent();
panelSilver.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelOrange.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelCyan.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
panelPink.MouseDown += panelColor_MouseDown;
defaultColor = labelColor.BackColor;
buttonCancel.Click += (s, e) => Close();
}
// Отрисовать танк
private void DrawingTank()
{
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);
Graphics gr = Graphics.FromImage(bmp);
_tank?.SetPosition(5, 5);
if (_tank is DrawTank)
(_tank as DrawTank).DrawTransport(gr);
else
_tank?.DrawTransport(gr);
pictureBox.Image = bmp;
}
// Добавление события
internal void AddEvent(Action<DrawArmoVehicle> ev)
{
if (EventAddTank == null)
{
EventAddTank = ev;
}
else
{
EventAddTank += ev;
}
}
// Передаем информацию при нажатии на Label
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
// Проверка получаемой информации (ее типа на соответствие требуемому)
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
// Действия при приеме перетаскиваемой информации
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelArmoVehicle":
_tank = new DrawArmoVehicle((int)numericSpeed.Value, (int)numericWeight.Value, Color.White, pictureBox.Width, pictureBox.Height);
break;
case "labelTank":
_tank = new DrawTank((int)numericSpeed.Value, (int)numericWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked, checkBoxCaterpillar.Checked, checkBoxTower.Checked, pictureBox.Width, pictureBox.Height);
break;
}
labelColor.BackColor = defaultColor;
labelAdditionalColor.BackColor = defaultColor;
DrawingTank();
}
// Добавление танка
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddTank?.Invoke(_tank);
Close();
}
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_tank == null)
return;
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
switch (((Label)sender).Name)
{
case "labelColor":
_tank.Tank.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (!(_tank is DrawTank))
return;
(_tank.Tank as EntityTank).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawingTank();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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

@ -11,7 +11,7 @@ namespace Tank
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormTanksCollections());
Application.Run(new CollectionsFrame());
}
}
}

View File

@ -9,39 +9,32 @@ namespace Tank
{
internal class SetGeneric<T> where T : class
{
// Список объектов, которые храним и их количество
private readonly List<T?> _places;
public int Count => _places.Count;
// Максимальное количество объектов
private readonly int _maxCount;
// Конструктор
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(_maxCount);
}
// Добавление объекта в набор
public bool Insert(T tank)
public bool Insert(T car)
{
return Insert(tank, 0);
return Insert(car, 0);
}
// Добавление на конкретную позицию
public bool Insert(T tank, int position)
public bool Insert(T car, int position)
{
if (position < 0 || position >= _maxCount)
return false;
if (Count >= _maxCount)
return false;
_places.Insert(0, tank);
_places.Insert(0, car);
return true;
}
// Удаление объекта из набора с конкретной позиции
public bool Remove(int position)
{
if (position < 0 || position > _maxCount)
@ -51,8 +44,6 @@ namespace Tank
_places.RemoveAt(position);
return true;
}
// Получение объекта из набора по позиции
public T? this[int position]
{
get
@ -69,17 +60,18 @@ namespace Tank
}
}
// Проход по списку
public IEnumerable<T?> GetTanks(int? maxTanks = null)
public IEnumerable<T?> GetCars(int? maxCars = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxTanks.HasValue && i == maxTanks.Value)
if (maxCars.HasValue && i == maxCars.Value)
{
yield break;
}
}
}
}
}

View File

@ -95,15 +95,18 @@ namespace Tank.Generics
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int i = 0;
foreach(var tank in _collection.GetTanks())
foreach(var tank in _collection.GetCars())
{
if (tank != null)
{
tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank._pictureWidth = _pictureWidth;
tank._pictureHeight = _pictureHeight;
tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank.DrawTransport(g);
}
i++;
}
}
}
}
}

View File

@ -11,37 +11,28 @@ namespace Tank
{
internal class TanksGenericStorage
{
// Словарь
readonly Dictionary<string, TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>> _tankStorages;
// Возвращение списка названий наборов
public List<string> Keys => _tankStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
// Конструктор
public TanksGenericStorage(int pictureWidth, int pictureHeight)
{
_tankStorages = new Dictionary<string, TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
// Добавление набора
public void AddSet(string name)
{
if (_tankStorages.ContainsKey(name)) return;
_tankStorages[name] = new TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>(_pictureWidth, _pictureHeight);
}
// Удаление набора
public void DelSet(string name)
{
if (!_tankStorages.ContainsKey(name)) return;
_tankStorages.Remove(name);
}
// Доступ к набору
public TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>?
this[string ind]
{
@ -52,4 +43,4 @@ namespace Tank
}
}
}
}
}