Готовая лаба №5

This commit is contained in:
Софья Якобчук 2023-12-02 12:34:12 +04:00
parent 928234337a
commit 799d4b1057
6 changed files with 616 additions and 4 deletions

View File

@ -30,6 +30,10 @@ namespace Sailboat.Entities
/// Шаг перемещения лодки
/// </summary>
public double Step => (double)Speed * 100 / Weight;
public void ChangeColor(Color color)
{
BodyColor = color;
}
/// <summary>
/// Конструктор с параметрами

View File

@ -25,6 +25,10 @@ namespace Sailboat.Entities
/// Признак (опция) наличия паруса
/// </summary>
public bool Sail { get; private set; }
public void ChangeAddColor(Color color)
{
AdditionalColor = color;
}
/// <summary>
/// Инициализация полей объекта-класса парусной лодки

View File

@ -56,10 +56,11 @@ namespace Sailboat
{
return;
}
FormSailboat form = new();
if (form.ShowDialog() == DialogResult.OK)
FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
form.Show();
Action<DrawingBoat>? boatDelegate = new((plane) =>
{
if (obj + form.SelectedBoat)
if (obj + plane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
@ -68,7 +69,8 @@ namespace Sailboat
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
form.AddEvent(boatDelegate);
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)

View File

@ -0,0 +1,352 @@
namespace Sailboat
{
partial class FormBoatConfig
{
/// <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()
{
groupBoxParameters = new GroupBox();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
groupBoxColors = new GroupBox();
panelGray = new Panel();
panelBlack = new Panel();
panelPurple = new Panel();
panelWhite = new Panel();
panelRed = new Panel();
panelBlue = new Panel();
panelYellow = new Panel();
panelGreen = new Panel();
checkBoxSail = new CheckBox();
checkBoxHull = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
labelWeight = new Label();
labelSpeed = new Label();
pictureBoxObject = new PictureBox();
PanelObject = new Panel();
labelAddColor = new Label();
labelColor = new Label();
buttonOk = new Button();
buttonCancel = new Button();
groupBoxParameters.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
PanelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxParameters
//
groupBoxParameters.Controls.Add(labelModifiedObject);
groupBoxParameters.Controls.Add(labelSimpleObject);
groupBoxParameters.Controls.Add(groupBoxColors);
groupBoxParameters.Controls.Add(checkBoxSail);
groupBoxParameters.Controls.Add(checkBoxHull);
groupBoxParameters.Controls.Add(numericUpDownWeight);
groupBoxParameters.Controls.Add(numericUpDownSpeed);
groupBoxParameters.Controls.Add(labelWeight);
groupBoxParameters.Controls.Add(labelSpeed);
groupBoxParameters.Location = new Point(12, 0);
groupBoxParameters.Name = "groupBoxParameters";
groupBoxParameters.Size = new Size(620, 283);
groupBoxParameters.TabIndex = 0;
groupBoxParameters.TabStop = false;
groupBoxParameters.Text = "Параметры";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(484, 219);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(109, 29);
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.MouseDown += LableObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(375, 219);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(72, 29);
labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой";
labelSimpleObject.MouseDown += LableObject_MouseDown;
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Location = new Point(332, 35);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(282, 172);
groupBoxColors.TabIndex = 6;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
//
// panelGray
//
panelGray.BackColor = Color.Silver;
panelGray.Location = new Point(91, 102);
panelGray.Name = "panelGray";
panelGray.Size = new Size(40, 40);
panelGray.TabIndex = 0;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(156, 102);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(40, 40);
panelBlack.TabIndex = 0;
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(225, 102);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(40, 40);
panelPurple.TabIndex = 0;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(19, 102);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(40, 40);
panelWhite.TabIndex = 15;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(19, 34);
panelRed.Name = "panelRed";
panelRed.Size = new Size(40, 40);
panelRed.TabIndex = 0;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(156, 34);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(40, 40);
panelBlue.TabIndex = 14;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(225, 34);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(40, 40);
panelYellow.TabIndex = 0;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(89, 34);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(40, 40);
panelGreen.TabIndex = 0;
//
// checkBoxSail
//
checkBoxSail.AutoSize = true;
checkBoxSail.Location = new Point(17, 203);
checkBoxSail.Name = "checkBoxSail";
checkBoxSail.Size = new Size(206, 24);
checkBoxSail.TabIndex = 5;
checkBoxSail.Text = "Признак наличия паруса";
checkBoxSail.UseVisualStyleBackColor = true;
//
// checkBoxHull
//
checkBoxHull.AutoSize = true;
checkBoxHull.Location = new Point(17, 173);
checkBoxHull.Name = "checkBoxHull";
checkBoxHull.Size = new Size(299, 24);
checkBoxHull.TabIndex = 4;
checkBoxHull.Text = "Признак наличия усиленного корпуса";
checkBoxHull.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(137, 112);
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(150, 27);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(137, 71);
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(150, 27);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(42, 114);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(36, 20);
labelWeight.TabIndex = 1;
labelWeight.Text = "Вес:";
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(42, 73);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(76, 20);
labelSpeed.TabIndex = 0;
labelSpeed.Text = "Скорость:";
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(14, 37);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(213, 191);
pictureBoxObject.TabIndex = 9;
pictureBoxObject.TabStop = false;
//
// PanelObject
//
PanelObject.AllowDrop = true;
PanelObject.Controls.Add(labelAddColor);
PanelObject.Controls.Add(labelColor);
PanelObject.Controls.Add(pictureBoxObject);
PanelObject.Location = new Point(638, 12);
PanelObject.Name = "PanelObject";
PanelObject.Size = new Size(239, 236);
PanelObject.TabIndex = 9;
PanelObject.DragDrop += PanelObject_DragDrop;
PanelObject.DragEnter += PanelObject_DragEnter;
//
// labelAddColor
//
labelAddColor.AllowDrop = true;
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
labelAddColor.Location = new Point(133, 9);
labelAddColor.Name = "labelAddColor";
labelAddColor.Size = new Size(86, 25);
labelAddColor.TabIndex = 11;
labelAddColor.Text = "Доп. цвет";
labelAddColor.DragDrop += addColorLabel_DragDrop;
labelAddColor.DragEnter += LabelColor_DragEnter;
//
// labelColor
//
labelColor.AllowDrop = true;
labelColor.BorderStyle = BorderStyle.FixedSingle;
labelColor.Location = new Point(41, 9);
labelColor.Name = "labelColor";
labelColor.Size = new Size(48, 25);
labelColor.TabIndex = 10;
labelColor.Text = "Цвет";
labelColor.DragDrop += LabelColor_DragDrop;
labelColor.DragEnter += LabelColor_DragEnter;
//
// buttonOk
//
buttonOk.Location = new Point(652, 254);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(94, 29);
buttonOk.TabIndex = 12;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(763, 254);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 13;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormBoatConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(887, 298);
Controls.Add(buttonOk);
Controls.Add(buttonCancel);
Controls.Add(PanelObject);
Controls.Add(groupBoxParameters);
Name = "FormBoatConfig";
Text = "Создание объекта";
groupBoxParameters.ResumeLayout(false);
groupBoxParameters.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 groupBoxParameters;
private CheckBox checkBoxSail;
private CheckBox checkBoxHull;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private GroupBox groupBoxColors;
private Label labelModifiedObject;
private Label labelSimpleObject;
private PictureBox pictureBoxObject;
private Panel PanelObject;
private Label labelAddColor;
private Label labelColor;
private Button buttonOk;
private Button buttonCancel;
private Panel panelGray;
private Panel panelBlack;
private Panel panelPurple;
private Panel panelWhite;
private Panel panelRed;
private Panel panelBlue;
private Panel panelYellow;
private Panel panelGreen;
}
}

View File

@ -0,0 +1,130 @@
using Sailboat.DrawingObjects;
using Sailboat.Entities;
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 Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat? _boat = null;
private event Action<DrawingBoat>? EventAddBoat;
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
public FormBoatConfig(int pictureWidth, int pictureHeight)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
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();
}
private void DrawBoat()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.SetPosition(5, 5);
_boat?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
internal void AddEvent(Action<DrawingBoat> ev)
{
if (EventAddBoat == null)
{
EventAddBoat = ev;
}
else
{
EventAddBoat += ev;
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LableObject_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":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
break;
case "labelModifiedObject":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
checkBoxSail.Checked, _pictureWidth, _pictureHeight);
break;
}
DrawBoat();
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat?.EntityBoat == null)
return;
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
_boat.EntityBoat.ChangeColor(bodyColor);
DrawBoat();
}
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
{
if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
return;
((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
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 buttonOk_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
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>