Сделал лабораторную 5

This commit is contained in:
Никита Волков 2023-12-12 01:28:34 +04:00
parent fbad9188bf
commit de23a30c02
12 changed files with 713 additions and 37 deletions

View File

@ -15,11 +15,11 @@ namespace Bulldozer.DrawingObjects
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
private int _pictureWidth; public int _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
private int _pictureHeight; public int _pictureHeight;
/// <summary> /// <summary>
/// Координата прорисовки по оси X /// Координата прорисовки по оси X
/// </summary> /// </summary>
@ -64,11 +64,16 @@ namespace Bulldozer.DrawingObjects
/// <param name="carHeight">Высота прорисовки бульдозера</param> /// <param name="carHeight">Высота прорисовки бульдозера</param>
protected DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int bulldozerWidth, int bulldozerHeight) protected DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int bulldozerWidth, int bulldozerHeight)
{ {
_pictureWidth = width; if (width < _bulldozerWidth || height < _bulldozerHeight)
_pictureHeight = height; {
_bulldozerWidth = bulldozerWidth; return;
_bulldozerHeight = bulldozerHeight; }
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
_pictureWidth = width;
_pictureHeight = height;
_bulldozerWidth = bulldozerWidth;
_bulldozerHeight = bulldozerHeight;
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
} }
/// <summary> /// <summary>
@ -133,7 +138,7 @@ namespace Bulldozer.DrawingObjects
/// Изменение направления перемещения /// Изменение направления перемещения
/// </summary> /// </summary>
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
public void MoveBulldozer(DirectionType direction) public void MoveTransport(DirectionType direction)
{ {
if (!CanMove(direction) || EntityBulldozer == null) if (!CanMove(direction) || EntityBulldozer == null)
{ {
@ -163,7 +168,7 @@ namespace Bulldozer.DrawingObjects
/// Прорисовка объекта /// Прорисовка объекта
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public virtual void DrawBulldozer(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (EntityBulldozer == null) if (EntityBulldozer == null)
{ {

View File

@ -25,19 +25,18 @@ namespace Bulldozer.DrawingObjects
EntityBulldozer = new EntityBulldozerUpgraded(speed, weight, bodyColor, additionalColor, dopColor, blade, ripper); EntityBulldozer = new EntityBulldozerUpgraded(speed, weight, bodyColor, additionalColor, dopColor, blade, ripper);
} }
} }
public override void DrawTransport(Graphics g)
public override void DrawBulldozer(Graphics g)
{ {
if (EntityBulldozer is not EntityBulldozerUpgraded upgradedBulldozer) if (EntityBulldozer is not EntityBulldozerUpgraded upgradedBulldozer)
{ {
return; return;
} }
Pen dopPen = new(upgradedBulldozer.DopColor);
Brush dopBrush = new SolidBrush(upgradedBulldozer.DopColor); Brush dopBrush = new SolidBrush(upgradedBulldozer.DopColor);
Pen dopPen = new Pen(upgradedBulldozer.DopColor);
/// <summary> /// <summary>
/// Отрисовка отвала бульдозера /// Отрисовка отвала бульдозера
/// </summary> /// </summary>
base.DrawBulldozer(g); base.DrawTransport(g);
if (upgradedBulldozer.Blade) if (upgradedBulldozer.Blade)
{ {
Point point1 = new Point(_startPosX + 8, _startPosY + 29); Point point1 = new Point(_startPosX + 8, _startPosY + 29);
@ -51,6 +50,7 @@ namespace Bulldozer.DrawingObjects
g.DrawRectangle(dopPen, _startPosX + 8, _startPosY + 29, 8, 8); // обводка основания отвала g.DrawRectangle(dopPen, _startPosX + 8, _startPosY + 29, 8, 8); // обводка основания отвала
g.DrawPolygon(dopPen, triangle); // обводка отвала g.DrawPolygon(dopPen, triangle); // обводка отвала
} }
/// <summary> /// <summary>
/// Отрисовка рыхлителя бульдозера /// Отрисовка рыхлителя бульдозера
/// </summary> /// </summary>

View File

@ -22,7 +22,6 @@ namespace Bulldozer.Entities
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public Color DopColor { get; private set; }
/// <summary> /// <summary>
/// Шаг перемещения бульдозера /// Шаг перемещения бульдозера
/// </summary> /// </summary>
@ -40,8 +39,10 @@ namespace Bulldozer.Entities
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
} }
public void SetBodyColor(Color bodyColor)
{
BodyColor = bodyColor;
}
} }
} }

View File

@ -10,6 +10,7 @@
/// Отвал бульдозера /// Отвал бульдозера
/// </summary> /// </summary>
public bool Blade { get; private set; } public bool Blade { get; private set; }
/// <summary> /// <summary>
/// Рыхлитель бульдозера /// Рыхлитель бульдозера
/// </summary> /// </summary>
@ -25,11 +26,16 @@
/// <param name="blade">Отвал бульдозера</param> /// <param name="blade">Отвал бульдозера</param>
/// <param name="ripper">Рыхлитель бульдозера</param> /// <param name="ripper">Рыхлитель бульдозера</param>
public EntityBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper) : public EntityBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper) :
base(speed, weight, bodyColor, additionalColor) base(speed, weight, bodyColor, additionalColor)
{ {
DopColor = dopColor; DopColor = dopColor;
Blade = blade; Blade = blade;
Ripper = ripper; Ripper = ripper;
} }
public void SetDopColor(Color dopColor)
{
DopColor = dopColor;
}
} }
} }

View File

@ -41,7 +41,7 @@ namespace Bulldozer
} }
Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingBulldozer.DrawBulldozer(gr); _drawingBulldozer.DrawTransport(gr);
pictureBoxBulldozer.Image = bmp; pictureBoxBulldozer.Image = bmp;
} }
@ -60,16 +60,16 @@ namespace Bulldozer
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
_drawingBulldozer.MoveBulldozer(DirectionType.Up); _drawingBulldozer.MoveTransport(DirectionType.Up);
break; break;
case "buttonDown": case "buttonDown":
_drawingBulldozer.MoveBulldozer(DirectionType.Down); _drawingBulldozer.MoveTransport(DirectionType.Down);
break; break;
case "buttonLeft": case "buttonLeft":
_drawingBulldozer.MoveBulldozer(DirectionType.Left); _drawingBulldozer.MoveTransport(DirectionType.Left);
break; break;
case "buttonRight": case "buttonRight":
_drawingBulldozer.MoveBulldozer(DirectionType.Right); _drawingBulldozer.MoveTransport(DirectionType.Right);
break; break;
} }
Draw(); Draw();

View File

@ -90,6 +90,7 @@ namespace Bulldozer
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void buttonAddBulldozer_Click(object sender, EventArgs e) private void buttonAddBulldozer_Click(object sender, EventArgs e)
{ {
if (listBoxBulldozerStorages.SelectedIndex == -1) if (listBoxBulldozerStorages.SelectedIndex == -1)
@ -97,27 +98,34 @@ namespace Bulldozer
MessageBox.Show("Выберите набор в списке.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите набор в списке.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
var formBulldozerConfig = new FormBulldozerConfig();
formBulldozerConfig.AddEvent(AddBulldozer);
formBulldozerConfig.Show();
}
private void AddBulldozer(DrawingBulldozer bulldozer)
{
bulldozer._pictureWidth = pictureBoxCollection.Width;
bulldozer._pictureHeight = pictureBoxCollection.Height;
if (listBoxBulldozerStorages.SelectedIndex == -1) return;
var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty]; var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null) if (obj == null)
{ {
MessageBox.Show("Выбранный набор не найден.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
FormBulldozer form = new(); if (obj + bulldozer > -1)
if (form.ShowDialog() == DialogResult.OK)
{ {
if (obj + form.SelectedBulldozer > -1) MessageBox.Show("Объект добавлен");
{ pictureBoxCollection.Image = obj.ShowBulldozers();
MessageBox.Show("Объект добавлен"); }
pictureBoxCollection.Image = obj.ShowBulldozers(); else
} {
else MessageBox.Show("Не удалось добавить объект");
{
MessageBox.Show("Не удалось добавить объект");
}
} }
} }
/// <summary> /// <summary>
/// Удаление объекта из набора /// Удаление объекта из набора
/// </summary> /// </summary>

View File

@ -0,0 +1,435 @@
namespace Bulldozer
{
partial class FormBulldozerConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBoxParameters = new System.Windows.Forms.GroupBox();
this.groupBoxMarks = new System.Windows.Forms.GroupBox();
this.checkBoxRipper = new System.Windows.Forms.CheckBox();
this.checkBoxBlade = new System.Windows.Forms.CheckBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelObject = new System.Windows.Forms.Panel();
this.labelAddColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxParameters.SuspendLayout();
this.groupBoxMarks.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelObject.SuspendLayout();
this.SuspendLayout();
//
// groupBoxParameters
//
this.groupBoxParameters.Controls.Add(this.groupBoxMarks);
this.groupBoxParameters.Controls.Add(this.labelModifiedObject);
this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
this.groupBoxParameters.Controls.Add(this.groupBoxColors);
this.groupBoxParameters.Controls.Add(this.numericUpDownWeight);
this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed);
this.groupBoxParameters.Controls.Add(this.labelWeight);
this.groupBoxParameters.Controls.Add(this.labelSpeed);
this.groupBoxParameters.Location = new System.Drawing.Point(10, 10);
this.groupBoxParameters.Margin = new System.Windows.Forms.Padding(2);
this.groupBoxParameters.Name = "groupBoxParameters";
this.groupBoxParameters.Padding = new System.Windows.Forms.Padding(2);
this.groupBoxParameters.Size = new System.Drawing.Size(586, 272);
this.groupBoxParameters.TabIndex = 0;
this.groupBoxParameters.TabStop = false;
this.groupBoxParameters.Text = "Параметры";
//
// groupBoxMarks
//
this.groupBoxMarks.Controls.Add(this.checkBoxRipper);
this.groupBoxMarks.Controls.Add(this.checkBoxBlade);
this.groupBoxMarks.Location = new System.Drawing.Point(24, 133);
this.groupBoxMarks.Name = "groupBoxMarks";
this.groupBoxMarks.Size = new System.Drawing.Size(250, 116);
this.groupBoxMarks.TabIndex = 9;
this.groupBoxMarks.TabStop = false;
this.groupBoxMarks.Text = "Признаки";
//
// checkBoxRipper
//
this.checkBoxRipper.AutoSize = true;
this.checkBoxRipper.Location = new System.Drawing.Point(17, 41);
this.checkBoxRipper.Margin = new System.Windows.Forms.Padding(2);
this.checkBoxRipper.Name = "checkBoxRipper";
this.checkBoxRipper.Size = new System.Drawing.Size(170, 24);
this.checkBoxRipper.TabIndex = 4;
this.checkBoxRipper.Text = "Наличие рыхлителя";
this.checkBoxRipper.UseVisualStyleBackColor = true;
//
// checkBoxBlade
//
this.checkBoxBlade.AutoSize = true;
this.checkBoxBlade.Location = new System.Drawing.Point(17, 74);
this.checkBoxBlade.Margin = new System.Windows.Forms.Padding(2);
this.checkBoxBlade.Name = "checkBoxBlade";
this.checkBoxBlade.Size = new System.Drawing.Size(143, 24);
this.checkBoxBlade.TabIndex = 5;
this.checkBoxBlade.Text = "Наличие отвала";
this.checkBoxBlade.UseVisualStyleBackColor = true;
//
// labelModifiedObject
//
this.labelModifiedObject.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(450, 180);
this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(107, 69);
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += labelObject_MouseDown;
//
// labelSimpleObject
//
this.labelSimpleObject.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(329, 180);
this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(102, 69);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += labelObject_MouseDown;
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(311, 16);
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(2);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(2);
this.groupBoxColors.Size = new System.Drawing.Size(259, 155);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
this.groupBoxColors.DragDrop += PanelObject_DragDrop;
this.groupBoxColors.DragEnter += PanelObject_DragEnter;
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(194, 90);
this.panelPurple.Margin = new System.Windows.Forms.Padding(2);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(43, 43);
this.panelPurple.TabIndex = 1;
this.panelPurple.MouseDown += panelColor_MouseDown;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(135, 90);
this.panelBlack.Margin = new System.Windows.Forms.Padding(2);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(43, 43);
this.panelBlack.TabIndex = 1;
this.panelBlack.MouseDown += panelColor_MouseDown;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(77, 90);
this.panelGray.Margin = new System.Windows.Forms.Padding(2);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(43, 43);
this.panelGray.TabIndex = 1;
this.panelGray.MouseDown += panelColor_MouseDown;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(18, 90);
this.panelWhite.Margin = new System.Windows.Forms.Padding(2);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(43, 43);
this.panelWhite.TabIndex = 1;
this.panelWhite.MouseDown += panelColor_MouseDown;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(194, 34);
this.panelYellow.Margin = new System.Windows.Forms.Padding(2);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(43, 43);
this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += panelColor_MouseDown;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(135, 34);
this.panelBlue.Margin = new System.Windows.Forms.Padding(2);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(43, 43);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += panelColor_MouseDown;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panelGreen.Location = new System.Drawing.Point(77, 34);
this.panelGreen.Margin = new System.Windows.Forms.Padding(2);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(43, 43);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += panelColor_MouseDown;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(18, 34);
this.panelRed.Margin = new System.Windows.Forms.Padding(2);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(43, 43);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += panelColor_MouseDown;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(117, 75);
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(2);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(144, 27);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(117, 42);
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(2);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(144, 27);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(24, 80);
this.labelWeight.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(33, 20);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Вес";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(24, 43);
this.labelSpeed.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(73, 20);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость";
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(26, 49);
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(2);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(286, 140);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelAddColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(621, 18);
this.panelObject.Margin = new System.Windows.Forms.Padding(2);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(334, 202);
this.panelObject.TabIndex = 2;
this. panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelAddColor
//
this.labelAddColor.AllowDrop = true;
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAddColor.Location = new System.Drawing.Point(180, 7);
this.labelAddColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelAddColor.Name = "labelAddColor";
this.labelAddColor.Size = new System.Drawing.Size(132, 40);
this.labelAddColor.TabIndex = 3;
this.labelAddColor.Text = "Дополн. цвет";
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAddColor.DragDrop += labelColor_dragDrop;
this.labelAddColor.DragEnter += labelColor_dragEnter;
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(26, 7);
this.labelColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(132, 40);
this.labelColor.TabIndex = 2;
this.labelColor.Text = "Основной цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += labelColor_dragDrop;
this.labelColor.DragEnter += labelColor_dragEnter;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(626, 233);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(152, 41);
this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += buttonAdd_Click;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(794, 233);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(152, 41);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormBulldozerConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(978, 291);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxParameters);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "FormBulldozerConfig";
this.Text = "Создание объекта";
this.groupBoxParameters.ResumeLayout(false);
this.groupBoxParameters.PerformLayout();
this.groupBoxMarks.ResumeLayout(false);
this.groupBoxMarks.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParameters;
private CheckBox checkBoxBlade;
private CheckBox checkBoxRipper;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private Label labelModifiedObject;
private Label labelSimpleObject;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Panel panelObject;
private Label labelAddColor;
private Label labelColor;
private Button buttonAdd;
private Button buttonCancel;
private GroupBox groupBoxMarks;
}
}

View File

@ -0,0 +1,146 @@
using Bulldozer.Entities;
using Bulldozer.DrawingObjects;
namespace Bulldozer
{
public partial class FormBulldozerConfig : Form
{
/// <summary>
/// Переменная-выбранный бульдозер
/// </summary>
DrawingBulldozer? _bulldozer = null;
/// <summary>
/// Делегат для передачи объекта-бульдозера
/// </summary>
private event Action<DrawingBulldozer>? EventAddBulldozer;
/// <summary>
/// Конструктор
/// </summary>
public FormBulldozerConfig()
{
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 DrawBulldozer()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_bulldozer?.SetPosition(5, 5);
_bulldozer?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawingBulldozer> ev)
{
if (EventAddBulldozer == null)
{
EventAddBulldozer = ev;
}
else
{
EventAddBulldozer += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_bulldozer = new DrawingBulldozer((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Cyan, pictureBoxObject.Width, pictureBoxObject.Height);
break;
case "labelModifiedObject":
_bulldozer = new DrawingBulldozerUpgraded((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, Color.Blue,checkBoxRipper.Checked, checkBoxBlade.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawBulldozer();
}
public 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 (_bulldozer == null)
return;
switch (((Label)sender).Name)
{
case "labelColor":
_bulldozer?.EntityBulldozer?.SetBodyColor((Color) e.Data.GetData(typeof(Color)));
break;
case "labelAddColor":
if (!(_bulldozer is DrawingBulldozerUpgraded))
return;
(_bulldozer.EntityBulldozer as EntityBulldozerUpgraded)?.SetDopColor(dopColor: (Color) e.Data.GetData(typeof(Color)));
break;
}
DrawBulldozer();
}
/// <summary>
/// Добавление бульдозера
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddBulldozer?.Invoke(_bulldozer);
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -68,6 +68,7 @@ namespace Bulldozer.Generics
} }
return obj; return obj;
} }
/// <summary> /// <summary>
/// Получение объекта IMoveableObject /// Получение объекта IMoveableObject
/// </summary> /// </summary>
@ -77,6 +78,7 @@ namespace Bulldozer.Generics
{ {
return (U?)_collection[pos]?.GetMoveableObject; return (U?)_collection[pos]?.GetMoveableObject;
} }
/// <summary> /// <summary>
/// Вывод всего набора объектов /// Вывод всего набора объектов
/// </summary> /// </summary>
@ -89,6 +91,7 @@ namespace Bulldozer.Generics
DrawObjects(gr); DrawObjects(gr);
return bmp; return bmp;
} }
/// <summary> /// <summary>
/// Метод отрисовки фона /// Метод отрисовки фона
/// </summary> /// </summary>
@ -109,6 +112,7 @@ namespace Bulldozer.Generics
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
} }
} }
/// <summary> /// <summary>
/// Метод прорисовки объектов /// Метод прорисовки объектов
/// </summary> /// </summary>
@ -128,14 +132,16 @@ namespace Bulldozer.Generics
int row = heightObjCount - 1 - (i / widthObjCount); int row = heightObjCount - 1 - (i / widthObjCount);
bulldozer.SetPosition(col * _placeSizeWidth + 3, row * _placeSizeHeight + 3); bulldozer.SetPosition(col * _placeSizeWidth + 3, row * _placeSizeHeight + 3);
bulldozer?.DrawBulldozer(g); bulldozer?.DrawTransport(g);
i++; i++;
} }
if (i > totalObjects) if (i > totalObjects)
{ {
return; return;
} }
} }
} }
} }
} }

View File

@ -17,10 +17,12 @@ namespace Bulldozer.Generics
/// Количество объектов в списке /// Количество объектов в списке
/// </summary> /// </summary>
public int Count => _places.Count; public int Count => _places.Count;
/// <summary> /// <summary>
/// Максимальное количество объектов в списке /// Максимальное количество объектов в списке
/// </summary> /// </summary>
private readonly int _maxCount; private readonly int _maxCount;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -30,6 +32,7 @@ namespace Bulldozer.Generics
_maxCount = count; _maxCount = count;
_places = new List<T?>(); _places = new List<T?>();
} }
/// <summary> /// <summary>
/// Добавление объекта в набор /// Добавление объекта в набор
/// </summary> /// </summary>
@ -54,6 +57,7 @@ namespace Bulldozer.Generics
_places.Insert(position, bulldozer); _places.Insert(position, bulldozer);
return position; return position;
} }
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
/// </summary> /// </summary>
@ -63,9 +67,12 @@ namespace Bulldozer.Generics
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
return false; return false;
_places.RemoveAt(position); _places.RemoveAt(position);
return true; return true;
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции
/// </summary> /// </summary>
@ -80,6 +87,7 @@ namespace Bulldozer.Generics
} }
return _places[position]; return _places[position];
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции
/// </summary> /// </summary>
@ -98,6 +106,7 @@ namespace Bulldozer.Generics
_places.Insert(position, value); _places.Insert(position, value);
} }
} }
/// <summary> /// <summary>
/// Проход по списку /// Проход по списку
/// </summary> /// </summary>

View File

@ -26,6 +26,6 @@ namespace Bulldozer.MovementStrategy
} }
public int GetStep => (int)(_drawingBulldozer?.EntityBulldozer?.Step ?? 0); public int GetStep => (int)(_drawingBulldozer?.EntityBulldozer?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawingBulldozer?.CanMove(direction) ?? false; public bool CheckCanMove(DirectionType direction) => _drawingBulldozer?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawingBulldozer?.MoveBulldozer(direction); public void MoveObject(DirectionType direction) => _drawingBulldozer?.MoveTransport(direction);
} }
} }