ISEbd-21. Pyatkin I.A. Lab work 03. #3

Closed
IvanPyatkin wants to merge 1 commits from lab03 into lab02
16 changed files with 650 additions and 71 deletions

View File

@ -4,11 +4,17 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.Entities;
using ProjectExcavator.MovementStrategy;
namespace ProjectExcavator.DrawingObjects
{
public class DrawingExcavator
{
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawingExcavator
/// </summary>
public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this);
/// <summary>
/// Класс-сущность
/// </summary>
@ -22,21 +28,21 @@ namespace ProjectExcavator.DrawingObjects
/// </summary>
private int _pictureHeight;
/// <summary>
/// /// Левая координата прорисовки автомобиля
/// /// Левая координата прорисовки экскаватора
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// Верхняя координата прорисовки экскаватора
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// Ширина прорисовки экскаватора
/// </summary>
protected readonly int _exWidth = 138;
protected readonly int _exWidth = 140;
/// <summary>
/// Высота прорисовки автомобиля
/// Высота прорисовки экскаватора
/// </summary>
protected readonly int _exHeight = 80;
protected readonly int _exHeight = 82;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -192,9 +198,7 @@ namespace ProjectExcavator.DrawingObjects
//цвета
Pen pen = new(Color.Black);
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush brYellow = new SolidBrush(Color.Yellow);
Brush brGray = new SolidBrush(Color.Gray);
Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor);
Brush brBlack = new SolidBrush(Color.Black);
//отрисовка экскаватора без ковша
@ -213,18 +217,18 @@ namespace ProjectExcavator.DrawingObjects
g.DrawEllipse(pen, _startPosX + 92, _startPosY + 68, 6, 6);
//кабина водителя
g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 11, 29, 24);
g.FillRectangle(bodyBrush, _startPosX + 96, _startPosY + 11, 29, 24);
// кузов
g.FillRectangle(brYellow, _startPosX + 51, _startPosY + 36, 74, 24);
g.FillRectangle(bodyBrush, _startPosX + 51, _startPosY + 36, 74, 24);
// труба
g.FillRectangle(brYellow, _startPosX + 61, _startPosY + 16, 9, 19);
g.FillRectangle(bodyBrush, _startPosX + 61, _startPosY + 16, 9, 19);
//гусеница
g.FillPie(brGray, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
g.FillPie(brGray, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
g.FillRectangle(brGray, _startPosX + 44, _startPosY + 65, 86, 20);
g.FillPie(bodyBrush, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
g.FillPie(bodyBrush, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
g.FillRectangle(bodyBrush, _startPosX + 44, _startPosY + 65, 86, 20);
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 76, 8, 8);

View File

@ -24,7 +24,7 @@ namespace ProjectExcavator.DrawingObjects
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawingExcavatorKovsh(int speed, double weight, Color bodyColor, Color
additionalColor, bool kovsh, bool katki, int width, int height) : base(speed, weight, bodyColor, width, height, 138, 80)
additionalColor, bool kovsh, bool katki, int width, int height) : base(speed, weight, bodyColor, width, height, 140, 82)
{
if (EntityExcavator != null)
{
@ -38,56 +38,54 @@ namespace ProjectExcavator.DrawingObjects
{
return;
}
//цвета
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(excavatorKovsh.AdditionalColor);
Brush brBlack = new SolidBrush(Color.Black);
// ковш
if (excavatorKovsh.Kovsh)
{
g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
g.FillPie(brBlack, _startPosX, _startPosY + 44, 28, 30, 90, 180);
Point point1 = new Point(_startPosX + 50, _startPosY + 35);
Point point2 = new Point(_startPosX + 10, _startPosY + 10);
Point point3 = new Point(_startPosX + 12, _startPosY + 5);
Point point4 = new Point(_startPosX + 58, _startPosY + 35);
Point[] truba_1 = { point1, point2, point3, point4, point1 };
g.FillPolygon(additionalBrush, truba_1);
g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180);
Point point1 = new Point(_startPosX + 50, _startPosY + 35);
Point point2 = new Point(_startPosX + 10, _startPosY + 10);
Point point3 = new Point(_startPosX + 12, _startPosY + 5);
Point point4 = new Point(_startPosX + 58, _startPosY + 35);
Point[] truba_1 = { point1, point2, point3, point4, point1 };
g.FillPolygon(additionalBrush, truba_1);
Point point5 = new Point(_startPosX + 10, _startPosY + 10);
Point point6 = new Point(_startPosX + 10, _startPosY + 45);
Point point7 = new Point(_startPosX + 14, _startPosY + 45);
Point point8 = new Point(_startPosX + 14, _startPosY + 5);
Point[] truba_2 = { point5, point6, point7, point8, point5 };
g.FillPolygon(additionalBrush, truba_2);
Point point5 = new Point(_startPosX + 10, _startPosY + 10);
Point point6 = new Point(_startPosX + 10, _startPosY + 45);
Point point7 = new Point(_startPosX + 14, _startPosY + 45);
Point point8 = new Point(_startPosX + 14, _startPosY + 5);
Point[] truba_2 = { point5, point6, point7, point8, point5 };
g.FillPolygon(additionalBrush, truba_2);
Point point9 = new Point(_startPosX + 14, _startPosY + 5);
Point point10 = new Point(_startPosX + 14, _startPosY);
Point point11 = new Point(_startPosX + 7, _startPosY + 10);
Point[] triangle = { point9, point10, point11, point9 };
g.FillPolygon(additionalBrush, triangle);
Point point9 = new Point(_startPosX + 14, _startPosY + 5);
Point point10 = new Point(_startPosX + 14, _startPosY);
Point point11 = new Point(_startPosX + 7, _startPosY + 10);
Point[] triangle = { point9, point10, point11, point9 };
g.FillPolygon(additionalBrush, triangle);
Point point12 = new Point(_startPosX + 14, _startPosY);
Point point13 = new Point(_startPosX + 50, _startPosY + 12);
Point point14 = new Point(_startPosX + 50, _startPosY + 16);
Point point15 = new Point(_startPosX + 14, _startPosY);
Point[] krepl = { point12, point13, point14, point15, point12 };
g.FillPolygon(additionalBrush, krepl);
Point point12 = new Point(_startPosX + 14, _startPosY);
Point point13 = new Point(_startPosX + 50, _startPosY + 12);
Point point14 = new Point(_startPosX + 50, _startPosY + 16);
Point point15 = new Point(_startPosX + 14, _startPosY);
Point[] krepl = { point12, point13, point14, point15, point12 };
g.FillPolygon(additionalBrush, krepl);
}
base.DrawTransport(g);
// катки

View File

@ -8,7 +8,7 @@ using ProjectExcavator.DrawingObjects;
namespace ProjectExcavator.MovementStrategy
{
/// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
/// Реализация интерфейса IDrawningObject для работы с объектом DrawingExcavator (паттерн Adapter)
/// </summary>
public class DrawingObjectExcavator : IMoveableObject
{

View File

@ -21,14 +21,14 @@ namespace ProjectExcavator.Entities
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// Шаг перемещения экскаватора
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// Инициализация полей объекта-класса экскаватора
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="weight">Вес экскаватора</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityExcavator(int speed, double weight, Color bodyColor)
{

View File

@ -28,7 +28,7 @@ namespace ProjectExcavator.Entities
/// Инициализация полей объекта-класса экскаватора с ковшом
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="weight">Вес экскаватора</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="kovsh">Признак наличия ковша</param>

View File

@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.DrawingObjects;
using ProjectExcavator.MovementStrategy;
namespace ProjectExcavator.Generics
{
/// <summary>
/// Параметризованный класс для набора объектов DrawingExcavator
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class ExcavatorGenericCollection<T, U>
where T : DrawingExcavator
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 200;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public ExcavatorGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(ExcavatorGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj) ?? -1;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static bool operator -(ExcavatorGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
return true;
}
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowExcavator()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++)
{
DrawingExcavator? excavator = _collection.Get(i);
if (excavator == null)
continue;
int r = i / width;
int s = width - 1 - (i % width);
excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight);
excavator.DrawTransport(g);
}
}
}
}

View File

@ -37,6 +37,7 @@
this.buttonCreateEx = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonSelectExcavator = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).BeginInit();
this.SuspendLayout();
//
@ -140,11 +141,22 @@
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
this.comboBoxStrategy.TabIndex = 9;
//
// buttonSelectExcavator
//
this.buttonSelectExcavator.Location = new System.Drawing.Point(370, 426);
this.buttonSelectExcavator.Name = "buttonSelectExcavator";
this.buttonSelectExcavator.Size = new System.Drawing.Size(105, 23);
this.buttonSelectExcavator.TabIndex = 10;
this.buttonSelectExcavator.Text = "Выбрать обьект";
this.buttonSelectExcavator.UseVisualStyleBackColor = true;
this.buttonSelectExcavator.Click += new System.EventHandler(this.ButtonSelectExcavator_Click);
//
// FormExcavator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
this.Controls.Add(this.buttonSelectExcavator);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateEx);
@ -172,5 +184,6 @@
private Button buttonCreateEx;
private Button buttonStep;
private ComboBox comboBoxStrategy;
private Button buttonSelectExcavator;
}
}

View File

@ -1,5 +1,6 @@
using ProjectExcavator.DrawingObjects;
using ProjectExcavator.MovementStrategy;
using System.Windows.Forms;
namespace ProjectExcavator
{
@ -11,9 +12,17 @@ namespace ProjectExcavator
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Âûáðàííûé ýêñêàâàòîð
/// </summary>
public DrawingExcavator? SelectedExcavator { get; private set; }
public FormExcavator()
{
InitializeComponent();
InitializeComponent();
_abstractStrategy = null;
_drawingExcavator = null;
}
private void Draw()
@ -30,11 +39,24 @@ namespace ProjectExcavator
private void buttonCreateExKovsh_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âûáîð îñíîâíîãî öâåòà
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âûáîð äîïîëíèòåëüíîãî öâåòà
ColorDialog dialog2 = new();
if (dialog2.ShowDialog() == DialogResult.OK)
{
dopColor = dialog2.Color;
}
_drawingExcavator = new DrawingExcavatorKovsh(random.Next(100, 300), random.Next(1000, 3000),
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)),
color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@ -42,8 +64,14 @@ namespace ProjectExcavator
private void buttonCreateEx_Click(object sender, EventArgs e)
{
Random random = new();
_drawingExcavator = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
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;
}
_drawingExcavator = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000), color,
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@ -113,5 +141,15 @@ namespace ProjectExcavator
_abstractStrategy = null;
}
}
/// <summary>
/// Âûáîð ýêñêàâàòîðà
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectExcavator_Click(object sender, EventArgs e)
{
SelectedExcavator = _drawingExcavator;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,122 @@
namespace ProjectExcavator
{
partial class FormExcavatorCollection
{
/// <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.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.buttonAddEx = new System.Windows.Forms.Button();
this.buttonRemoveEx = new System.Windows.Forms.Button();
this.buttonRefreshCollection = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCollection
//
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(909, 461);
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false;
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(26, 125);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 23);
this.maskedTextBoxNumber.TabIndex = 1;
//
// buttonAddEx
//
this.buttonAddEx.Location = new System.Drawing.Point(6, 57);
this.buttonAddEx.Name = "buttonAddEx";
this.buttonAddEx.Size = new System.Drawing.Size(150, 23);
this.buttonAddEx.TabIndex = 2;
this.buttonAddEx.Text = "Добавить экскаватор";
this.buttonAddEx.UseVisualStyleBackColor = true;
this.buttonAddEx.Click += new System.EventHandler(this.ButtonAddEx_Click);
//
// buttonRemoveEx
//
this.buttonRemoveEx.Location = new System.Drawing.Point(6, 166);
this.buttonRemoveEx.Name = "buttonRemoveEx";
this.buttonRemoveEx.Size = new System.Drawing.Size(150, 23);
this.buttonRemoveEx.TabIndex = 3;
this.buttonRemoveEx.Text = "Удалить экскаватор";
this.buttonRemoveEx.UseVisualStyleBackColor = true;
this.buttonRemoveEx.Click += new System.EventHandler(this.ButtonRemoveEx_Click);
//
// buttonRefreshCollection
//
this.buttonRefreshCollection.Location = new System.Drawing.Point(6, 230);
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
this.buttonRefreshCollection.Size = new System.Drawing.Size(148, 23);
this.buttonRefreshCollection.TabIndex = 4;
this.buttonRefreshCollection.Text = "Обновить коллекцию";
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
this.buttonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonAddEx);
this.groupBox1.Controls.Add(this.buttonRefreshCollection);
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
this.groupBox1.Controls.Add(this.buttonRemoveEx);
this.groupBox1.Location = new System.Drawing.Point(749, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(160, 461);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// FormExcavatorCollection
//
this.ClientSize = new System.Drawing.Size(909, 461);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.pictureBoxCollection);
this.Name = "FormExcavatorCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
private Button buttonAddEx;
private Button buttonRemoveEx;
private Button buttonRefreshCollection;
private GroupBox groupBox1;
}
}

View File

@ -0,0 +1,81 @@
using ProjectExcavator.DrawingObjects;
using ProjectExcavator.Generics;
using ProjectExcavator.MovementStrategy;
namespace ProjectExcavator
{
/// <summary>
/// Форма для работы с набором объектов класса DrawingExcavator
/// </summary>
public partial class FormExcavatorCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly ExcavatorGenericCollection<DrawingExcavator,
DrawingObjectExcavator> _excavator;
/// <summary>
/// Конструктор
/// </summary>
public FormExcavatorCollection()
{
InitializeComponent();
_excavator = new ExcavatorGenericCollection<DrawingExcavator,
DrawingObjectExcavator>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddEx_Click(object sender, EventArgs e)
{
FormExcavator form = new();
if (form.ShowDialog() == DialogResult.OK)
{
int result = _excavator + form.SelectedExcavator;
if (result != -2)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _excavator.ShowExcavator();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveEx_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_excavator - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _excavator.ShowExcavator();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _excavator.ShowExcavator();
}
}
}

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

@ -26,7 +26,7 @@ namespace ProjectExcavator.MovementStrategy
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления перемещения объекта
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);

View File

@ -41,7 +41,6 @@ namespace ProjectExcavator.MovementStrategy
{
MoveRight();
}
}
var diffY = objParams.ObjectBorderDown - FieldHeight;
if (Math.Abs(diffY) > GetStep())

View File

@ -36,7 +36,13 @@ namespace ProjectExcavator.MovementStrategy
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
/// <summary>
/// Нижний правый угол объекта
/// </summary>
public int ObjectBorderRight => _x + _width;
/// <summary>
/// Нижний правый угол объекта
/// </summary>
public int ObjectBorderDown => _y + _height;
/// <summary>
/// Конструктор

View File

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

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator.Generics
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T?[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
_places = new T?[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="excavator">Добавляемый экскаватор</param>
/// <returns></returns>
public int Insert(T excavator)
{
for (int i = _places.Length - 1; i > 0; i--)
Review

И зачем, если потом вызывается Insert(excavator, 0)?

И зачем, если потом вызывается Insert(excavator, 0)?
{
_places[i] = _places[i - 1];
}
_places[0] = excavator;
return Insert(excavator, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="excavator">Добавляемый экскаватор</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T excavator, int position)
{
if (position < 0 || position >= _places.Length)
{
return -1;
}
if (_places[position] != null)
{
return -1;
}
int NullIndex = 0;
for (int i = position; i < _places.Length; i++)
{
if (_places[i] == null)
{
NullIndex = i;
break;
}
}
if (NullIndex == 0)
{
return -1;
}
for (int i = NullIndex; i >= position; i--)
{
_places[i + 1] = _places[i];
}
_places[position] = excavator;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= _places.Length)
{
return false;
}
_places[position] = null;
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
{
if (position < 0 || position >= _places.Length)
{
return null;
}
return _places[position];
}
}
}