Сделал лабораторную 3
This commit is contained in:
parent
0f4098ad95
commit
40cd0e854b
@ -1,4 +1,5 @@
|
||||
using Bulldozer.Entities;
|
||||
using Bulldozer.MovementStrategy;
|
||||
|
||||
namespace Bulldozer.DrawingObjects
|
||||
{
|
||||
@ -46,32 +47,28 @@ namespace Bulldozer.DrawingObjects
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height)
|
||||
{
|
||||
if (width < _bulldozerWidth || height < _bulldozerHeight)
|
||||
{
|
||||
width += _bulldozerWidth * 2;
|
||||
height += _bulldozerHeight * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="carWidth">Ширина прорисовки бульдозера</param>
|
||||
/// <param name="carHeight">Высота прорисовки бульдозера</param>
|
||||
protected DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int bulldozerWidth, int bulldozerHeight)
|
||||
{
|
||||
if (width < _bulldozerWidth || height < _bulldozerHeight)
|
||||
{
|
||||
width += _bulldozerWidth * 2;
|
||||
height += _bulldozerHeight * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_bulldozerWidth = bulldozerWidth;
|
||||
_bulldozerHeight = bulldozerHeight;
|
||||
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -82,15 +79,14 @@ namespace Bulldozer.DrawingObjects
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0)
|
||||
{
|
||||
_startPosX = 0; _startPosY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
// Проверка границ
|
||||
if (x < 0) x = 0;
|
||||
if (y < 0) y = 0;
|
||||
if (x > _pictureWidth - _bulldozerWidth) x = _pictureWidth - _bulldozerWidth;
|
||||
if (y > _pictureHeight - _bulldozerHeight) y = _pictureHeight - _bulldozerHeight;
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -122,13 +118,13 @@ namespace Bulldozer.DrawingObjects
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
// влево
|
||||
DirectionType.Left => _startPosX - EntityBulldozer.Step > 0,
|
||||
//вверх
|
||||
// вверх
|
||||
DirectionType.Up => _startPosY - EntityBulldozer.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityBulldozer.Step < _pictureWidth,
|
||||
//вниз
|
||||
// вниз
|
||||
DirectionType.Down => _startPosY + EntityBulldozer.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
@ -137,7 +133,7 @@ namespace Bulldozer.DrawingObjects
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public virtual void MoveBulldozer(DirectionType direction)
|
||||
public void MoveBulldozer(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityBulldozer == null)
|
||||
{
|
||||
@ -176,29 +172,33 @@ namespace Bulldozer.DrawingObjects
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityBulldozer.AdditionalColor);
|
||||
|
||||
/// <summary>
|
||||
/// Заливка гусеницы бульдозера
|
||||
/// </summary>
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
|
||||
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(brGray, _startPosX + 17, _startPosY + 24, 119, 40); //Гусеница
|
||||
g.FillEllipse(additionalBrush, _startPosX + 20, _startPosY + 35, 20, 20); // Левое колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 115, _startPosY + 35, 20, 20); // Правое колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 50, _startPosY + 45, 10, 10); // 1 центральное колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 70, _startPosY + 45, 10, 10); // 2 центральное колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 45, 10, 10); // 3 центральное колесо гусеницы
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовка границ бульдозера
|
||||
/// </summary>
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 17, _startPosY + 24, 119, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 20, 20); // Левое колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 35, 20, 20); // Правое колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 45, 10, 10); // 1 центральное колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 45, 10, 10); // 2 центральное колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 45, 10, 10); // 3 центральное колесо гусеницы
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Кузов бульдозера
|
||||
/// </summary>
|
||||
@ -212,7 +212,11 @@ namespace Bulldozer.DrawingObjects
|
||||
g.DrawRectangle(pen, _startPosX + 17, _startPosY + 24, 119, 18); // основная часть
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 10, 24); // выхлопная труба
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawingBulldozer
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectBulldozer(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,12 @@ namespace Bulldozer.DrawingObjects
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="additionalColor">Цвет обвесов</param>
|
||||
/// <param name="blade">Признак наличия рыхлителя</param>
|
||||
/// <param name="ripper">Признак наличия отвала</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
|
||||
|
||||
|
||||
public DrawingBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper, int width, int height) :
|
||||
base(speed, weight, bodyColor, additionalColor, width, height)
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Bulldozer.Entities
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Bulldozer.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бульдозер"
|
||||
@ -17,10 +19,10 @@
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения бульдозера
|
||||
/// </summary>
|
||||
@ -31,7 +33,6 @@
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес бульдозера</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
public EntityBulldozer(int speed, double weight, Color bodyColor, Color additionalColor)
|
||||
{
|
||||
Speed = speed;
|
||||
@ -40,5 +41,7 @@
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
241
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
241
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
@ -28,144 +28,168 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxBulldozer = new PictureBox();
|
||||
buttonCreateBulldozer = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonCreateUpgradedBulldozer = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
|
||||
SuspendLayout();
|
||||
this.pictureBoxBulldozer = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateBulldozer = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonCreateUpgradedBulldozer = new System.Windows.Forms.Button();
|
||||
this.buttonSelectBulldozer = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBulldozer)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxBulldozer
|
||||
//
|
||||
pictureBoxBulldozer.Dock = DockStyle.Fill;
|
||||
pictureBoxBulldozer.Location = new Point(0, 0);
|
||||
pictureBoxBulldozer.Name = "pictureBoxBulldozer";
|
||||
pictureBoxBulldozer.Size = new Size(884, 461);
|
||||
pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxBulldozer.TabIndex = 0;
|
||||
pictureBoxBulldozer.TabStop = false;
|
||||
this.pictureBoxBulldozer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxBulldozer.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxBulldozer.Name = "pictureBoxBulldozer";
|
||||
this.pictureBoxBulldozer.Size = new System.Drawing.Size(1110, 793);
|
||||
this.pictureBoxBulldozer.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxBulldozer.TabIndex = 0;
|
||||
this.pictureBoxBulldozer.TabStop = false;
|
||||
//
|
||||
// buttonCreateBulldozer
|
||||
//
|
||||
buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBulldozer.Location = new Point(12, 426);
|
||||
buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
||||
buttonCreateBulldozer.Size = new Size(132, 23);
|
||||
buttonCreateBulldozer.TabIndex = 1;
|
||||
buttonCreateBulldozer.Text = "Создать бульдозер";
|
||||
buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
||||
buttonCreateBulldozer.Click += buttonCreateBulldozer_Click;
|
||||
this.buttonCreateBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateBulldozer.Location = new System.Drawing.Point(14, 746);
|
||||
this.buttonCreateBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
||||
this.buttonCreateBulldozer.Size = new System.Drawing.Size(151, 31);
|
||||
this.buttonCreateBulldozer.TabIndex = 1;
|
||||
this.buttonCreateBulldozer.Text = "Создать бульдозер";
|
||||
this.buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateBulldozer.Click += new System.EventHandler(this.buttonCreateBulldozer_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Image = Properties.Resources.arrowLeft;
|
||||
buttonLeft.Location = new Point(759, 422);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Bulldozer.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Image = global::Bulldozer.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(967, 741);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(795, 422);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Bulldozer.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(1009, 741);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Image = Properties.Resources.arrowRight;
|
||||
buttonRight.Location = new Point(831, 422);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Bulldozer.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Image = global::Bulldozer.Properties.Resources.arrowRight;
|
||||
this.buttonRight.Location = new System.Drawing.Point(1050, 741);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonRight.TabIndex = 4;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Image = Properties.Resources.arrowUp;
|
||||
buttonUp.Location = new Point(795, 386);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Bulldozer.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Image = global::Bulldozer.Properties.Resources.arrowUp;
|
||||
this.buttonUp.Location = new System.Drawing.Point(1009, 693);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonUp.TabIndex = 5;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "Движение к центру", "Движение к правой нижней границе" });
|
||||
comboBoxStrategy.Location = new Point(642, 9);
|
||||
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(232, 23);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"Движение к центру",
|
||||
"Движение к правой нижней границе"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(834, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(264, 28);
|
||||
this.comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Location = new Point(821, 35);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(52, 23);
|
||||
buttonStep.TabIndex = 7;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonStep.Location = new System.Drawing.Point(1038, 47);
|
||||
this.buttonStep.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(60, 31);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "Шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// buttonCreateUpgradedBulldozer
|
||||
//
|
||||
buttonCreateUpgradedBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateUpgradedBulldozer.Location = new Point(150, 426);
|
||||
buttonCreateUpgradedBulldozer.Name = "buttonCreateUpgradedBulldozer";
|
||||
buttonCreateUpgradedBulldozer.Size = new Size(206, 23);
|
||||
buttonCreateUpgradedBulldozer.TabIndex = 8;
|
||||
buttonCreateUpgradedBulldozer.Text = "Создать бульдозер с обвесами";
|
||||
buttonCreateUpgradedBulldozer.UseVisualStyleBackColor = true;
|
||||
buttonCreateUpgradedBulldozer.Click += buttonCreateUpgradedBulldozer_Click;
|
||||
this.buttonCreateUpgradedBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateUpgradedBulldozer.Location = new System.Drawing.Point(171, 746);
|
||||
this.buttonCreateUpgradedBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateUpgradedBulldozer.Name = "buttonCreateUpgradedBulldozer";
|
||||
this.buttonCreateUpgradedBulldozer.Size = new System.Drawing.Size(235, 31);
|
||||
this.buttonCreateUpgradedBulldozer.TabIndex = 8;
|
||||
this.buttonCreateUpgradedBulldozer.Text = "Создать бульдозер с обвесами";
|
||||
this.buttonCreateUpgradedBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateUpgradedBulldozer.Click += new System.EventHandler(this.buttonCreateUpgradedBulldozer_Click);
|
||||
//
|
||||
// buttonSelectBulldozer
|
||||
//
|
||||
this.buttonSelectBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectBulldozer.Location = new System.Drawing.Point(412, 746);
|
||||
this.buttonSelectBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonSelectBulldozer.Name = "buttonSelectBulldozer";
|
||||
this.buttonSelectBulldozer.Size = new System.Drawing.Size(130, 31);
|
||||
this.buttonSelectBulldozer.TabIndex = 9;
|
||||
this.buttonSelectBulldozer.Text = "Выбрать объект";
|
||||
this.buttonSelectBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectBulldozer.Click += new System.EventHandler(this.buttonSelectBulldozer_Click);
|
||||
//
|
||||
// FormBulldozer
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonCreateUpgradedBulldozer);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateBulldozer);
|
||||
Controls.Add(pictureBoxBulldozer);
|
||||
Name = "FormBulldozer";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Bulldozer";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1110, 793);
|
||||
this.Controls.Add(this.buttonSelectBulldozer);
|
||||
this.Controls.Add(this.buttonCreateUpgradedBulldozer);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonCreateBulldozer);
|
||||
this.Controls.Add(this.pictureBoxBulldozer);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormBulldozer";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Bulldozer";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBulldozer)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -179,5 +203,6 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreateUpgradedBulldozer;
|
||||
private Button buttonSelectBulldozer;
|
||||
}
|
||||
}
|
@ -5,19 +5,34 @@ namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozer : Form
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawingBulldozer? _drawingBulldozer;
|
||||
|
||||
public FormBulldozer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Âûáðàííûé áóëüäîçåð
|
||||
/// </summary>
|
||||
public DrawingBulldozer? SelectedBulldozer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormBulldozer()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBulldozer = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè áóëüäîçåðà
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingBulldozer == null)
|
||||
@ -35,7 +50,6 @@ namespace Bulldozer
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBulldozer == null)
|
||||
@ -61,26 +75,58 @@ namespace Bulldozer
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateUpgradedBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Îñíîâíîé öâåò
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Äîï. öâåò äëÿ EntityUpgradedBulldozer
|
||||
ColorDialog colorDialog = new();
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = colorDialog.Color;
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = colorDialog.Color;
|
||||
_drawingBulldozer = new DrawingBulldozerUpgraded(
|
||||
random.Next(100, 300), // Ñêîðîñòü
|
||||
random.Next(1000, 3000), // Âåñ
|
||||
bodyColor, additionalColor, dopColor,
|
||||
Convert.ToBoolean(random.Next(2)),
|
||||
Convert.ToBoolean(random.Next(2)),
|
||||
pictureBoxBulldozer.Width,
|
||||
pictureBoxBulldozer.Height
|
||||
);
|
||||
|
||||
_drawingBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingBulldozer = new DrawingBulldozer(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)),
|
||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
_drawingBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = colorDialog.Color;
|
||||
}
|
||||
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
_drawingBulldozer = new DrawingBulldozer(random.Next(100, 300), // Ñêîðîñòü
|
||||
random.Next(1000, 3000), // Âåñ
|
||||
bodyColor, additionalColor,
|
||||
pictureBoxBulldozer.Width,
|
||||
pictureBoxBulldozer.Height);
|
||||
|
||||
private void buttonCreateUpgradedBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingBulldozer = new DrawingBulldozerUpgraded(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)),
|
||||
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)),
|
||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
_drawingBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
@ -118,5 +164,17 @@ namespace Bulldozer
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Âûáîð áóëüäîçåðà
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonSelectBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBulldozer = _drawingBulldozer;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
124
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
124
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class FormBulldozerCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxCollection = new PictureBox();
|
||||
panelTools = new Panel();
|
||||
textBox = new TextBox();
|
||||
buttonUpdateColletion = new Button();
|
||||
buttonDeleteBulldozer = new Button();
|
||||
buttonAddBulldozer = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panelTools.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Anchor = AnchorStyles.Left;
|
||||
pictureBoxCollection.BackColor = SystemColors.Control;
|
||||
pictureBoxCollection.Location = new Point(12, 12);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(711, 571);
|
||||
pictureBoxCollection.TabIndex = 0;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
panelTools.Controls.Add(textBox);
|
||||
panelTools.Controls.Add(buttonUpdateColletion);
|
||||
panelTools.Controls.Add(buttonDeleteBulldozer);
|
||||
panelTools.Controls.Add(buttonAddBulldozer);
|
||||
panelTools.Location = new Point(729, 12);
|
||||
panelTools.Name = "panelTools";
|
||||
panelTools.Size = new Size(234, 571);
|
||||
panelTools.TabIndex = 1;
|
||||
panelTools.Tag = "";
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
textBox.Location = new Point(23, 164);
|
||||
textBox.Name = "textBox";
|
||||
textBox.Size = new Size(193, 23);
|
||||
textBox.TabIndex = 3;
|
||||
//
|
||||
// buttonUpdateColletion
|
||||
//
|
||||
buttonUpdateColletion.Location = new Point(23, 263);
|
||||
buttonUpdateColletion.Name = "buttonUpdateColletion";
|
||||
buttonUpdateColletion.Size = new Size(193, 40);
|
||||
buttonUpdateColletion.TabIndex = 2;
|
||||
buttonUpdateColletion.Text = "Обновить коллекцию";
|
||||
buttonUpdateColletion.UseVisualStyleBackColor = true;
|
||||
buttonUpdateColletion.Click += ButtonUpdateCollection_Click;
|
||||
//
|
||||
// buttonDeleteBulldozer
|
||||
//
|
||||
buttonDeleteBulldozer.Location = new Point(23, 193);
|
||||
buttonDeleteBulldozer.Name = "buttonDeleteBulldozer";
|
||||
buttonDeleteBulldozer.Size = new Size(193, 40);
|
||||
buttonDeleteBulldozer.TabIndex = 1;
|
||||
buttonDeleteBulldozer.Text = "Удалить объект";
|
||||
buttonDeleteBulldozer.UseVisualStyleBackColor = true;
|
||||
buttonDeleteBulldozer.Click += ButtonDeleteBulldozer_Click;
|
||||
//
|
||||
// buttonAddBulldozer
|
||||
//
|
||||
buttonAddBulldozer.Location = new Point(23, 32);
|
||||
buttonAddBulldozer.Name = "buttonAddBulldozer";
|
||||
buttonAddBulldozer.Size = new Size(193, 40);
|
||||
buttonAddBulldozer.TabIndex = 0;
|
||||
buttonAddBulldozer.Text = "Добавить объект";
|
||||
buttonAddBulldozer.UseVisualStyleBackColor = true;
|
||||
buttonAddBulldozer.Click += ButtonAddBulldozer_Click;
|
||||
//
|
||||
// FormBulldozerCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(971, 595);
|
||||
Controls.Add(panelTools);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name = "FormBulldozerCollection";
|
||||
Text = "Bulldozer Collection";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
panelTools.ResumeLayout(false);
|
||||
panelTools.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private TextBox textBox;
|
||||
private Button buttonUpdateColletion;
|
||||
private Button buttonDeleteBulldozer;
|
||||
private Button buttonAddBulldozer;
|
||||
}
|
||||
}
|
60
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
60
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
using Bulldozer.Generics;
|
||||
using Bulldozer.MovementStrategy;
|
||||
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozerCollection : Form
|
||||
{
|
||||
private readonly BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer> _bulldozers;
|
||||
public FormBulldozerCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_bulldozers = new BulldozersGenericCollection<DrawingBulldozer,
|
||||
DrawingObjectBulldozer>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
|
||||
}
|
||||
private void ButtonAddBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormBulldozer form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_bulldozers + form.SelectedBulldozer != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _bulldozers.ShowBulldozers();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDeleteBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(textBox.Text);
|
||||
if (_bulldozers - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _bulldozers.ShowBulldozers();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdateCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _bulldozers.ShowBulldozers();
|
||||
}
|
||||
}
|
||||
}
|
120
Bulldozer/Bulldozer/FormBulldozerCollection.resx
Normal file
120
Bulldozer/Bulldozer/FormBulldozerCollection.resx
Normal 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>
|
129
Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs
Normal file
129
Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
using Bulldozer.MovementStrategy;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
internal class BulldozersGenericCollection<T, U>
|
||||
where T : DrawingBulldozer
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 300;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 70;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public BulldozersGenericCollection(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 +(BulldozersGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
|
||||
public static bool operator -(BulldozersGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
return collect._collection.Remove(pos);
|
||||
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 ShowBulldozers()
|
||||
{
|
||||
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 / 2, 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 heightObjCount = _pictureHeight / _placeSizeHeight;
|
||||
int widthObjCount = _pictureWidth / _placeSizeWidth;
|
||||
int totalObjects = _collection.Count;
|
||||
|
||||
for (int i = 0; i < totalObjects; i++)
|
||||
{
|
||||
T? type = _collection.Get(i);
|
||||
if (type != null)
|
||||
{
|
||||
int col = widthObjCount - 1 - (i % widthObjCount);
|
||||
int row = heightObjCount - 1 - (i / widthObjCount);
|
||||
|
||||
type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
|
||||
type?.DrawBulldozer(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
87
Bulldozer/Bulldozer/Generics/SetGeneric.cs
Normal file
87
Bulldozer/Bulldozer/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
namespace Bulldozer.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="bulldozer">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T bulldozer)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(bulldozer, 0);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="bulldozer">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T bulldozer, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = bulldozer;
|
||||
return position;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
|
||||
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -12,10 +12,10 @@ namespace Bulldozer.MovementStrategy
|
||||
var objParams = GetObjectParameters;
|
||||
|
||||
return objParams != null
|
||||
&& objParams.RightBorder <= FieldWidth
|
||||
&& objParams.RightBorder + GetStep() >= FieldWidth
|
||||
&& objParams.TopBorder <= FieldHeight
|
||||
&& objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
&& objParams.ObjectMiddleHorizontal >= FieldWidth
|
||||
&& objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
|
||||
&& objParams.ObjectMiddleVertical >= FieldHeight
|
||||
&& objParams.ObjectMiddleVertical - GetStep() <= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
@ -26,8 +26,8 @@ namespace Bulldozer.MovementStrategy
|
||||
return;
|
||||
}
|
||||
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
//public int DownBorder => _y + _height;
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
|
@ -9,7 +9,7 @@ namespace Bulldozer.MovementStrategy
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBulldozer());
|
||||
Application.Run(new FormBulldozerCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user