5 лабораторная работа

This commit is contained in:
Almaz 2024-04-22 17:09:39 +04:00
parent cabdb41342
commit 719a219d96
10 changed files with 762 additions and 167 deletions

View File

@ -0,0 +1,6 @@
using ProjectCruiser.Drawings;
namespace ProjectCruiser;
public delegate void CruiserDelegate(DrawningCruiser cruiser);

View File

@ -17,12 +17,12 @@ public class DrawningMilitaryCruiser: DrawningCruiser
/// <param name="weigth">Вес крейсера</param> /// <param name="weigth">Вес крейсера</param>
/// <param name="bodyColor">Скорость</param> /// <param name="bodyColor">Скорость</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="rocketMine">Признак наличия обвеса</param>
/// <param name="armor">Признак наличия брони</param> /// <param name="helicopterPad">Признак наличия брони</param>
/// <param name="weapon">Признак наличия оружия</param> /// <param name="weapon">Признак наличия оружия</param>
public DrawningMilitaryCruiser(int speed, double weigth, Color bodyColor, Color additionalColor, bool bodyKit, bool armor, bool weapon): base(180, 70) public DrawningMilitaryCruiser(int speed, double weigth, Color bodyColor, Color additionalColor, bool rocketMine, bool helicopterPad): base(180, 70)
{ {
EntityCruiser = new EntityMilitaryCruiser(speed, weigth, bodyColor, additionalColor, bodyKit, armor, weapon); EntityCruiser = new EntityMilitaryCruiser(speed, weigth, bodyColor, additionalColor, rocketMine, helicopterPad);
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
@ -52,12 +52,18 @@ public class DrawningMilitaryCruiser: DrawningCruiser
//Взлетная полоса //Взлетная полоса
Brush additionalBrush = new SolidBrush(militaryCruiser.AdditionalColor); Brush additionalBrush = new SolidBrush(militaryCruiser.AdditionalColor);
if(militaryCruiser.HelicopterPad)
{
g.FillEllipse(additionalBrush, (int)(_startPosX + 100), (int)(_startPosY + 25), 20, 20); g.FillEllipse(additionalBrush, (int)(_startPosX + 100), (int)(_startPosY + 25), 20, 20);
g.DrawEllipse(pen, (int)(_startPosX + 100), (int)(_startPosY + 25), 20, 20); g.DrawEllipse(pen, (int)(_startPosX + 100), (int)(_startPosY + 25), 20, 20);
}
//Рокетная шахта //Рокетная шахта
if (militaryCruiser.RocketMine)
{
g.FillRectangle(additionalBrush, (int)(_startPosX + 70), (int)(_startPosY + 20), 20, 30); g.FillRectangle(additionalBrush, (int)(_startPosX + 70), (int)(_startPosY + 20), 20, 30);
g.FillRectangle(additionalBrush, (int)(_startPosX + 40), (int)(_startPosY + 27), 30, 15); g.FillRectangle(additionalBrush, (int)(_startPosX + 40), (int)(_startPosY + 27), 30, 15);
}
} }
} }

View File

@ -31,6 +31,15 @@ public class EntityCruiser
/// </summary> /// </summary>
public double Step => Speed * 100 / Weigth; public double Step => Speed * 100 / Weigth;
/// <summary>
/// Публичный сеттер для основного цвета
/// </summary>
/// <param name="bodyColor"></param>
public void SetBodyColor(Color bodyColor)
{
this.BodyColor = bodyColor;
}
/// <summary> /// <summary>
/// Конструктор сущности /// Конструктор сущности
/// </summary> /// </summary>

View File

@ -10,20 +10,20 @@
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
/// <summary> public void SetAdditionalColor(Color AdditionalColor)
/// Признак (опция) наличие обвеса {
/// </summary> this.AdditionalColor = AdditionalColor;
public bool BodyKit { get; private set; } }
/// <summary> /// <summary>
/// Признак (опция) брони /// Признак (опция) ракетная шахта
/// </summary> /// </summary>
public bool Armor { get; private set; } public bool RocketMine { get; private set; }
/// <summary> /// <summary>
/// Признак (опция) оружия /// Признак (опция) площадка под вертолет
/// </summary> /// </summary>
public bool Weapon { get; private set; } public bool HelicopterPad { get; private set; }
/// <summary> /// <summary>
/// Инициализация полей объекта класса крейсера /// Инициализация полей объекта класса крейсера
@ -32,18 +32,24 @@
/// <param name="weigth">Вес крейсера</param> /// <param name="weigth">Вес крейсера</param>
/// <param name="bodyColor">Скорость</param> /// <param name="bodyColor">Скорость</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param> /// <param name="rocketMine">Признак наличия рокетной шахты</param>
/// <param name="armor">Признак наличия брони</param> /// <param name="helicopterPad">Признак наличия площадки под вертолет</param>
/// <param name="weapon">Признак наличия оружия</param> public EntityMilitaryCruiser(
public EntityMilitaryCruiser(int speed, double weigth, Color bodyColor, Color additionalColor, bool bodyKit, bool armor, bool weapon): base(speed, weigth, bodyColor) int speed,
double weigth,
Color bodyColor,
Color additionalColor,
bool rocketMine,
bool helicopterPad
)
: base(speed, weigth, bodyColor)
{ {
Speed = speed; Speed = speed;
Weigth = weigth; Weigth = weigth;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
BodyKit = bodyKit; RocketMine = rocketMine;
Armor = armor; HelicopterPad = helicopterPad;
Weapon = weapon;
} }
} }
} }

View File

@ -62,7 +62,6 @@ namespace ProjectCruiser
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2))); Convert.ToBoolean(random.Next(0, 2)));
break; break;

View File

@ -29,6 +29,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonAddCruiser = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
buttonRemoveCruiser = new Button();
buttonGoToCheck = new Button();
buttonCreateCompany = new Button(); buttonCreateCompany = new Button();
panelStorage = new Panel(); panelStorage = new Panel();
buttonCollectionDel = new Button(); buttonCollectionDel = new Button();
@ -38,19 +44,12 @@
radioButtonMassive = new RadioButton(); radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox(); textBoxCollectionName = new TextBox();
labelCollectionName = new Label(); labelCollectionName = new Label();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveCruiser = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddMilitaryCruiser = new Button();
buttonAddCruiser = new Button();
comboBoxSelectorCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout(); panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
@ -67,6 +66,73 @@
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddCruiser);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveCruiser);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 431);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(244, 294);
panelCompanyTools.TabIndex = 9;
//
// buttonAddCruiser
//
buttonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCruiser.Location = new Point(9, 3);
buttonAddCruiser.Name = "buttonAddCruiser";
buttonAddCruiser.Size = new Size(226, 40);
buttonAddCruiser.TabIndex = 1;
buttonAddCruiser.Text = "Добавление крейсера";
buttonAddCruiser.UseVisualStyleBackColor = true;
buttonAddCruiser.Click += ButtonAddCruiser_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(9, 109);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(232, 27);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(9, 234);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(226, 40);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonRemoveCruiser
//
buttonRemoveCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveCruiser.Location = new Point(9, 142);
buttonRemoveCruiser.Name = "buttonRemoveCruiser";
buttonRemoveCruiser.Size = new Size(226, 40);
buttonRemoveCruiser.TabIndex = 4;
buttonRemoveCruiser.Text = "Удаление крейсера";
buttonRemoveCruiser.UseVisualStyleBackColor = true;
buttonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(9, 188);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(226, 40);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать не тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonCreateCompany // buttonCreateCompany
// //
buttonCreateCompany.Location = new Point(12, 396); buttonCreateCompany.Location = new Point(12, 396);
@ -158,70 +224,6 @@
labelCollectionName.TabIndex = 0; labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:"; labelCollectionName.Text = "Название коллекции:";
// //
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(9, 234);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(226, 40);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(9, 188);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(226, 40);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать не тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveCruiser
//
buttonRemoveCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveCruiser.Location = new Point(9, 142);
buttonRemoveCruiser.Name = "buttonRemoveCruiser";
buttonRemoveCruiser.Size = new Size(226, 40);
buttonRemoveCruiser.TabIndex = 4;
buttonRemoveCruiser.Text = "Удаление крейсера";
buttonRemoveCruiser.UseVisualStyleBackColor = true;
buttonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(9, 109);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(232, 27);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddMilitaryCruiser
//
buttonAddMilitaryCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMilitaryCruiser.Location = new Point(9, 49);
buttonAddMilitaryCruiser.Name = "buttonAddMilitaryCruiser";
buttonAddMilitaryCruiser.Size = new Size(226, 54);
buttonAddMilitaryCruiser.TabIndex = 2;
buttonAddMilitaryCruiser.Text = "Добавление военного крейсера";
buttonAddMilitaryCruiser.UseVisualStyleBackColor = true;
buttonAddMilitaryCruiser.Click += ButtonAddMilitaryCruiser_Click;
//
// buttonAddCruiser
//
buttonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCruiser.Location = new Point(9, 3);
buttonAddCruiser.Name = "buttonAddCruiser";
buttonAddCruiser.Size = new Size(226, 40);
buttonAddCruiser.TabIndex = 1;
buttonAddCruiser.Text = "Добавление крейсера";
buttonAddCruiser.UseVisualStyleBackColor = true;
buttonAddCruiser.Click += ButtonAddCruiser_Click;
//
// comboBoxSelectorCompany // comboBoxSelectorCompany
// //
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@ -243,21 +245,6 @@
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddCruiser);
panelCompanyTools.Controls.Add(buttonAddMilitaryCruiser);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveCruiser);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 431);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(244, 294);
panelCompanyTools.TabIndex = 9;
//
// FormCruiserCollection // FormCruiserCollection
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
@ -268,11 +255,11 @@
Name = "FormCruiserCollection"; Name = "FormCruiserCollection";
Text = "Коллекция Крейсеров"; Text = "Коллекция Крейсеров";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false); panelStorage.ResumeLayout(false);
panelStorage.PerformLayout(); panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
@ -283,7 +270,6 @@
private ComboBox comboBoxSelectorCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonRemoveCruiser; private Button buttonRemoveCruiser;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddMilitaryCruiser;
private PictureBox pictureBox; private PictureBox pictureBox;
private Button buttonRefresh; private Button buttonRefresh;
private Button buttonGoToCheck; private Button buttonGoToCheck;

View File

@ -33,40 +33,17 @@ public partial class FormCruiserCollection : Form
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
} }
private void ButtonAddCruiser_Click(object sender, EventArgs e)
private void CreateObject(string type)
{ {
FormCruiserConfig form = new();
if (_company == null) form.AddEvent(SetCruiser);
{ form.Show();
return;
} }
DrawningCruiser drawningCruiser; private void SetCruiser(DrawningCruiser cruiser)
Random random = new();
switch (type)
{ {
case nameof(DrawningCruiser): if (_company == null || cruiser == null) { return; }
if (_company + cruiser)
drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), SetColor(random));
break;
case nameof(DrawningMilitaryCruiser):
drawningCruiser = new DrawningMilitaryCruiser(random.Next(100, 300),
random.Next(1000, 3000),
SetColor(random),
SetColor(random),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningCruiser)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
@ -77,27 +54,6 @@ public partial class FormCruiserCollection : Form
} }
} }
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
private static Color SetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
private void ButtonAddCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser));
private void ButtonAddMilitaryCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryCruiser));
private void ButtonRemoveCruiser_Click(object sender, EventArgs e) private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)

View File

@ -0,0 +1,357 @@
namespace ProjectCruiser
{
partial class FormCruiserConfig
{
/// <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()
{
groupBoxConfig = new GroupBox();
groupBoxColors = new GroupBox();
panelPurple = new Panel();
panelBlack = new Panel();
panelGray = new Panel();
panelWhite = new Panel();
panelYellow = new Panel();
panelBlue = new Panel();
panelGreen = new Panel();
panelRed = new Panel();
checkBoxHelicopterPad = new CheckBox();
checkBoxRocketMine = new CheckBox();
numericUpDownWeight = new NumericUpDown();
labelWeight = new Label();
numericUpDownSpeed = new NumericUpDown();
labelSpeed = new Label();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
pictureBoxObject = new PictureBox();
buttonAdd = new Button();
buttonCancel = new Button();
panelObject = new Panel();
labelAdditionalColor = new Label();
labelBodyColor = new Label();
groupBoxConfig.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
panelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxConfig
//
groupBoxConfig.Controls.Add(groupBoxColors);
groupBoxConfig.Controls.Add(checkBoxHelicopterPad);
groupBoxConfig.Controls.Add(checkBoxRocketMine);
groupBoxConfig.Controls.Add(numericUpDownWeight);
groupBoxConfig.Controls.Add(labelWeight);
groupBoxConfig.Controls.Add(numericUpDownSpeed);
groupBoxConfig.Controls.Add(labelSpeed);
groupBoxConfig.Controls.Add(labelModifiedObject);
groupBoxConfig.Controls.Add(labelSimpleObject);
groupBoxConfig.Dock = DockStyle.Left;
groupBoxConfig.Location = new Point(0, 0);
groupBoxConfig.Name = "groupBoxConfig";
groupBoxConfig.Size = new Size(595, 261);
groupBoxConfig.TabIndex = 0;
groupBoxConfig.TabStop = false;
groupBoxConfig.Text = "Параметры";
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Location = new Point(297, 30);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(256, 132);
groupBoxColors.TabIndex = 8;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(195, 79);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(36, 34);
panelPurple.TabIndex = 2;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(131, 79);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(36, 34);
panelBlack.TabIndex = 2;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(71, 79);
panelGray.Name = "panelGray";
panelGray.Size = new Size(36, 34);
panelGray.TabIndex = 2;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(11, 79);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(36, 34);
panelWhite.TabIndex = 2;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(195, 26);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(36, 34);
panelYellow.TabIndex = 1;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(131, 26);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(36, 34);
panelBlue.TabIndex = 1;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(71, 26);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(36, 34);
panelGreen.TabIndex = 1;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(11, 26);
panelRed.Name = "panelRed";
panelRed.Size = new Size(36, 34);
panelRed.TabIndex = 0;
//
// checkBoxHelicopterPad
//
checkBoxHelicopterPad.AutoSize = true;
checkBoxHelicopterPad.Location = new Point(12, 149);
checkBoxHelicopterPad.Name = "checkBoxHelicopterPad";
checkBoxHelicopterPad.Size = new Size(260, 24);
checkBoxHelicopterPad.TabIndex = 7;
checkBoxHelicopterPad.Text = "Признак площадка под вертолет";
checkBoxHelicopterPad.UseVisualStyleBackColor = true;
//
// checkBoxRocketMine
//
checkBoxRocketMine.AutoSize = true;
checkBoxRocketMine.Location = new Point(12, 119);
checkBoxRocketMine.Name = "checkBoxRocketMine";
checkBoxRocketMine.Size = new Size(203, 24);
checkBoxRocketMine.TabIndex = 6;
checkBoxRocketMine.Text = "Признак ракетная шахта";
checkBoxRocketMine.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(94, 76);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(121, 27);
numericUpDownWeight.TabIndex = 5;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(12, 78);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(36, 20);
labelWeight.TabIndex = 4;
labelWeight.Text = "Вес:";
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(94, 36);
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(121, 27);
numericUpDownSpeed.TabIndex = 3;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(12, 38);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(76, 20);
labelSpeed.TabIndex = 2;
labelSpeed.Text = "Скорость:";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(428, 206);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(127, 35);
labelModifiedObject.TabIndex = 1;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(274, 206);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(127, 35);
labelSimpleObject.TabIndex = 0;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(22, 66);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(211, 113);
pictureBoxObject.TabIndex = 1;
pictureBoxObject.TabStop = false;
//
// buttonAdd
//
buttonAdd.Location = new Point(623, 206);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(740, 206);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// panelObject
//
panelObject.AllowDrop = true;
panelObject.Controls.Add(labelAdditionalColor);
panelObject.Controls.Add(labelBodyColor);
panelObject.Controls.Add(pictureBoxObject);
panelObject.Location = new Point(601, 12);
panelObject.Name = "panelObject";
panelObject.Size = new Size(257, 188);
panelObject.TabIndex = 4;
panelObject.DragDrop += PanelObjects_DragDrop;
panelObject.DragEnter += PanelObjects_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(130, 11);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(103, 35);
labelAdditionalColor.TabIndex = 3;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += LabelOptionalColor_DragDrop;
labelAdditionalColor.DragEnter += LabelOptionalColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(22, 11);
labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(103, 35);
labelBodyColor.TabIndex = 2;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += LabelBodyColor_DragDrop;
labelBodyColor.DragEnter += LabelBodyColor_DragEnter;
//
// FormCruiserConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(870, 261);
Controls.Add(panelObject);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(groupBoxConfig);
Name = "FormCruiserConfig";
Text = "Создание объекта";
groupBoxConfig.ResumeLayout(false);
groupBoxConfig.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
panelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private Label labelSimpleObject;
private Label labelWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelSpeed;
private Label labelModifiedObject;
private NumericUpDown numericUpDownWeight;
private CheckBox checkBoxRocketMine;
private CheckBox checkBoxHelicopterPad;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
private Panel panelObject;
private Label labelAdditionalColor;
private Label labelBodyColor;
}
}

View File

@ -0,0 +1,150 @@
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 ProjectCruiser.Drawings;
using ProjectCruiser.Entities;
namespace ProjectCruiser;
public partial class FormCruiserConfig : Form
{
private DrawningCruiser _cruiser;
/// <summary>
/// Событие для передачи объекта
/// </summary>
private event CruiserDelegate _cruiserDelegate;
public FormCruiserConfig()
{
InitializeComponent();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
panelYellow.MouseDown += Panel_MouseDown;
panelWhite.MouseDown += Panel_MouseDown;
panelGray.MouseDown += Panel_MouseDown;
panelBlack.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="cruiserDelegate"></param>
public void AddEvent(CruiserDelegate cruiserDelegate)
{
_cruiserDelegate += cruiserDelegate;
}
// <summary>
/// Прорисовка объекта
/// </summary>
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_cruiser?.SetPictireSize(pictureBoxObject.Width,
pictureBoxObject.Height);
_cruiser?.SetPosition(15, 15);
_cruiser?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObjects_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
private void PanelObjects_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
{
case "labelSimpleObject":
_cruiser = new DrawningCruiser(
(int)numericUpDownSpeed.Value,
(double)numericUpDownWeight.Value,
Color.White
);
break;
case "labelModifiedObject":
Random random = new Random();
_cruiser = new DrawningMilitaryCruiser(
(int)numericUpDownSpeed.Value,
(double)numericUpDownWeight.Value,
Color.White,
Color.Black,
checkBoxRocketMine.Checked,
checkBoxHelicopterPad.Checked);
break;
}
DrawObject();
}
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
// TODO реализовать выбор цвета
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Передача объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_cruiser != null)
{
_cruiserDelegate?.Invoke(_cruiser);
Close();
}
}
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser != null)
{
_cruiser.EntityCruiser.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void LabelBodyColor_DragEnter(object? sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
private void LabelOptionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser.EntityCruiser is EntityMilitaryCruiser militaryCruiser)
{
militaryCruiser.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void LabelOptionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_cruiser is DrawningMilitaryCruiser)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
}
}

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>