ISE_22.Aparyan.Bulldozer.Base Lab03 #3

Closed
LuizaAparyan wants to merge 4 commits from Laba03 into Laba02
20 changed files with 585 additions and 215 deletions

View File

@ -1,6 +1,4 @@
 namespace ProjectBulldozer
namespace ProjectBulldozer
{ {
public enum DirectionType public enum DirectionType
{ {

View File

@ -1,17 +1,17 @@
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)
@ -23,51 +23,35 @@ namespace ProjectBulldozer.Drawings
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
{ Point[] Otval =
//otval {
Point[] Otval = new Point(_startPosX + 118, _startPosY + 50),
{ new Point(_startPosX + 148, _startPosY + 111),
new Point(_startPosX + 122, _startPosY + 55), new Point(_startPosX+ 118, _startPosY + 111),
new Point(_startPosX + 142, _startPosY + 115),
new Point(_startPosX+ 122, _startPosY + 115),
}; };
g.FillPolygon(additionalColor, Otval);
g.FillPolygon(blackBrush, 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, 13, 13);
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 13, 13);
g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 15, 15);
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 15, 15);
Point[] Ttt = Point[] Ttt =
{ {
new Point(_startPosX + 18 , _startPosY + 80), new Point(_startPosX + 16, _startPosY + 79),
new Point(_startPosX + 18, _startPosY + 110), new Point(_startPosX + 16, _startPosY + 120),
new Point(_startPosX, _startPosY + 50), 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);
} }

View File

@ -1,35 +1,22 @@
using System; using ProjectBulldozer.Entities;
using System.Collections.Generic; using ProjectBulldozer.MovementStrategy;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bulldozer;
using ProjectBulldozer.Entities;
using ProjectBulldozer.Properties;
namespace ProjectBulldozer.Drawings namespace ProjectBulldozer.Drawning
{ {
public class DrawingTractor public class DrawingTractor
{ {
public EntityTractor? EntityTractor { get; protected set; } public EntityTractor? EntityTractor { get; protected set; }
protected int _pictureWidth; protected int _pictureWidth;
protected int _pictureHeight; protected int _pictureHeight;
protected int _startPosX; protected int _startPosX;
protected int _startPosY; protected int _startPosY;
protected readonly int _tractWidth = 120;
private int tractWidth; protected readonly int _tractHeight = 110;
protected readonly int _tractWidth = 140;
protected readonly int _tractHeight = 123;
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)
@ -40,7 +27,6 @@ namespace ProjectBulldozer.Drawings
_pictureHeight = heigth; _pictureHeight = heigth;
EntityTractor = new EntityTractor(speed, weight, bodyColor); EntityTractor = new EntityTractor(speed, weight, bodyColor);
} }
protected DrawingTractor(int speed, double weight, Color bodyColor, int width, protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
int height, int tractWidth, int tractHeight) int height, int tractWidth, int tractHeight)
{ {
@ -54,13 +40,12 @@ namespace ProjectBulldozer.Drawings
_tractHeight = tractHeight; _tractHeight = tractHeight;
EntityTractor = new EntityTractor(speed, weight, bodyColor); EntityTractor = new EntityTractor(speed, weight, bodyColor);
} }
//Установка позиции //Установка позиции
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
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)
{ {
@ -110,43 +95,26 @@ 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);
Brush bodyColor = new SolidBrush(EntityTractor.BodyColor); Brush bodyColor = new SolidBrush(EntityTractor.BodyColor);
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 + 19, _startPosY + 76, 45, 45);
g.FillEllipse(grayBrush, _startPosX + 20, _startPosY + 74, 47, 47); g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 74, 47, 47); g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33);
g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 85, 35, 35);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 85, 35, 35);
//выхлопная труба //выхлопная труба
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);
} }
public bool CanMove(DirectionType direction) public bool CanMove(DirectionType direction)
{ {
if (EntityTractor == null) if (EntityTractor == null)

View File

@ -1,9 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.Entities namespace ProjectBulldozer.Entities
{ {
public class EntityBulldozer : EntityTractor public class EntityBulldozer : EntityTractor

View File

@ -1,10 +1,4 @@
using System; namespace ProjectBulldozer.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.Entities
{ {
public class EntityTractor public class EntityTractor
{ {

View File

@ -1,16 +1,9 @@
namespace Bulldozer 
namespace Bulldozer
{ {
partial class Bulldozer partial class FormBulldozer
{ {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; 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) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -19,13 +12,7 @@
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #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() private void InitializeComponent()
{ {
pictureBoxBulldozer = new PictureBox(); pictureBoxBulldozer = new PictureBox();
@ -37,6 +24,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 +34,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 +42,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 +56,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 +69,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 +82,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 +95,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 +107,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 +131,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,16 +168,19 @@
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();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}
#endregion #endregion
private PictureBox pictureBoxBulldozer; private PictureBox pictureBoxBulldozer;
private Button buttonCreateBulldozer; private Button buttonCreateBulldozer;
private Button buttonLeft; private Button buttonLeft;
@ -190,5 +190,6 @@
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonCreateTractor; private Button buttonCreateTractor;
private Button buttonStep; private Button buttonStep;
private Button ButtonSelect_Tractor;
} }
} }

View File

@ -1,22 +1,20 @@
using ProjectBulldozer; using ProjectBulldozer;
using ProjectBulldozer.Drawings; using ProjectBulldozer.Drawning;
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()
{ {
if (_drawingTractor == null) if (_drawingTractor == null)
@ -28,29 +26,40 @@ namespace Bulldozer
_drawingTractor.DrawTransport(gr); _drawingTractor.DrawTransport(gr);
pictureBoxBulldozer.Image = bmp; pictureBoxBulldozer.Image = bmp;
} }
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 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();
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), 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));
Draw(); Draw();
} }
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();
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
if (_drawingTractor == null) if (_drawingTractor == null)
@ -75,7 +84,6 @@ namespace Bulldozer
} }
Draw(); Draw();
} }
private void buttonStep_Click(object sender, EventArgs e) private void buttonStep_Click(object sender, EventArgs e)
{ {
if (_drawingTractor == null) if (_drawingTractor == null)
@ -94,15 +102,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)
@ -111,10 +118,10 @@ namespace Bulldozer
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
private void ButtonSelect_Tractor_Click(object sender, EventArgs e)
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{ {
SelectedTractor = _drawingTractor;
DialogResult = DialogResult.OK;
} }
} }
} }

View File

@ -0,0 +1,126 @@
namespace ProjectBulldozer
{
partial class FormTractorCollections
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
Instruments = new Panel();
maskedTextBoxNumber = new MaskedTextBox();
ButtonRefreshCollection = new Button();
ButtonRemoveTractor = new Button();
ButtonAddTractor = new Button();
pictureBoxCollections = new PictureBox();
Instruments.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit();
SuspendLayout();
//
// Instruments
//
Instruments.Anchor = AnchorStyles.Right;
Instruments.AutoSize = true;
Instruments.Controls.Add(maskedTextBoxNumber);
Instruments.Controls.Add(ButtonRefreshCollection);
Instruments.Controls.Add(ButtonAddTractor);
Instruments.Controls.Add(ButtonRemoveTractor);
Instruments.Location = new Point(588, 11);
Instruments.Margin = new Padding(3, 2, 3, 2);
Instruments.Name = "Instruments";
Instruments.Size = new Size(150, 456);
Instruments.TabIndex = 0;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(15, 51);
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Mask = "0";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(119, 23);
maskedTextBoxNumber.TabIndex = 4;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.Anchor = AnchorStyles.Right;
ButtonRefreshCollection.Location = new Point(3, 175);
ButtonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(131, 27);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = "Обновить ";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// ButtonRemoveTractor
//
ButtonRemoveTractor.Anchor = AnchorStyles.Right;
ButtonRemoveTractor.Location = new Point(3, 133);
ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2);
ButtonRemoveTractor.Name = "ButtonRemoveTractor";
ButtonRemoveTractor.Size = new Size(131, 27);
ButtonRemoveTractor.TabIndex = 1;
ButtonRemoveTractor.Text = "Удалить объект";
ButtonRemoveTractor.UseVisualStyleBackColor = true;
ButtonRemoveTractor.Click += ButtonRemoveTractor_Click;
//
// ButtonAddTractor
//
ButtonAddTractor.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonAddTractor.Location = new Point(6, 20);
ButtonAddTractor.Margin = new Padding(3, 2, 3, 2);
ButtonAddTractor.Name = "ButtonAddTractor";
ButtonAddTractor.Size = new Size(128, 27);
ButtonAddTractor.TabIndex = 0;
ButtonAddTractor.Text = "Добавить объект";
ButtonAddTractor.UseVisualStyleBackColor = true;
ButtonAddTractor.Click += ButtonAddTractor_Click;
//
// pictureBoxCollections
//
pictureBoxCollections.Anchor = AnchorStyles.Left;
pictureBoxCollections.Location = new Point(12, 11);
pictureBoxCollections.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollections.Name = "pictureBoxCollections";
pictureBoxCollections.Size = new Size(570, 456);
pictureBoxCollections.TabIndex = 1;
pictureBoxCollections.TabStop = false;
pictureBoxCollections.Click += pictureBoxCollections_Click;
//
// FormTractorCollections
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(748, 478);
Controls.Add(pictureBoxCollections);
Controls.Add(Instruments);
Margin = new Padding(3, 2, 3, 2);
Name = "FormTractorCollections";
Text = "Набор трактороов";
Instruments.ResumeLayout(false);
Instruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit();
ResumeLayout(false);
PerformLayout();
}
private void pictureBoxCollections_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
#endregion
private Panel Instruments;
private Button ButtonRefreshCollection;
private Button ButtonRemoveTractor;
private Button ButtonAddTractor;
private PictureBox pictureBoxCollections;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,56 @@
using Bulldozer;
using ProjectBulldozer.Drawning;
using ProjectBulldozer.Generics;
using ProjectBulldozer.MovementStrategy;
namespace ProjectBulldozer
{
public partial class FormTractorCollections : Form
{
private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _Tractors;
public FormTractorCollections()
{
InitializeComponent();
_Tractors = new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(pictureBoxCollections.Width,
pictureBoxCollections.Height);
}
private void ButtonAddTractor_Click(object sender, EventArgs e)
{
if (_Tractors == null) return;
FormBulldozer form = new();
if (form.ShowDialog() == DialogResult.OK)
{
//проверяем, удалось ли нам загрузить объект
if (_Tractors + form.SelectedTractor != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollections.Image = _Tractors.ShowTractors();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_Tractors - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollections.Image = _Tractors.ShowTractors();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollections.Image = _Tractors.ShowTractors();
}
}
}

View File

@ -0,0 +1,122 @@
<?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="
1" 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>

View File

@ -0,0 +1,92 @@
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);
}
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);
}
}
}
}
}
}

View File

@ -0,0 +1,63 @@
namespace ProjectBulldozer.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T[count];
}
/// Добавление объекта в набор
public int Insert(T tract)
{
return Insert(tract, 0);
}
public int Insert(T tract, int position)
{
int NoEmpty = 0, temp = 0;
for (int i = position; i < Count; i++)
{
if (_places[i] != null) NoEmpty++;
}
if (NoEmpty == Count - position - 1) return -1;
if (position < Count && position >= 0)
{
for (int j = position; j < Count; j++)
{
if (_places[j] == null)
{
temp = j;
break;
}
}
// shift right
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = tract;
return position;
}
return -1;
}
public T? Remove(int position)
{
if (position >= Count || position < 0)
return null;
T tmp = _places[position];
_places[position] = null;
return tmp;
}
//Получение объекта из набора по позиции
public T? Get(int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}

View File

@ -1,5 +1,4 @@
 namespace ProjectBulldozer.Generics
namespace ProjectBulldozer.MovementStrategy
{ {
public enum Status public enum Status
{ {

View File

@ -1,8 +1,7 @@
namespace ProjectBulldozer.MovementStrategy using ProjectBulldozer.Generics;
namespace ProjectBulldozer.MovementStrategy
{ {
/// <summary>
/// Абстрактный класс стратегии
/// </summary>
public abstract class AbstractStrategy public abstract class AbstractStrategy
{ {
private IMoveableObject? _moveableObject; private IMoveableObject? _moveableObject;
@ -11,7 +10,6 @@
protected int FieldWidth { get; private set; } protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; } protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; } public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height) public void SetData(IMoveableObject moveableObject, int width, int height)
{ {
if (moveableObject == null) if (moveableObject == null)
@ -38,18 +36,12 @@
} }
MoveToTarget(); MoveToTarget();
} }
protected bool MoveLeft() => MoveTo(DirectionType.Left); protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right); protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up); protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down); protected bool MoveDown() => MoveTo(DirectionType.Down);
/// Параметры объекта /// Параметры объекта
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
protected int? GetStep() protected int? GetStep()
{ {
if (_state != Status.InProgress) if (_state != Status.InProgress)
@ -59,9 +51,7 @@
return _moveableObject?.GetStep; return _moveableObject?.GetStep;
} }
protected abstract void MoveToTarget(); protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion(); protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType) private bool MoveTo(DirectionType directionType)
{ {
if (_state != Status.InProgress) if (_state != Status.InProgress)

View File

@ -1,12 +1,9 @@
 using ProjectBulldozer.Drawning;
using ProjectBulldozer.Drawings;
namespace ProjectBulldozer.MovementStrategy namespace ProjectBulldozer.MovementStrategy
{ {
public class DrawingObjectTractor : IMoveableObject public class DrawingObjectTractor : IMoveableObject
{ {
private readonly DrawingTractor? _drawningTractor = null; private readonly DrawingTractor? _drawningTractor = null;
public DrawingObjectTractor(DrawingTractor drawningTractor) public DrawingObjectTractor(DrawingTractor drawningTractor)
{ {
_drawningTractor = drawningTractor; _drawningTractor = drawningTractor;

View File

@ -1,12 +1,9 @@
 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);
} }

View File

@ -1,6 +1,4 @@
 namespace ProjectBulldozer.MovementStrategy
namespace ProjectBulldozer.MovementStrategy
{ {
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {
@ -13,7 +11,6 @@ namespace ProjectBulldozer.MovementStrategy
+ GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 && + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
var objParams = GetObjectParameters; var objParams = GetObjectParameters;

View File

@ -1,6 +1,4 @@
 namespace ProjectBulldozer.MovementStrategy
namespace ProjectBulldozer.MovementStrategy
{ {
public class MoveToRightCorner : AbstractStrategy public class MoveToRightCorner : AbstractStrategy
{ {
@ -11,12 +9,10 @@ namespace ProjectBulldozer.MovementStrategy
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep(); return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
var objParams = GetObjectParameters; var objParams = GetObjectParameters;
if (objParams == null) return; if (objParams == null) return;
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight(); if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown(); if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();

View File

@ -1,6 +1,4 @@
 namespace ProjectBulldozer.MovementStrategy
namespace ProjectBulldozer.MovementStrategy
{ {
public class ObjectParameters public class ObjectParameters
{ {
@ -8,25 +6,18 @@ 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;
public ObjectParameters(int x, int y, int width, int height) public ObjectParameters(int x, int y, int width, int height)
{ {
_x = x; _x = x;

View File

@ -1,17 +1,14 @@
using ProjectBulldozer;
namespace Bulldozer namespace Bulldozer
{ {
internal static class Program internal static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font, https://aka.ms/applicationconfiguration.
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Bulldozer()); Application.Run(new FormTractorCollections());
} }
} }
} }