PIbd-21. Makarov D.V. Lab work 05 #5

Closed
DavidMakarov wants to merge 1 commits from lab5 into lab4
6 changed files with 643 additions and 12 deletions
Showing only changes of commit 05f1d8701d - Show all commits

View File

@ -4,7 +4,7 @@
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
public double Step => (double)Speed * 100 / Weight;
public AirplaneEntity(int speed, double weight, Color bodyColor)

View File

@ -2,7 +2,7 @@
{
public class AirplaneWithRadarEntity : AirplaneEntity
{
public Color AdditColor { get; private set; }
public Color AdditColor { get; set; }
public bool RadarOnBoard { get; private set; }
public bool AdditFuelPod { get; private set; }

View File

@ -67,19 +67,28 @@ namespace AirplaneWithRadar
{
return;
}
PlaneVisual form = new();
if (form.ShowDialog() == DialogResult.OK)
var formAirplaneConfig = new FormAirplaneConfig();
formAirplaneConfig.AddEvent(airplane =>
{
if (!(obj + form.SelectedAirplane == -1))
if (listBoxStorages.SelectedIndex != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowAirplanes();
var obj = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
if (obj != null)
{
if (obj + airplane != 1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
formAirplaneConfig.Show();
}
private void ButtonDeleteAirplane_Click(object sender, EventArgs e)

View File

@ -0,0 +1,367 @@
namespace AirplaneWithRadar
{
partial class FormAirplaneConfig
{
/// <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()
{
groupBox1 = new GroupBox();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
groupBox2 = 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();
checkBoxAdditFuelPod = new CheckBox();
checkBoxRadar = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
label2 = new Label();
label1 = new Label();
panelColor = new Panel();
labelAdditColor = new Label();
labelMainColor = new Label();
pictureBoxObject = new PictureBox();
buttonOk = new Button();
buttonCancel = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
panelColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(labelModifiedObject);
groupBox1.Controls.Add(labelSimpleObject);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(checkBoxAdditFuelPod);
groupBox1.Controls.Add(checkBoxRadar);
groupBox1.Controls.Add(numericUpDownWeight);
groupBox1.Controls.Add(numericUpDownSpeed);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(10, 11);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(428, 427);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Параметры";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(282, 197);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(91, 41);
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += labelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(174, 197);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(91, 41);
labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += labelObject_MouseDown;
//
// groupBox2
//
groupBox2.Controls.Add(panelPurple);
groupBox2.Controls.Add(panelBlack);
groupBox2.Controls.Add(panelGray);
groupBox2.Controls.Add(panelWhite);
groupBox2.Controls.Add(panelYellow);
groupBox2.Controls.Add(panelBlue);
groupBox2.Controls.Add(panelGreen);
groupBox2.Controls.Add(panelRed);
groupBox2.Location = new Point(140, 27);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(274, 150);
groupBox2.TabIndex = 6;
groupBox2.TabStop = false;
groupBox2.Text = "Цвет";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(209, 86);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(47, 48);
panelPurple.TabIndex = 4;
panelPurple.MouseClick += PanelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(142, 86);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(47, 48);
panelBlack.TabIndex = 3;
panelBlack.MouseClick += PanelColor_MouseDown;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(78, 86);
panelGray.Name = "panelGray";
panelGray.Size = new Size(47, 48);
panelGray.TabIndex = 2;
panelGray.MouseClick += PanelColor_MouseDown;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(13, 86);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(47, 48);
panelWhite.TabIndex = 1;
panelWhite.MouseClick += PanelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(209, 24);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(47, 48);
panelYellow.TabIndex = 3;
panelYellow.MouseClick += PanelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(142, 24);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(47, 48);
panelBlue.TabIndex = 2;
panelBlue.MouseClick += PanelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(78, 24);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(47, 48);
panelGreen.TabIndex = 1;
panelGreen.MouseClick += PanelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(13, 24);
panelRed.Name = "panelRed";
panelRed.Size = new Size(47, 48);
panelRed.TabIndex = 0;
panelRed.MouseClick += PanelColor_MouseDown;
//
// checkBoxAdditFuelPod
//
checkBoxAdditFuelPod.AutoSize = true;
checkBoxAdditFuelPod.Location = new Point(19, 167);
checkBoxAdditFuelPod.Name = "checkBoxAdditFuelPod";
checkBoxAdditFuelPod.Size = new Size(97, 19);
checkBoxAdditFuelPod.TabIndex = 5;
checkBoxAdditFuelPod.Text = "Есть доп. бак";
checkBoxAdditFuelPod.UseVisualStyleBackColor = true;
//
// checkBoxRadar
//
checkBoxRadar.AutoSize = true;
checkBoxRadar.Location = new Point(19, 142);
checkBoxRadar.Name = "checkBoxRadar";
checkBoxRadar.Size = new Size(84, 19);
checkBoxRadar.TabIndex = 4;
checkBoxRadar.Text = "Есть радар";
checkBoxRadar.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(19, 89);
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(65, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(19, 45);
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(65, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(15, 71);
label2.Name = "label2";
label2.Size = new Size(26, 15);
label2.TabIndex = 1;
label2.Text = "Вес";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(15, 27);
label1.Name = "label1";
label1.Size = new Size(59, 15);
label1.TabIndex = 0;
label1.Text = "Скорость";
//
// panelColor
//
panelColor.AllowDrop = true;
panelColor.Controls.Add(labelAdditColor);
panelColor.Controls.Add(labelMainColor);
panelColor.Controls.Add(pictureBoxObject);
panelColor.Location = new Point(444, 11);
panelColor.Name = "panelColor";
panelColor.Size = new Size(344, 344);
panelColor.TabIndex = 1;
panelColor.DragDrop += PanelObject_DragDrop;
panelColor.DragEnter += PanelObject_DragEnter;
panelColor.MouseDown += PanelColor_MouseDown;
//
// labelAdditColor
//
labelAdditColor.AllowDrop = true;
labelAdditColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditColor.Location = new Point(193, 21);
labelAdditColor.Name = "labelAdditColor";
labelAdditColor.Size = new Size(131, 33);
labelAdditColor.TabIndex = 10;
labelAdditColor.Text = "Доп. цвет";
labelAdditColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditColor.DragDrop += labelAdditColor_DragDrop;
labelAdditColor.DragEnter += labelColor_DragEnter;
labelAdditColor.MouseDown += labelObject_MouseDown;
//
// labelMainColor
//
labelMainColor.AllowDrop = true;
labelMainColor.BorderStyle = BorderStyle.FixedSingle;
labelMainColor.Location = new Point(26, 21);
labelMainColor.Name = "labelMainColor";
labelMainColor.Size = new Size(128, 33);
labelMainColor.TabIndex = 9;
labelMainColor.Text = "Цвет";
labelMainColor.TextAlign = ContentAlignment.MiddleCenter;
labelMainColor.DragDrop += labelMainColor_DragDrop;
labelMainColor.DragEnter += labelColor_DragEnter;
labelMainColor.MouseDown += labelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(26, 65);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(298, 264);
pictureBoxObject.TabIndex = 11;
pictureBoxObject.TabStop = false;
//
// buttonOk
//
buttonOk.Location = new Point(470, 379);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(128, 44);
buttonOk.TabIndex = 2;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(623, 379);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(128, 44);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirplaneConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCancel);
Controls.Add(buttonOk);
Controls.Add(panelColor);
Controls.Add(groupBox1);
Name = "FormAirplaneConfig";
Text = "FormAirplaneConfig";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
panelColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Label label1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private GroupBox groupBox2;
private CheckBox checkBoxAdditFuelPod;
private CheckBox checkBoxRadar;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Panel panelColor;
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 Label labelAdditColor;
private Label labelMainColor;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,135 @@
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.Entities;
namespace AirplaneWithRadar
{
public partial class FormAirplaneConfig : Form
{
PaintAirplane? airplane = null;
private event Action<PaintAirplane> EventAddAirplane;
public FormAirplaneConfig()
{
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 += (sender, e) => Close();
}
public void DrawAirplane()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
airplane?.SetPosition(5, 5);
airplane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(Action<PaintAirplane> ev)
{
if (EventAddAirplane == null)
{
EventAddAirplane = new Action<PaintAirplane>(ev);
}
else
{
EventAddAirplane += ev;
}
}
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 "labelSimpleObject":
airplane = new PaintAirplane((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
airplane = new PaintAirplaneWithRadar((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRadar.Checked,
checkBoxAdditFuelPod.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawAirplane();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity entityAirplane)
{
labelAdditColor.AllowDrop = true;
}
else
{
labelAdditColor.AllowDrop = false;
}
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
{
if (airplane != null)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
airplane.AirplaneEntity.BodyColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirplane();
}
}
private void labelAdditColor_DragDrop(object sender, DragEventArgs e)
{
if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity airplaneWithRadarEntity)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
airplaneWithRadarEntity.AdditColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirplane();
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void buttonOk_Click(object sender, EventArgs e)
{
EventAddAirplane?.Invoke(airplane);
Close();
}
}
}

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>