Hard_lab2
This commit is contained in:
parent
6167d840a7
commit
01b6de30dd
@ -29,11 +29,14 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxBus = new PictureBox();
|
pictureBoxBus = new PictureBox();
|
||||||
buttonCreate = new Button();
|
buttonCreatDoubleDeckerBus = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
|
buttonCreateBus = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -47,16 +50,16 @@
|
|||||||
pictureBoxBus.TabIndex = 0;
|
pictureBoxBus.TabIndex = 0;
|
||||||
pictureBoxBus.TabStop = false;
|
pictureBoxBus.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreatDoubleDeckerBus
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreatDoubleDeckerBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 433);
|
buttonCreatDoubleDeckerBus.Location = new Point(12, 411);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreatDoubleDeckerBus.Name = "buttonCreatDoubleDeckerBus";
|
||||||
buttonCreate.Size = new Size(75, 23);
|
buttonCreatDoubleDeckerBus.Size = new Size(163, 45);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreatDoubleDeckerBus.TabIndex = 1;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreatDoubleDeckerBus.Text = "Создать двухэтажный автобус";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreatDoubleDeckerBus.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
buttonCreatDoubleDeckerBus.Click += buttonCreatDoubleDeckerBus_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -106,16 +109,51 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += buttonMove_Click;
|
buttonRight.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateBus
|
||||||
|
//
|
||||||
|
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateBus.Location = new Point(181, 411);
|
||||||
|
buttonCreateBus.Name = "buttonCreateBus";
|
||||||
|
buttonCreateBus.Size = new Size(137, 45);
|
||||||
|
buttonCreateBus.TabIndex = 6;
|
||||||
|
buttonCreateBus.Text = "Создать автобус";
|
||||||
|
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateBus.Click += buttonCreateBus_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
|
comboBoxStrategy.Location = new Point(751, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(121, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonStep.Location = new Point(811, 41);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(61, 25);
|
||||||
|
buttonStep.TabIndex = 8;
|
||||||
|
buttonStep.Text = "Шаг";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStep_Click;
|
||||||
|
//
|
||||||
// DoubleDeckerBus
|
// DoubleDeckerBus
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(884, 468);
|
ClientSize = new Size(884, 468);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonCreateBus);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreatDoubleDeckerBus);
|
||||||
Controls.Add(pictureBoxBus);
|
Controls.Add(pictureBoxBus);
|
||||||
Name = "DoubleDeckerBus";
|
Name = "DoubleDeckerBus";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
@ -128,10 +166,13 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxBus;
|
private PictureBox pictureBoxBus;
|
||||||
private Button buttonCreate;
|
private Button buttonCreatDoubleDeckerBus;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateBus;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,13 @@
|
|||||||
|
using DoubleDeckerBus_Hard.DrawningObjects;
|
||||||
|
using DoubleDeckerBus_Hard.MovementStrategy;
|
||||||
|
|
||||||
namespace DoubleDeckerBus_Hard
|
namespace DoubleDeckerBus_Hard
|
||||||
{
|
{
|
||||||
public partial class DoubleDeckerBus : Form
|
public partial class DoubleDeckerBus : Form
|
||||||
{
|
{
|
||||||
private DrawningDoubleDeckerBus? _drawningBus;
|
private DrawningBus? _drawningBus;
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
public DrawningBus? SelectedBus { get; private set; }
|
||||||
public DoubleDeckerBus()
|
public DoubleDeckerBus()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -13,22 +18,51 @@ namespace DoubleDeckerBus_Hard
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxBus.Width,
|
Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
pictureBoxBus.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningBus.DrawTransport(gr);
|
_drawningBus.DrawTransport(gr);
|
||||||
pictureBoxBus.Image = bmp;
|
pictureBoxBus.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreateBus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningBus = new DrawningDoubleDeckerBus();
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
_drawningBus.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), 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)),
|
ColorDialog dialog = new();
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), random.Next(2, 6), pictureBoxBus.Width, pictureBoxBus.Height);
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawningBus = new DrawningBus(random.Next(100, 300),random.Next(1000, 3000), color,
|
||||||
|
pictureBoxBus.Width, pictureBoxBus.Height, random.Next(2, 6), random.Next(0, 4));
|
||||||
|
_drawningBus.SetPosition(random.Next(10, 100), random.Next(10,100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCreatDoubleDeckerBus_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogColor = new();
|
||||||
|
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialogColor.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogDopColor = new();
|
||||||
|
if (dialogDopColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDopColor.Color;
|
||||||
|
}
|
||||||
|
_drawningBus = new DrawningDoubleDeckerBus(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), random.Next(2, 6),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBus.Width, pictureBoxBus.Height, random.Next(0, 4));
|
||||||
_drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningBus == null)
|
if (_drawningBus == null)
|
||||||
@ -53,6 +87,39 @@ namespace DoubleDeckerBus_Hard
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningBus == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(_drawningBus.GetMoveableObject,
|
||||||
|
pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,114 +0,0 @@
|
|||||||
using DoubleDeckerBus_Hard;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DoubleDeckerBus_Hard
|
|
||||||
{
|
|
||||||
internal class DrawningDoubleDeckerBus
|
|
||||||
{
|
|
||||||
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; }
|
|
||||||
|
|
||||||
private int _pictureWidth;
|
|
||||||
private int _pictureHeight;
|
|
||||||
private int _startPosX;
|
|
||||||
private int _startPosY;
|
|
||||||
private readonly int _busWidth = 100;
|
|
||||||
private readonly int _busHeight = 70;
|
|
||||||
private DrawningDoor drawningsDoors;
|
|
||||||
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
|
||||||
bool secondFloor, bool ladder, bool roadLine, int doorNumbers, int width, int height)
|
|
||||||
{
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
if (_pictureHeight < _busHeight || _pictureWidth < _busWidth)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
EntityDoubleDeckerBus = new EntityDoubleDeckerBus();
|
|
||||||
EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, ladder, roadLine, doorNumbers);
|
|
||||||
|
|
||||||
drawningsDoors = new DrawningDoor();
|
|
||||||
drawningsDoors.ChangeDoorsNumber(doorNumbers);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
_startPosX = Math.Min(x, _pictureWidth - _busWidth);
|
|
||||||
_startPosY = Math.Min(y, _pictureHeight - _busHeight);
|
|
||||||
}
|
|
||||||
public void MoveTransport(DirectionBus direction)
|
|
||||||
{
|
|
||||||
if (EntityDoubleDeckerBus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
//влево
|
|
||||||
case DirectionBus.Left:
|
|
||||||
if (_startPosX - EntityDoubleDeckerBus.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= (int)EntityDoubleDeckerBus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case DirectionBus.Up:
|
|
||||||
if (_startPosY - EntityDoubleDeckerBus.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= (int)EntityDoubleDeckerBus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// вправо
|
|
||||||
case DirectionBus.Right:
|
|
||||||
if (_startPosX + _busWidth + EntityDoubleDeckerBus.Step < _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX += (int)EntityDoubleDeckerBus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case DirectionBus.Down:
|
|
||||||
if (_startPosY + _busHeight + EntityDoubleDeckerBus.Step < _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY += (int)EntityDoubleDeckerBus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (EntityDoubleDeckerBus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
|
|
||||||
g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 60);
|
|
||||||
Brush brBodyColor = new SolidBrush(EntityDoubleDeckerBus.BodyColor);
|
|
||||||
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 60);
|
|
||||||
|
|
||||||
|
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 55, 20, 20);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 55, 20, 20);
|
|
||||||
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 55, 20, 20);
|
|
||||||
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 55, 20, 20);
|
|
||||||
|
|
||||||
Brush brBlue = new SolidBrush(Color.Blue);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15);
|
|
||||||
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 35, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 35, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 35, 10, 15);
|
|
||||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 35, 10, 15);
|
|
||||||
|
|
||||||
drawningsDoors.DrawDoorsNumber(g, _startPosX, _startPosY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,138 @@
|
|||||||
|
using DoubleDeckerBus_Hard.Entities;
|
||||||
|
using DoubleDeckerBus_Hard.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningBus
|
||||||
|
{
|
||||||
|
public EntityBus? EntityBus { get; protected set; }
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectBus(this);
|
||||||
|
public int? _pictureWidth;
|
||||||
|
public int? _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected readonly int _busWidth = 110;
|
||||||
|
protected readonly int _busHeight = 70;
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
public int GetWidth => _busWidth;
|
||||||
|
public int GetHeight => _busHeight;
|
||||||
|
private IDrawningDoors drawningsDoors;
|
||||||
|
public DrawningBus(int speed, float weight, Color bodyColor, int width, int height,int doorNumbers, int doorShape)
|
||||||
|
{
|
||||||
|
if (width < _busWidth || height < _busHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||||
|
switch (doorShape)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
drawningsDoors = new DrawningDoorOval();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
drawningsDoors = new DrawningDoorTriangle();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
drawningsDoors = new DrawningDoorRectangle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
drawningsDoors.ChangeDoorsNumber(doorNumbers);
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
public bool CanMove(DirectionBus direction)
|
||||||
|
{
|
||||||
|
if (EntityBus == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionBus.Left => _startPosX - EntityBus.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionBus.Up => _startPosY - EntityBus.Step > 0,
|
||||||
|
//вправо
|
||||||
|
DirectionBus.Right => _startPosX + _busWidth + EntityBus.Step < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionBus.Down => _startPosY + _busHeight + EntityBus.Step < _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionBus direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityBus == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionBus.Left:
|
||||||
|
_startPosX -= (int)EntityBus.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DirectionBus.Up:
|
||||||
|
_startPosY -= (int)EntityBus.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case DirectionBus.Right:
|
||||||
|
_startPosX += (int)EntityBus.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DirectionBus.Down:
|
||||||
|
_startPosY += (int)EntityBus.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBus == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (EntityBus == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
// Границы первого этажа автобуса
|
||||||
|
g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 30);
|
||||||
|
Brush brBodyColor = new SolidBrush(EntityBus.BodyColor);
|
||||||
|
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 30);
|
||||||
|
// Колеса
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 35, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 35, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 35, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 35, 10, 10);
|
||||||
|
// Окна
|
||||||
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 30, _startPosY + 15, 10, 15);
|
||||||
|
|
||||||
|
drawningsDoors.DrawDoorsNumber(g, _startPosX, _startPosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.DrawningObjects
|
||||||
|
{
|
||||||
|
internal class DrawningDoorOval : IDrawningDoors
|
||||||
|
{
|
||||||
|
public DoorNumbers _doorNumbers;
|
||||||
|
public void ChangeDoorsNumber(int x)
|
||||||
|
{
|
||||||
|
if (x <= 3)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Three;
|
||||||
|
}
|
||||||
|
if (x == 4)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Four;
|
||||||
|
}
|
||||||
|
if (x >= 5)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Five;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.White);
|
||||||
|
Brush brBlue = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 20, _startPosY + 21, 10, 20);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 31, _startPosY + 21, 10, 20);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 60, _startPosY + 21, 10, 20);
|
||||||
|
|
||||||
|
if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 80, _startPosY + 21, 10, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_doorNumbers == DoorNumbers.Five)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 42, _startPosY + 21, 10, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,40 +7,40 @@ using System.Threading.Tasks;
|
|||||||
using static DoubleDeckerBus_Hard.DoorNumbers;
|
using static DoubleDeckerBus_Hard.DoorNumbers;
|
||||||
|
|
||||||
|
|
||||||
namespace DoubleDeckerBus_Hard
|
namespace DoubleDeckerBus_Hard.DrawningObjects
|
||||||
{
|
{
|
||||||
internal class DrawningDoor
|
internal class DrawningDoorRectangle : IDrawningDoors
|
||||||
{
|
{
|
||||||
public DoorNumbers _doorNumbers;
|
public DoorNumbers _doorNumbers;
|
||||||
public void ChangeDoorsNumber(int x)
|
public void ChangeDoorsNumber(int x)
|
||||||
{
|
{
|
||||||
if (x <= 3)
|
if (x <= 3)
|
||||||
{
|
{
|
||||||
_doorNumbers = DoorNumbers.Three;
|
_doorNumbers = Three;
|
||||||
}
|
}
|
||||||
if (x == 4)
|
if (x == 4)
|
||||||
{
|
{
|
||||||
_doorNumbers = DoorNumbers.Four;
|
_doorNumbers = Four;
|
||||||
}
|
}
|
||||||
if (x >= 5)
|
if (x >= 5)
|
||||||
{
|
{
|
||||||
_doorNumbers = DoorNumbers.Five;
|
_doorNumbers = Five;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY)
|
public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.White);
|
Pen pen = new(Color.White);
|
||||||
Brush brBlue = new SolidBrush(Color.Black);
|
Brush brBlue = new SolidBrush(Color.Black);
|
||||||
g.FillRectangle(brBlue, _startPosX + 20, _startPosY + 21, 10, 20);
|
g.FillRectangle(brBlue, _startPosX + 20, _startPosY + 21, 10, 20);
|
||||||
g.FillRectangle(brBlue, _startPosX + 31, _startPosY + 21, 10, 20);
|
g.FillRectangle(brBlue, _startPosX + 31, _startPosY + 21, 10, 20);
|
||||||
g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 21, 10, 20);
|
g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 21, 10, 20);
|
||||||
|
|
||||||
if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five)
|
if (_doorNumbers == Four || _doorNumbers == Five)
|
||||||
{
|
{
|
||||||
g.FillRectangle(brBlue, _startPosX + 80, _startPosY + 21, 10, 20);
|
g.FillRectangle(brBlue, _startPosX + 80, _startPosY + 21, 10, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_doorNumbers == DoorNumbers.Five)
|
if (_doorNumbers == Five)
|
||||||
{
|
{
|
||||||
g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 21, 10, 20);
|
g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 21, 10, 20);
|
||||||
}
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.DrawningObjects
|
||||||
|
{
|
||||||
|
internal class DrawningDoorTriangle : IDrawningDoors
|
||||||
|
{
|
||||||
|
public DoorNumbers _doorNumbers;
|
||||||
|
public void ChangeDoorsNumber(int x)
|
||||||
|
{
|
||||||
|
if (x <= 3)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Three;
|
||||||
|
}
|
||||||
|
if (x == 4)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Four;
|
||||||
|
}
|
||||||
|
if (x >= 5)
|
||||||
|
{
|
||||||
|
_doorNumbers = DoorNumbers.Five;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.White);
|
||||||
|
Brush brBlue = new SolidBrush(Color.Black);
|
||||||
|
Point[] triangle1 = {
|
||||||
|
new Point(_startPosX + 20, _startPosY + 41),
|
||||||
|
new Point(_startPosX + 25, _startPosY + 21),
|
||||||
|
new Point(_startPosX + 30, _startPosY + 41)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brBlue, triangle1);
|
||||||
|
|
||||||
|
Point[] triangle2 = {
|
||||||
|
new Point(_startPosX + 41, _startPosY + 41),
|
||||||
|
new Point(_startPosX + 36, _startPosY + 21),
|
||||||
|
new Point(_startPosX + 46, _startPosY + 21)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brBlue, triangle2);
|
||||||
|
|
||||||
|
Point[] triangle3 = {
|
||||||
|
new Point(_startPosX + 60, _startPosY + 41),
|
||||||
|
new Point(_startPosX + 55, _startPosY + 21),
|
||||||
|
new Point(_startPosX + 65, _startPosY + 21)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brBlue, triangle3);
|
||||||
|
|
||||||
|
if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five)
|
||||||
|
{
|
||||||
|
Point[] triangle4 = {
|
||||||
|
new Point(_startPosX + 80, _startPosY + 41),
|
||||||
|
new Point(_startPosX + 75, _startPosY + 21),
|
||||||
|
new Point(_startPosX + 85, _startPosY + 21)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brBlue, triangle4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_doorNumbers == DoorNumbers.Five)
|
||||||
|
{
|
||||||
|
Point[] triangle5 = {
|
||||||
|
new Point(_startPosX + 42, _startPosY + 41),
|
||||||
|
new Point(_startPosX + 37, _startPosY + 21),
|
||||||
|
new Point(_startPosX + 47, _startPosY + 21)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brBlue, triangle5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using DoubleDeckerBus_Hard.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.DrawningObjects
|
||||||
|
{
|
||||||
|
internal class DrawningDoubleDeckerBus : DrawningBus
|
||||||
|
{
|
||||||
|
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; }
|
||||||
|
|
||||||
|
public DrawningDoubleDeckerBus(int speed, float weight, Color bodyColor,
|
||||||
|
Color additionalColor, bool secondFloor, bool ladder, int doorNumbers, bool lineBetweenFloor, bool doors, int width, int height, int doorShape) :
|
||||||
|
base(speed, weight, bodyColor, width, height, doorNumbers, doorShape)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (EntityBus != null)
|
||||||
|
{
|
||||||
|
EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor,
|
||||||
|
additionalColor, secondFloor, ladder, doorNumbers, lineBetweenFloor, doors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBus is not EntityDoubleDeckerBus doubleDeckerBus)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush brAdditionalColor = new SolidBrush(doubleDeckerBus.AdditionalColor);
|
||||||
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
//2 этаж
|
||||||
|
if (doubleDeckerBus.SecondFloor)
|
||||||
|
{
|
||||||
|
//границы 2 этажа
|
||||||
|
g.FillRectangle(brAdditionalColor, _startPosX, _startPosY + 10, 100, 30);
|
||||||
|
// Окна 2 этажа
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15);
|
||||||
|
g.FillEllipse(brBlue, _startPosX + 30, _startPosY + 15, 10, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 30;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosY -= 30;
|
||||||
|
// лестница на второй этаж
|
||||||
|
if (doubleDeckerBus.Ladder)
|
||||||
|
{
|
||||||
|
if (doubleDeckerBus.SecondFloor == true)
|
||||||
|
{
|
||||||
|
//Вертикальные прямые
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 70)), new Point((int)(_startPosX), (int)(_startPosY + 10)));
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX + 10), (int)(_startPosY + 70)), new Point((int)(_startPosX + 10), (int)(_startPosY + 10)));
|
||||||
|
|
||||||
|
//Горизонтальные прямые
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + 10), (int)(_startPosY + 20)));
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 30)), new Point((int)(_startPosX + 10), (int)(_startPosY + 30)));
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 40)), new Point((int)(_startPosX + 10), (int)(_startPosY + 40)));
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 50)), new Point((int)(_startPosX + 10), (int)(_startPosY + 50)));
|
||||||
|
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 60)), new Point((int)(_startPosX + 10), (int)(_startPosY + 60)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.Entities
|
||||||
|
{
|
||||||
|
public class EntityBus
|
||||||
|
{
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public EntityBus(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.Entities
|
||||||
|
{
|
||||||
|
public class EntityDoubleDeckerBus : EntityBus
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool SecondFloor { get; private set; }
|
||||||
|
public bool Ladder { get; private set; }
|
||||||
|
public bool LineBetweenFloor { get; private set; }
|
||||||
|
public int DoorNumbers { get; private set; }
|
||||||
|
public bool Doors { get; private set; }
|
||||||
|
public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool secondFloor, bool ladder, int doorNumbers, bool lineBetweenFloor, bool doors) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
SecondFloor = secondFloor;
|
||||||
|
Ladder = ladder;
|
||||||
|
LineBetweenFloor = lineBetweenFloor;
|
||||||
|
DoorNumbers = doorNumbers;
|
||||||
|
Doors = doors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DoubleDeckerBus_Hard
|
|
||||||
{
|
|
||||||
public class EntityDoubleDeckerBus
|
|
||||||
{
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
public Color AdditionalColor { get; private set; }
|
|
||||||
public bool SecondFloor { get; private set; }
|
|
||||||
public bool Ladder { get; private set; }
|
|
||||||
public bool RoadLine { get; private set; }
|
|
||||||
public int DoorNumbers { get; private set; }
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool secondFloor, bool ladder, bool roadLine, int doorNumbers)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
SecondFloor = secondFloor;
|
|
||||||
Ladder = ladder;
|
|
||||||
RoadLine = roadLine;
|
|
||||||
DoorNumbers = doorNumbers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
14
DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs
Normal file
14
DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard
|
||||||
|
{
|
||||||
|
internal interface IDrawningDoors
|
||||||
|
{
|
||||||
|
public void ChangeDoorsNumber(int x);
|
||||||
|
public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DoubleDeckerBus_Hard.DrawningObjects;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
|
height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionBus.Left);
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionBus.Right);
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionBus.Up);
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionBus.Down);
|
||||||
|
protected ObjectParameters? GetObjectParameters =>
|
||||||
|
_moveableObject?.GetObjectPosition;
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
private bool MoveTo(DirectionBus directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
using DoubleDeckerBus_Hard.DrawningObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectBus : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningBus? _drawningBus = null;
|
||||||
|
public DrawningObjectBus(DrawningBus drawningBus)
|
||||||
|
{
|
||||||
|
_drawningBus = drawningBus;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningBus == null || _drawningBus.EntityBus == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningBus.GetPosX,
|
||||||
|
_drawningBus.GetPosY, _drawningBus.GetWidth, _drawningBus.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningBus?.EntityBus?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionBus direction) =>
|
||||||
|
_drawningBus?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionBus direction) =>
|
||||||
|
_drawningBus?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
int GetStep { get; }
|
||||||
|
bool CheckCanMove(DirectionBus direction);
|
||||||
|
void MoveObject(DirectionBus direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
public int TopBorder => _y;
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus_Hard.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user