ISE_22.Aparyan.Bulldozer.Base Lab03 #3
@ -1,17 +1,19 @@
|
|||||||
using ProjectBulldozer.Entities;
|
using ProjectBulldozer.Entities;
|
||||||
|
namespace ProjectBulldozer.Drawning
|
||||||
namespace ProjectBulldozer.Drawings
|
|
||||||
{
|
{
|
||||||
public class DrawingBulldozer : DrawingTractor
|
public class DrawingBulldozer : DrawingTractor
|
||||||
{
|
{
|
||||||
public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor,
|
public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
bool otval, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 129, 120)
|
bool horns, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 140, 130)
|
||||||
{
|
{
|
||||||
if (EntityTractor != null)
|
if (EntityTractor != null)
|
||||||
{
|
{
|
||||||
EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, otval, seifBatteries);
|
EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, horns, seifBatteries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Otval { get; private set; }
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityTractor is not EntityBulldozer Bulldozer)
|
if (EntityTractor is not EntityBulldozer Bulldozer)
|
||||||
@ -20,54 +22,61 @@ namespace ProjectBulldozer.Drawings
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
|
|
||||||
|
|
||||||
Brush blackBrush = new SolidBrush(Color.Black);
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
Brush windows = new SolidBrush(Color.LightBlue);
|
Brush windows = new SolidBrush(Color.LightBlue);
|
||||||
Brush bodyColor = new SolidBrush(Bulldozer.BodyColor);
|
Brush bodyColor = new SolidBrush(Bulldozer.BodyColor);
|
||||||
Brush additionalBrush = new SolidBrush(Bulldozer.AdditionalColor);
|
|
||||||
|
Brush additionalColor = new SolidBrush(Bulldozer.AdditionalColor);
|
||||||
|
|
||||||
Brush grayBrush = new SolidBrush(Color.Gray);
|
Brush grayBrush = new SolidBrush(Color.Gray);
|
||||||
if (Bulldozer.Otval)
|
|
||||||
{
|
|
||||||
//otval
|
//otval
|
||||||
Point[] Otval =
|
Point[] Otval =
|
||||||
{
|
{
|
||||||
new Point(_startPosX + 122, _startPosY + 55),
|
new Point(_startPosX + 118, _startPosY + 50),
|
||||||
new Point(_startPosX + 142, _startPosY + 115),
|
new Point(_startPosX + 148, _startPosY + 111),
|
||||||
new Point(_startPosX+ 122, _startPosY + 115),
|
new Point(_startPosX+ 118, _startPosY + 111),
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
g.FillPolygon(blackBrush, Otval);
|
g.FillPolygon(additionalColor, Otval);
|
||||||
g.DrawPolygon(pen, Otval);
|
g.DrawPolygon(pen, Otval);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//гусеницы
|
//гусеницы
|
||||||
Brush gg = new SolidBrush(Color.LightGray);
|
Brush gg = new SolidBrush(Color.LightGray);
|
||||||
g.FillEllipse(gg, _startPosX + 19, _startPosY + 62, 100, 65);
|
g.FillEllipse(gg, _startPosX + 16, _startPosY + 65, 101, 63);
|
||||||
g.DrawEllipse(pen, _startPosX + 19, _startPosY + 62, 100, 65);
|
g.DrawEllipse(pen, _startPosX + 16, _startPosY + 65, 101, 63);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 15, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 15, 15);
|
g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 13, 13);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 13, 13);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Point[] Ttt =
|
Point[] Ttt =
|
||||||
{
|
{
|
||||||
new Point(_startPosX + 18 , _startPosY + 80),
|
|
||||||
new Point(_startPosX + 18, _startPosY + 110),
|
new Point(_startPosX + 16, _startPosY + 79),
|
||||||
new Point(_startPosX, _startPosY + 50),
|
new Point(_startPosX + 16, _startPosY + 120),
|
||||||
|
new Point(_startPosX, _startPosY + 48),
|
||||||
|
|
||||||
};
|
};
|
||||||
g.FillPolygon(blackBrush, Ttt);
|
g.FillPolygon(blackBrush, Ttt);
|
||||||
g.DrawPolygon(pen, Ttt);
|
g.DrawPolygon(pen, Ttt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (Bulldozer.SeifBatteries)
|
if (Bulldozer.SeifBatteries)
|
||||||
{
|
{
|
||||||
g.FillRectangle(blackBrush, _startPosX + 78, _startPosY + 30, 10, 10);
|
g.FillRectangle(blackBrush, _startPosX + 110, _startPosY + 60, 5, 10);
|
||||||
}
|
}
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
}
|
}
|
@ -1,13 +1,10 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bulldozer;
|
using Bulldozer;
|
||||||
using ProjectBulldozer.Entities;
|
using ProjectBulldozer.Entities;
|
||||||
using ProjectBulldozer.Properties;
|
using ProjectBulldozer.MovementStrategy;
|
||||||
|
|
||||||
namespace ProjectBulldozer.Drawings
|
|
||||||
|
namespace ProjectBulldozer.Drawning
|
||||||
{
|
{
|
||||||
public class DrawingTractor
|
public class DrawingTractor
|
||||||
{
|
{
|
||||||
@ -21,15 +18,15 @@ namespace ProjectBulldozer.Drawings
|
|||||||
|
|
||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
|
|
||||||
private int tractWidth;
|
protected readonly int _tractWidth = 120;
|
||||||
protected readonly int _tractWidth = 140;
|
|
||||||
|
|
||||||
protected readonly int _tractHeight = 123;
|
protected readonly int _tractHeight = 110;
|
||||||
public int GetPosX => _startPosX;
|
public int GetPosX => _startPosX;
|
||||||
public int GetPosY => _startPosY;
|
public int GetPosY => _startPosY;
|
||||||
public int GetWidth => _tractWidth;
|
public int GetWidth => _tractWidth;
|
||||||
public int GetHeight => _tractHeight;
|
public int GetHeight => _tractHeight;
|
||||||
|
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this);
|
||||||
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||||
{
|
{
|
||||||
if (width < _tractWidth || heigth < _tractHeight)
|
if (width < _tractWidth || heigth < _tractHeight)
|
||||||
@ -60,7 +57,7 @@ namespace ProjectBulldozer.Drawings
|
|||||||
{
|
{
|
||||||
if (x < 0 || x + _tractWidth > _pictureWidth)
|
if (x < 0 || x + _tractWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
x = _pictureWidth - tractWidth;
|
x = _pictureWidth - _tractWidth;
|
||||||
}
|
}
|
||||||
if (y < 0 || y + _tractHeight > _pictureHeight)
|
if (y < 0 || y + _tractHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
@ -111,6 +108,7 @@ namespace ProjectBulldozer.Drawings
|
|||||||
if (EntityTractor == null) return;
|
if (EntityTractor == null) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush brownBrush = new SolidBrush(Color.Brown);
|
Brush brownBrush = new SolidBrush(Color.Brown);
|
||||||
Brush windows = new SolidBrush(Color.LightYellow);
|
Brush windows = new SolidBrush(Color.LightYellow);
|
||||||
@ -119,30 +117,30 @@ namespace ProjectBulldozer.Drawings
|
|||||||
Brush grayBrush = new SolidBrush(Color.Gray);
|
Brush grayBrush = new SolidBrush(Color.Gray);
|
||||||
|
|
||||||
//основное тело
|
//основное тело
|
||||||
g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 40, 100, 60);
|
g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56);
|
||||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 100, 60);
|
g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//кабина водителя
|
//кабина водителя
|
||||||
g.FillRectangle(windows, _startPosX + 20, _startPosY, 40, 40);
|
g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37);
|
||||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40);
|
g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//колеса
|
//колеса
|
||||||
|
|
||||||
g.FillEllipse(grayBrush, _startPosX + 20, _startPosY + 74, 47, 47);
|
g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45);
|
||||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 74, 47, 47);
|
g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45);
|
||||||
|
|
||||||
|
|
||||||
g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 85, 35, 35);
|
g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33);
|
||||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 85, 35, 35);
|
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33);
|
||||||
|
|
||||||
|
|
||||||
//выхлопная труба
|
//выхлопная труба
|
||||||
g.FillRectangle(brownBrush, _startPosX + 90, _startPosY, 15, 40);
|
g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35);
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 40);
|
g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
59
ProjectBulldozer/FormBulldozer.Designer.cs
generated
59
ProjectBulldozer/FormBulldozer.Designer.cs
generated
@ -1,6 +1,6 @@
|
|||||||
namespace Bulldozer
|
namespace Bulldozer
|
||||||
{
|
{
|
||||||
partial class Bulldozer
|
partial class FormBulldozer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -37,6 +37,7 @@
|
|||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonCreateTractor = new Button();
|
buttonCreateTractor = new Button();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
|
ButtonSelect_Tractor = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -46,7 +47,7 @@
|
|||||||
pictureBoxBulldozer.Location = new Point(0, 0);
|
pictureBoxBulldozer.Location = new Point(0, 0);
|
||||||
pictureBoxBulldozer.Margin = new Padding(2);
|
pictureBoxBulldozer.Margin = new Padding(2);
|
||||||
pictureBoxBulldozer.Name = "pictureBoxBulldozer";
|
pictureBoxBulldozer.Name = "pictureBoxBulldozer";
|
||||||
pictureBoxBulldozer.Size = new Size(869, 307);
|
pictureBoxBulldozer.Size = new Size(870, 390);
|
||||||
pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxBulldozer.TabIndex = 0;
|
pictureBoxBulldozer.TabIndex = 0;
|
||||||
pictureBoxBulldozer.TabStop = false;
|
pictureBoxBulldozer.TabStop = false;
|
||||||
@ -54,11 +55,10 @@
|
|||||||
// buttonCreateBulldozer
|
// buttonCreateBulldozer
|
||||||
//
|
//
|
||||||
buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateBulldozer.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonCreateBulldozer.Location = new Point(11, 332);
|
||||||
buttonCreateBulldozer.Location = new Point(131, 249);
|
|
||||||
buttonCreateBulldozer.Margin = new Padding(2);
|
buttonCreateBulldozer.Margin = new Padding(2);
|
||||||
buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
||||||
buttonCreateBulldozer.Size = new Size(100, 47);
|
buttonCreateBulldozer.Size = new Size(95, 48);
|
||||||
buttonCreateBulldozer.TabIndex = 1;
|
buttonCreateBulldozer.TabIndex = 1;
|
||||||
buttonCreateBulldozer.Text = "Создать булльдозер";
|
buttonCreateBulldozer.Text = "Создать булльдозер";
|
||||||
buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
||||||
@ -69,10 +69,10 @@
|
|||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = ProjectBulldozer.Properties.Resources.left1;
|
buttonLeft.BackgroundImage = ProjectBulldozer.Properties.Resources.left1;
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonLeft.Location = new Point(764, 271);
|
buttonLeft.Location = new Point(767, 353);
|
||||||
buttonLeft.Margin = new Padding(2);
|
buttonLeft.Margin = new Padding(2);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(26, 25);
|
buttonLeft.Size = new Size(30, 27);
|
||||||
buttonLeft.TabIndex = 2;
|
buttonLeft.TabIndex = 2;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
buttonLeft.Click += buttonMove_Click;
|
buttonLeft.Click += buttonMove_Click;
|
||||||
@ -82,10 +82,10 @@
|
|||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = ProjectBulldozer.Properties.Resources.up1;
|
buttonUp.BackgroundImage = ProjectBulldozer.Properties.Resources.up1;
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonUp.Location = new Point(792, 240);
|
buttonUp.Location = new Point(801, 320);
|
||||||
buttonUp.Margin = new Padding(2);
|
buttonUp.Margin = new Padding(2);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(30, 27);
|
buttonUp.Size = new Size(34, 28);
|
||||||
buttonUp.TabIndex = 3;
|
buttonUp.TabIndex = 3;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += buttonMove_Click;
|
buttonUp.Click += buttonMove_Click;
|
||||||
@ -95,10 +95,10 @@
|
|||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = ProjectBulldozer.Properties.Resources.right1;
|
buttonRight.BackgroundImage = ProjectBulldozer.Properties.Resources.right1;
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonRight.Location = new Point(826, 271);
|
buttonRight.Location = new Point(837, 353);
|
||||||
buttonRight.Margin = new Padding(2);
|
buttonRight.Margin = new Padding(2);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(27, 25);
|
buttonRight.Size = new Size(28, 26);
|
||||||
buttonRight.TabIndex = 4;
|
buttonRight.TabIndex = 4;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += buttonMove_Click;
|
buttonRight.Click += buttonMove_Click;
|
||||||
@ -108,10 +108,10 @@
|
|||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = ProjectBulldozer.Properties.Resources.down1;
|
buttonDown.BackgroundImage = ProjectBulldozer.Properties.Resources.down1;
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonDown.Location = new Point(794, 271);
|
buttonDown.Location = new Point(801, 353);
|
||||||
buttonDown.Margin = new Padding(2);
|
buttonDown.Margin = new Padding(2);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(30, 25);
|
buttonDown.Size = new Size(32, 27);
|
||||||
buttonDown.TabIndex = 5;
|
buttonDown.TabIndex = 5;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += buttonMove_Click;
|
buttonDown.Click += buttonMove_Click;
|
||||||
@ -120,24 +120,22 @@
|
|||||||
//
|
//
|
||||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxStrategy.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "В угол" });
|
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "В угол" });
|
||||||
comboBoxStrategy.Location = new Point(693, 10);
|
comboBoxStrategy.Location = new Point(740, 8);
|
||||||
comboBoxStrategy.Margin = new Padding(2);
|
comboBoxStrategy.Margin = new Padding(2);
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
comboBoxStrategy.Size = new Size(150, 25);
|
comboBoxStrategy.Size = new Size(113, 23);
|
||||||
comboBoxStrategy.TabIndex = 6;
|
comboBoxStrategy.TabIndex = 6;
|
||||||
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
|
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonCreateTractor
|
// buttonCreateTractor
|
||||||
//
|
//
|
||||||
buttonCreateTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateTractor.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonCreateTractor.Location = new Point(122, 332);
|
||||||
buttonCreateTractor.Location = new Point(11, 249);
|
|
||||||
buttonCreateTractor.Margin = new Padding(2);
|
buttonCreateTractor.Margin = new Padding(2);
|
||||||
buttonCreateTractor.Name = "buttonCreateTractor";
|
buttonCreateTractor.Name = "buttonCreateTractor";
|
||||||
buttonCreateTractor.Size = new Size(106, 47);
|
buttonCreateTractor.Size = new Size(81, 47);
|
||||||
buttonCreateTractor.TabIndex = 7;
|
buttonCreateTractor.TabIndex = 7;
|
||||||
buttonCreateTractor.Text = "Создать трактор";
|
buttonCreateTractor.Text = "Создать трактор";
|
||||||
buttonCreateTractor.UseVisualStyleBackColor = true;
|
buttonCreateTractor.UseVisualStyleBackColor = true;
|
||||||
@ -146,21 +144,33 @@
|
|||||||
// buttonStep
|
// buttonStep
|
||||||
//
|
//
|
||||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonStep.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
buttonStep.Location = new Point(755, 39);
|
buttonStep.Location = new Point(755, 39);
|
||||||
buttonStep.Margin = new Padding(2);
|
buttonStep.Margin = new Padding(2);
|
||||||
buttonStep.Name = "buttonStep";
|
buttonStep.Name = "buttonStep";
|
||||||
buttonStep.Size = new Size(88, 34);
|
buttonStep.Size = new Size(88, 20);
|
||||||
buttonStep.TabIndex = 8;
|
buttonStep.TabIndex = 8;
|
||||||
buttonStep.Text = "Шаг";
|
buttonStep.Text = "Шаг";
|
||||||
buttonStep.UseVisualStyleBackColor = true;
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
buttonStep.Click += buttonStep_Click;
|
buttonStep.Click += buttonStep_Click;
|
||||||
//
|
//
|
||||||
// Bulldozer
|
// ButtonSelect_Tractor
|
||||||
|
//
|
||||||
|
ButtonSelect_Tractor.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
ButtonSelect_Tractor.Location = new Point(755, 63);
|
||||||
|
ButtonSelect_Tractor.Margin = new Padding(2);
|
||||||
|
ButtonSelect_Tractor.Name = "ButtonSelect_Tractor";
|
||||||
|
ButtonSelect_Tractor.Size = new Size(88, 23);
|
||||||
|
ButtonSelect_Tractor.TabIndex = 9;
|
||||||
|
ButtonSelect_Tractor.Text = "Выбрать";
|
||||||
|
ButtonSelect_Tractor.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSelect_Tractor.Click += ButtonSelect_Tractor_Click;
|
||||||
|
//
|
||||||
|
// FormBulldozer
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(869, 307);
|
ClientSize = new Size(870, 390);
|
||||||
|
Controls.Add(ButtonSelect_Tractor);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(buttonCreateTractor);
|
Controls.Add(buttonCreateTractor);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
@ -171,7 +181,7 @@
|
|||||||
Controls.Add(buttonCreateBulldozer);
|
Controls.Add(buttonCreateBulldozer);
|
||||||
Controls.Add(pictureBoxBulldozer);
|
Controls.Add(pictureBoxBulldozer);
|
||||||
Margin = new Padding(2);
|
Margin = new Padding(2);
|
||||||
Name = "Bulldozer";
|
Name = "FormBulldozer";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Bulldozer";
|
Text = "Bulldozer";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit();
|
||||||
@ -190,5 +200,6 @@
|
|||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonCreateTractor;
|
private Button buttonCreateTractor;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
|
private Button ButtonSelect_Tractor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,21 +1,23 @@
|
|||||||
using ProjectBulldozer;
|
using ProjectBulldozer;
|
||||||
using ProjectBulldozer.Drawings;
|
using ProjectBulldozer.Drawning;
|
||||||
using ProjectBulldozer.Generics;
|
using ProjectBulldozer.Generics;
|
||||||
using ProjectBulldozer.MovementStrategy;
|
using ProjectBulldozer.MovementStrategy;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Bulldozer
|
namespace Bulldozer
|
||||||
{
|
{
|
||||||
public partial class Bulldozer : Form
|
public partial class FormBulldozer : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private DrawingTractor? _drawingTractor;
|
private DrawingTractor? _drawingTractor;
|
||||||
|
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawingTractor? SelectedTractor { get; private set; }
|
||||||
|
|
||||||
public Bulldozer()
|
public FormBulldozer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedTractor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
@ -33,9 +35,24 @@ namespace Bulldozer
|
|||||||
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawingTractor = 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 color = 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)),
|
|
||||||
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||||
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
@ -45,8 +62,13 @@ namespace Bulldozer
|
|||||||
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
|
||||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||||
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
@ -95,15 +117,14 @@ namespace Bulldozer
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new
|
_abstractStrategy.SetData(_drawingTractor.GetMoveableObject, pictureBoxBulldozer.Width,
|
||||||
DrawingObjectTractor(_drawingTractor), pictureBoxBulldozer.Width,
|
|
||||||
pictureBoxBulldozer.Height);
|
pictureBoxBulldozer.Height);
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
_abstractStrategy.MakeStep();
|
_abstractStrategy.MakeStep();
|
||||||
Draw();
|
Draw();
|
||||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
@ -113,6 +134,12 @@ namespace Bulldozer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelect_Tractor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedTractor = _drawingTractor;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
99
ProjectBulldozer/Generics/BulldozerGenericCollection.cs
Normal file
99
ProjectBulldozer/Generics/BulldozerGenericCollection.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using ProjectBulldozer.MovementStrategy;
|
||||||
|
using ProjectBulldozer.Drawning;
|
||||||
|
namespace ProjectBulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
|
||||||
|
{
|
||||||
|
//ширина /высота окна
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
//ширина /высота занимаемого места
|
||||||
|
private readonly int _placeSizeWidth = 170;
|
||||||
|
private readonly int _placeSizeHeight = 130;
|
||||||
|
/// Набор объектов
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
public TractorGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
|
||||||
|
// высчитываем размер массива для setgeneric
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
public static int operator +(TractorGenericCollection<T, U> collect, T tract)
|
||||||
|
{
|
||||||
|
if (tract == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(tract);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(TractorGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private bool Remove(int pos)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
// получение объекта imoveableObj
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowTractors()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
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 / 3, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int HeightObjCount = _pictureHeight / _placeSizeHeight;
|
||||||
|
int WidthObjCount = _pictureWidth / _placeSizeWidth;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
T t = _collection.Get(i);
|
||||||
|
if (t != null)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
t.SetPosition(((_collection.Count - i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection.Count - i - 1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
|
||||||
|
t.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
using ProjectBulldozer.Drawings;
|
using ProjectBulldozer.Drawning;
|
||||||
|
|
||||||
namespace ProjectBulldozer.MovementStrategy
|
namespace ProjectBulldozer.MovementStrategy
|
||||||
{
|
{
|
||||||
public class DrawingObjectTractor : IMoveableObject
|
public class DrawingObjectTractor : IMoveableObject
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
|
using Bulldozer;
|
||||||
|
|
||||||
namespace ProjectBulldozer.MovementStrategy
|
namespace ProjectBulldozer.MovementStrategy
|
||||||
{
|
{
|
||||||
public interface IMoveableObject
|
public interface IMoveableObject
|
||||||
{
|
{
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
int GetStep { get; }
|
int GetStep { get; }
|
||||||
|
|
||||||
bool CheckCanMove(DirectionType direction);
|
bool CheckCanMove(DirectionType direction);
|
||||||
void MoveObject(DirectionType direction);
|
void MoveObject(DirectionType direction);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
|
namespace ProjectBulldozer.MovementStrategy
|
||||||
|
|
||||||
namespace ProjectBulldozer.MovementStrategy
|
|
||||||
{
|
{
|
||||||
public class ObjectParameters
|
public class ObjectParameters
|
||||||
{
|
{
|
||||||
@ -8,22 +6,16 @@ namespace ProjectBulldozer.MovementStrategy
|
|||||||
private readonly int _y;
|
private readonly int _y;
|
||||||
private readonly int _width;
|
private readonly int _width;
|
||||||
private readonly int _height;
|
private readonly int _height;
|
||||||
|
|
||||||
/// Левая граница
|
/// Левая граница
|
||||||
public int LeftBorder => _x;
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
/// Верхняя граница
|
/// Верхняя граница
|
||||||
public int TopBorder => _y;
|
public int TopBorder => _y;
|
||||||
|
|
||||||
/// Правая граница
|
/// Правая граница
|
||||||
public int RightBorder => _x + _width;
|
public int RightBorder => _x + _width;
|
||||||
|
|
||||||
/// Нижняя граница
|
/// Нижняя граница
|
||||||
public int DownBorder => _y + _height;
|
public int DownBorder => _y + _height;
|
||||||
|
|
||||||
/// Середина объекта по горизонтали
|
/// Середина объекта по горизонтали
|
||||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
|
||||||
/// Середина объекта по вертикали
|
/// Середина объекта по вертикали
|
||||||
public int ObjectMiddleVertical => _y + _height / 2;
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using ProjectBulldozer;
|
||||||
|
|
||||||
namespace Bulldozer
|
namespace Bulldozer
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +13,7 @@ namespace Bulldozer
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Bulldozer());
|
Application.Run(new FormTractorCollections());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user